public object Any(ResetPassword request) { var res = new ResetPasswordResponse(); var user = UserAuthRepository.GetUserAuthByUserName(request.Email); if (null == user) { res.Success = false; res.Message = "Invalid email address."; return(res); } var secret = Cache.Get <string>($"password:secret:{user.Email}"); if (secret.IsNullOrEmpty() || !secret.Equals(request.Token)) { res.Success = false; res.Message = "Reset window expired."; return(res); } UserAuthRepository.UpdateUserAuth(user, user, request.Password); Cache.Remove($"password:secret:{user.Email}"); using (var service = ResolveService <AuthenticateService>()) { return(service.Authenticate(new Authenticate { provider = AuthenticateService.CredentialsProvider, UserName = user.Email, Password = request.Password })); } }
public object Any(ResetViewModel request) { ValidationResult validations = new ResetAccountValidator().Validate(request); if (!validations.IsValid) { request.ResponseResult.ResultStatus = ResultStatuses.Error; foreach (var item in validations.Errors) { request.ResponseResult.Messages.Add(item.ErrorMessage); } return(request); } string de = request.Hash.Decrypt("hash"); var userAuth = UserAuthRepository.GetUserAuthByUserName(de); if (userAuth != null) { UserAuthRepository.UpdateUserAuth(userAuth, userAuth, request.Password); } request.ResponseResult.ResultStatus = ResultStatuses.Success; request.ResponseResult.Messages.Clear(); return(request); }