Beispiel #1
0
        public GenericResponse <bool> ResetPassword(Core.DTO.UpdateSecurityQuestionsRequest securityQuestionAnswers)
        {
            GenericResponse <bool> response = new GenericResponse <bool>();
            GenericResponse <AHP.Core.DTO.PasswordResetResponse> dbResponse = _userInfoManager.ResetPassword(securityQuestionAnswers.Username, securityQuestionAnswers.SecurityQuestions);

            response.Success = dbResponse.Success;
            response.Errors  = dbResponse.Errors;
            if (dbResponse.Success)
            {
                if (dbResponse.Data == null)
                {
                    response.Errors.Add("Random password could not be generated. Please try again.");
                    response.Success = false;
                }
                else
                {
                    //send welcome email. If successfully emailed then we will activate their email address on File
                    _logMessages.AppendFormat("Resetting the password for user {0} with email {1}.", dbResponse.Data.Username, dbResponse);
                    string fromEmail = System.Configuration.ConfigurationManager.AppSettings["EmailFROM"];
                    _logMessages.AppendFormat("Password reset email will be sent from {0}.", fromEmail);
                    string subject = System.Configuration.ConfigurationManager.AppSettings["ResetPasswordSubject"];
                    _logMessages.AppendFormat("Subject of the email is {0}.", subject);
                    string portalUrl = System.Configuration.ConfigurationManager.AppSettings["LogonUrl"];
                    _logMessages.AppendFormat("Logon url for the user is {0}.", portalUrl);

                    string welcomeEmailBody = System.IO.File.ReadAllText(System.Web.Hosting.HostingEnvironment.MapPath("~/App_Data/EmailTemplates/ResetPassword.html"));
                    welcomeEmailBody = welcomeEmailBody.Replace("{ServerUrl}", portalUrl);
                    //welcomeEmailBody = welcomeEmailBody.Replace("{Username}", securityQuestionAnswers.Username);
                    welcomeEmailBody = welcomeEmailBody.Replace("{RandomPassword}", dbResponse.Data.NewPassword);
                    welcomeEmailBody = welcomeEmailBody.Replace("{CopyrightYear}", DateTime.Today.Year.ToString());

                    if (_emailDeliveryService.SendEmail(fromEmail, new[] { dbResponse.Data.Email }, new string[] { }, subject, welcomeEmailBody))
                    {
                        response.Success = true;
                        response.Data    = true;
                        _logMessages.AppendFormat("Password reset email has been sent successfully to user {0} with email {1}.", dbResponse.Data.Username, dbResponse.Data.Email);
                    }
                    else
                    {
                        response.Success = false;
                        response.Data    = false;
                        response.Errors.Add("We could not deliver random password to your email address on file.");
                        _logMessages.AppendFormat("Error occurred sending email to user {0} with email {1}.", dbResponse.Data.Username, dbResponse.Data.Email);
                    }

                    //operation succeeded only if email and db operation succeeded
                    response.Success = response.Success && dbResponse.Success;
                    response.Errors  = dbResponse.Errors;
                }
            }
            return(response);
        }
Beispiel #2
0
 public GenericResponse <bool> UpdateSecurityQuestions(Core.DTO.UpdateSecurityQuestionsRequest securityQuestionAnswers)
 {
     return(_userInfoManager.SetupQuestions(securityQuestionAnswers.Username, securityQuestionAnswers.SecurityQuestions));
 }