public async Task <bool> ChangePassword(ChangePassDto dto) { var account = (await DatabaseConnectService.Connection.FindAsync <Data.Entity.Account.Account>(x => x .Include <User>(join => join.InnerJoin()) .Where($"bys_account.user_id = @Id") .WithParameters(new { Id = _sessionService.UserId }))).FirstOrDefault(); if (account != null) { if (account.User.Status == AccountStatus.Active.ToString()) { if (account.Password == dto.OldPassword) { if (account.Password != dto.NewPassword) { account.Password = dto.NewPassword; await DatabaseConnectService.Connection.UpdateAsync(account); return(true); } throw new BusinessException("Mật khẩu này đang được sử dụng", ErrorCode.FAIL); } throw new BusinessException("Mật khẩu cũ không đúng", ErrorCode.WRONG_PASSWORD); } throw new BusinessException("Tài khoản chưa được kích hoạt", ErrorCode.INVALID_STATUS); } return(false); }
public IActionResult Post([FromBody] ChangePassDto changePass) { string userName = ""; if (User != null) { try { userName = User.FindFirst(ClaimTypes.Name).Value; } catch (Exception ex) { Console.WriteLine(ex.StackTrace); Console.WriteLine(new Response("401", "Error: Unauthorized")); return(Unauthorized(new Response("401", "Error: Unauthorized"))); } } try { string mess = _account.ChangePassword(userName, changePass); return(Ok(new Response("200", mess))); }catch (Exception ex) { return(BadRequest(new Response("400", ex.Message))); } }
public async Task <ActionResult> ChangePassword(ChangePassDto model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } try { var intialInfo = await GetTenantDbInfo(model.HostName); if (intialInfo == null || string.IsNullOrEmpty(intialInfo.TenantDBServer)) { ModelState.AddModelError("", "Invalid Host Name."); return(BadRequest(ModelState)); } bool result = await _loginService.ChangeUserPassword(intialInfo.GetConnectionString(), model.Email, model.OldPassword, model.NewPassword); if (!result) { return(StatusCode(StatusCodes.Status401Unauthorized, "Invalid Email or old password.")); } else { return(Ok("Password Changed Successfully.")); } } catch (Exception ex) { _logger.LogError(ex.StackTrace); return(StatusCode(StatusCodes.Status500InternalServerError, "Something went wrong!")); } }
public async Task <IActionResult> ChangeUserPassword([FromBody] ChangePassDto changePass) { await _userService.ChangePassword(HttpContext.User.Identity?.Name, changePass, ModelState); if (ModelState.ErrorCount > 0) { return(BadRequest(ModelState)); } return(NoContent()); }
public IActionResult ForgotPassword([FromBody] ChangePassDto pass) { try { service.ChangePass(pass); } catch (PassChangeException exc) { return(NotFound("no such thing")); } return(Ok()); }
public void ChangePass(ChangePassDto dto) { var secretUser = context.Users.SingleOrDefault(x => x.MailSecret == dto.Secret); if (secretUser == null) { throw new PassChangeException("No such thing"); } secretUser.SettPass(dto.NewPassword); secretUser.MailSecret = null; context.SaveChanges(); }
public string ChangePassword(string UserName, ChangePassDto changePass) { if (!changePass.Password.Equals(changePass.ConfirmPassword)) { throw new Exception("Mật khẩu mới xác nhận không đúng!"); } string msg; var check = _account.ChangePassword(UserName, changePass.CurrentPassword, changePass.Password, out msg); if (!check) { throw new Exception(msg); } return(msg); }
public async Task <BaseResponse <bool> > ChangePassword([FromBody] ChangePassDto dto) { if (dto == null || dto.AccountId == null || dto.OldPassword.IsNullOrWhiteSpace() || dto.NewPassword.IsNullOrWhiteSpace()) { throw new BusinessException("Invalid parameter!", ErrorCode.INVALID_PARAMETER); } var response = new BaseResponse <bool> { Data = await _userService.ChangePassword(dto), Status = true }; return(await Task.FromResult(response)); }
public async Task <ActionResult> ChangePassword(ChangePassDto changePassDto) { var user = await _userManager.GetUserAsync(User); if (user == null) { return(NotFound("Could not find user")); } var result = await _userManager.ChangePasswordAsync( user, changePassDto.OldPassword, changePassDto.NewPassword); if (!result.Succeeded) { return(BadRequest("Failed to change password")); } return(Ok("Password changed successfully")); }
public IHttpActionResult PutUser(int id, ChangePassDto user) { var currentUser = db.Users.FirstOrDefault(x => x.Email == this.User.Identity.Name); if (currentUser.UserId != id) { return(Content(HttpStatusCode.Forbidden, Messages.AccsesDenied)); } var tmp = db.Users.Find(id); if (tmp == null) { return(NotFound()); } if (user.OldPass != tmp.Password) { return(BadRequest()); } tmp.Password = user.NewPass; db.Entry(tmp).State = EntityState.Modified; try { db.SaveChanges(); return(Ok()); } catch (DbUpdateConcurrencyException) { if (!UserExists(id)) { return(NotFound()); } else { throw; } } }
public async Task ChangePassword(string userId, ChangePassDto changePass, ModelStateDictionary modelState) { _user = await _userManager.FindByIdAsync(userId); if (_user == null) { _logger.Log(LogLevel.Error, "Something went wrong! There is no such user!"); } if (!await _userManager.CheckPasswordAsync(_user, changePass.OldPassword)) { modelState.TryAddModelError("wrong-pass", "Invalid current password!"); return; } if (changePass.OldPassword == changePass.NewPassword) { modelState.TryAddModelError("same-pass", "New password can't be such as current password!"); return; } await _userManager.ChangePasswordAsync(_user, changePass.OldPassword, changePass.NewPassword); }
public async Task <ActionResult> ChangePassword(string username, ChangePassDto changePassDto) { var user = await _userManager.FindByNameAsync(username); if (user == null) { return(NotFound("Could not find user")); } /*if (await _userManager.IsInRoleAsync(user, "Admin")) * return StatusCode((int)HttpStatusCode.Forbidden, "You can't change another admin's password"); */ var resetToken = await _userManager.GeneratePasswordResetTokenAsync(user); var result = await _userManager.ResetPasswordAsync(user, resetToken, changePassDto.NewPassword); if (!result.Succeeded) { return(BadRequest("Failed to change password")); } return(Ok("Password changed successfully")); }
public HttpResponseMessage ChangePassword(ChangePassDto view) { ExecuteInTransaction(session => GetEntity <User>(session, view.Id).Password = Helpers.CreateMD5Hash(view.Password)); return(Request.CreateResponse(HttpStatusCode.OK)); }