public ApiResponse RecoverPassword(User info) { try { var validator = new UserRecoverPasswordValidator(); 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)) { logMgr.Info(info.Email + " success to request password change"); var emailMgr = new EmailMgr(); info.TempPassword = StringCipher.Decrypt(info.TempPassword, passPhrase); if (emailMgr.SendPwdRecoveryEmail(info)) { response.Success = true; } else { logMgr.Error(info.Email + " failed to send an email for password recovery"); } } } 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.PropertyName + 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 RecoverPassword(User info) { try { var validator = new UserRecoverPasswordValidator(); 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)) { logMgr.Info(info.Email + " success to request password change"); var emailMgr = new EmailMgr(); info.TempPassword = StringCipher.Decrypt(info.TempPassword, passPhrase); if (emailMgr.SendPwdRecoveryEmail(info)) response.Success = true; else logMgr.Error(info.Email + " failed to send an email for password recovery"); } } 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.PropertyName + error.ErrorMessage }); } } } catch (Exception ex) { response.Success = false; response.ErrorList.Add(new Error { Message = "Internal Server Error Code:500" }); logMgr.Error(ex); } return response; }