public IHttpActionResult ResetPassword(ResetDetails resetDetails) { LoginDetail loginDetail = null; ActionStatus status = new ActionStatus(); try { loginDetail = userService.ResetPassword(resetDetails, userId); } catch (UserServiceException ex) { status.Number = (int)ex.ErrorCodeService; } catch (BaseException ex) { status.Number = (int)ex.ErrorCode; } catch (Exception ex) { status.Number = -1; logger.Error("Exception in User/ResetPassword: {0} \r\n {1}", ex.ToString(), ex.StackTrace); } if (status.Number != -1) { return(Ok(new { LoginDetail = loginDetail, Status = status })); } else { return(InternalServerError()); } }
public IActionResult UserReset(ResetDetails reset) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var resp = _auth.ResetRequest(reset.userId, reset.Front); if (!resp) { return(NotFound()); } return(Ok(resp)); }
public LoginDetail ResetPassword(ResetDetails reserDetails, int userId) { logger.Info("Inside Userservice/ResetPassword"); LoginDetail loginResult = new LoginDetail(); string pwd = String.Empty; string salt = String.Empty; try { var userDetail = unitOfWork.DbContext.UserDetail .Where(ud => ud.ID == userId) .FirstOrDefault(); if (userDetail != null) { bool validPassword = PasswordManager.IsPasswordMatch(reserDetails.OldPassword, userDetail.Salt, userDetail.Password); if (validPassword) { logger.Info("Valid credentials."); pwd = PasswordManager.GeneratePasswordHash(reserDetails.NewPassword, out salt); userDetail.Password = pwd; userDetail.Salt = salt; userDetail.SetByAdmin = false; PasswordResetMapping passwordResetMapping = new PasswordResetMapping() { UserId = userDetail.ID, PasswordResetOn = DateTime.UtcNow, }; unitOfWork.DbContext.PasswordResetMapping.Add(passwordResetMapping); loginResult.UserId = userDetail.ID; loginResult.UserName = userDetail.Name; unitOfWork.DbContext.SaveChanges(); loginResult.Result = 1; } else { throw new PasswordNotValidException(); } } else { throw new NoDataFoundException(); } return(loginResult); } catch (UserServiceException ex) { throw ex; } catch (BaseException ex) { throw ex; } catch (Exception ex) { throw ex; } }