public ActionResult ActivateUser(AHP.Core.DTO.ExternalUserInfo userInfo) { GenericAjaxResponse <bool> response = new GenericAjaxResponse <bool>(); try { if (string.IsNullOrEmpty(userInfo.Username)) { response.Success = false; response.Errors.Add("Username is required"); return(Json(response)); } if (string.IsNullOrEmpty(userInfo.Email)) { response.Success = false; response.Errors.Add("Email is required"); return(Json(response)); } response = _restClient.ActivateUser(userInfo.Username, userInfo.Email); if (response == null) { response = new GenericAjaxResponse <bool>(); response.Success = false; response.Errors.Add("An error occurred. Please try again."); } } catch (Exception ex) { response.Success = false; response.Errors.Add("Error occurred. Please try again"); } return(Json(response)); }
public AHP.Core.Model.GenericResponse <bool> CreateUserAccount(AHP.Core.DTO.ExternalUserInfo userInfo) { AHP.Core.Model.GenericResponse <bool> response = new Core.Model.GenericResponse <bool>(); try { if (userInfo == null) { response.Success = false; response.Data = false; response.Errors.Add("User information provided is empty"); return(response); } response = _userInfoManager.CreateUser(userInfo); //send welcome email to admin if (response.Success && response.Data) { string[] toEmail = System.Configuration.ConfigurationManager.AppSettings["WelcomeEmailTo"].Split(','); //send user details email. To User _logMessages.AppendFormat("Sending email to admin {0} with user details.", string.Join(";", toEmail)); string fromEmail = System.Configuration.ConfigurationManager.AppSettings["EmailFROM"]; _logMessages.AppendFormat("Welcome email will be sent from {0}.", fromEmail); string subject = System.Configuration.ConfigurationManager.AppSettings["NewUserSubject"]; _logMessages.AppendFormat("Subject of the email is {0}.", subject); string welcomeEmailBody = System.IO.File.ReadAllText(System.Web.Hosting.HostingEnvironment.MapPath("~/App_Data/EmailTemplates/NewUserEmail.html")); welcomeEmailBody = welcomeEmailBody.Replace("{Firstname}", userInfo.Firstname); welcomeEmailBody = welcomeEmailBody.Replace("{Lastname}", userInfo.Lastname); welcomeEmailBody = welcomeEmailBody.Replace("{Email}", userInfo.Email); welcomeEmailBody = welcomeEmailBody.Replace("{Username}", userInfo.Username); welcomeEmailBody = welcomeEmailBody.Replace("{SupplierId}", userInfo.SupplierId); welcomeEmailBody = welcomeEmailBody.Replace("{Role}", userInfo.Role); welcomeEmailBody = welcomeEmailBody.Replace("{Company}", userInfo.Company); //welcomeEmailBody = welcomeEmailBody.Replace("{Birthyear}", userInfo.BirthYear.ToString()); //welcomeEmailBody = welcomeEmailBody.Replace("{Birthmonth}", userInfo.BirthMonth.ToString()); //welcomeEmailBody = welcomeEmailBody.Replace("{Zipcode}", userInfo.ZipCode); if (_emailDeliveryService.SendEmail(fromEmail, toEmail, new string[] { }, subject, welcomeEmailBody)) { response.Success = true; response.Data = true; } else { response.Success = false; response.Data = false; response.Errors.Add("User successfully created. Failed to send email to admin with user information."); } } } catch (Exception ex) { _logger.Error("Error occurred creating new user account. Error info - ", ex); response.Success = false; response.Errors.Add("Error occurred creating new user account. Please try again."); } return(response); }
public ActionResult ResetPassword(AHP.Core.DTO.ExternalUserInfo userInfo) { //email template needs these details {CopyrightYear}{ServerUrl}{RandomPassword}{Username} //should check email address and also reset his password and also force change pwd on first logon GenericAjaxResponse <bool> response = new GenericAjaxResponse <bool>(); try { if (string.IsNullOrEmpty(userInfo.Username)) { response.Success = false; response.Errors.Add("Username is required"); return(Json(response)); } if (string.IsNullOrEmpty(userInfo.Email)) { response.Success = false; response.Errors.Add("Email is required"); return(Json(response)); } //reset password from admin will always force user to set new password on logon response = _restClient.ResetPassword(userInfo.Username, userInfo.Email, true); if (response == null) { response = new GenericAjaxResponse <bool>(); response.Success = false; response.Errors.Add("An error occurred. Please try again."); } } catch (Exception ex) { _logger.Error("Error occurred resetting user password", ex); response.Success = false; response.Errors.Add("Error occurred. Please try again"); } return(Json(response)); }
public AHP.Core.Model.GenericResponse <AHP.Core.DTO.ExternalUserInfo> UpdateUserAccount(AHP.Core.DTO.ExternalUserInfo userInfo) { AHP.Core.Model.GenericResponse <AHP.Core.DTO.ExternalUserInfo> response = new Core.Model.GenericResponse <AHP.Core.DTO.ExternalUserInfo>(); try { if (userInfo == null) { response.Success = false; response.Errors.Add("User information provided is empty"); return(response); } response = _userInfoManager.UpdateUser(userInfo); } catch (Exception ex) { _logger.Error("Error occurred creating new user account. Error info - ", ex); response.Success = false; response.Errors.Add("Error occurred creating new user account. Please try again."); } return(response); }