예제 #1
0
        public BaseResponse ResetPasswordRequest(DynamicDictionary _parameters)
        {
            BaseResponse response = new BaseResponse();

            string json = Request.Body.ReadAsString();

            if (json != null)
            {
                ResetRequest rr = JsonConvert.DeserializeObject <ResetRequest>(json);
                if (rr.Email != null &&
                    rr.InstallId != null)
                {
                    HydrantWikiManager manager = new HydrantWikiManager();
                    User user = manager.GetUserByEmail(UserSources.HydrantWiki, rr.Email);
                    if (user != null)
                    {
                        //Send reset password email
                        PasswordReset reset = PasswordReset.GetNewRequest(user.Guid);
                        manager.Persist(reset);

                        NameValueCollection nvc = new NameValueCollection
                        {
                            { "Code", reset.Code }
                        };

                        manager.SendCannedEmail(user, CannedEmailNames.ResetPasswordEmail, nvc);
                        manager.LogInfo(
                            user.Guid,
                            string.Format(
                                "Password Reset Request for user {0} on {1}",
                                user.Username,
                                rr.InstallId));

                        response.Success = true;
                        response.Message = "Password reset email sent.";
                    }
                    else
                    {
                        response.Success = false;
                        response.Message = "";
                    }
                }
            }

            return(response);
        }