public ApiResponse ChangePassword(User info) { try { var validator = new UserChangePasswordValidator(); var result = validator.Validate(info); if (result.IsValid) { if (dacMgr.Select(info.Email) != null) { info.UpdatedDate = DateTime.Now; info.TempPassword = StringCipher.Encrypt(LogicHelper.ConstructPassword(), passPhrase); info.Status = NUserStatus.ChangePassword.GetStrValue(); if (dacMgr.UpdateStatus(info)) { var emailMgr = new EmailMgr(); info.TempPassword = StringCipher.Decrypt(info.TempPassword, passPhrase); if (emailMgr.SendPwdChangeNotifyEmail(info)) { response.Success = true; } else { logMgr.Error(info.Email + " failed to send an email for password change notification"); } } } else { response.ErrorList.Add(new Error { Message = "Email doesn't exist in database" }); } } else { foreach (var error in result.Errors) { response.ErrorList.Add(new Error { Message = error.ErrorMessage }); } } } catch (Exception ex) { response.Success = false; response.ErrorList.Add(new Error { Message = "Internal Server Error Code:500" }); logMgr.Error(ex); } return(response); }
public ApiResponse ChangePassword(User info) { try { var validator = new UserChangePasswordValidator(); var result = validator.Validate(info); if (result.IsValid) { if (dacMgr.Select(info.Email) != null) { info.UpdatedDate = DateTime.Now; info.TempPassword = StringCipher.Encrypt(LogicHelper.ConstructPassword(), passPhrase); info.Status = NUserStatus.ChangePassword.GetStrValue(); if (dacMgr.UpdateStatus(info)) { var emailMgr = new EmailMgr(); info.TempPassword = StringCipher.Decrypt(info.TempPassword, passPhrase); if (emailMgr.SendPwdChangeNotifyEmail(info)) response.Success = true; else logMgr.Error(info.Email + " failed to send an email for password change notification"); } } else { response.ErrorList.Add(new Error { Message = "Email doesn't exist in database" }); } } else { foreach (var error in result.Errors) { response.ErrorList.Add(new Error { Message = error.ErrorMessage }); } } } catch (Exception ex) { response.Success = false; response.ErrorList.Add(new Error { Message = "Internal Server Error Code:500" }); logMgr.Error(ex); } return response; }