public async Task <IHttpActionResult> SetPassword(SetPasswordBindingModel model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } IdentityResult result = await UserManager.AddPasswordAsync(User.Identity.GetUserId(), model.NewPassword); if (!result.Succeeded) { return(GetErrorResult(result)); } return(Ok()); }
public async Task <IHttpActionResult> ResetPassword(SetPasswordBindingModel model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var user = await UserManager.FindByNameAsync(model.Email); IdentityResult result = await UserManager.ResetPasswordAsync(user.Id, model.NewPassword, model.ConfirmPassword); if (!result.Succeeded) { return(GetErrorResult(result)); } return(Ok()); }
public async Task <IActionResult> SetPassword() { var user = await this.CheckUser(); var hasPassword = await this.userManager .HasPasswordAsync(user); if (hasPassword) { return(this.RedirectToAction(nameof(ChangePassword))); } var model = new SetPasswordBindingModel { StatusMessage = this.StatusMessage }; return(this.View(model)); }
public async Task <IHttpActionResult> SetPassword(SetPasswordBindingModel model) { if (!this.ModelState.IsValid) { return(this.BadRequest(this.ModelState)); } var result = await this.UserManager.AddPasswordAsync(this.User.Identity.GetUserId(), model.NewPassword); var errorResult = this.GetErrorResult(result); if (errorResult != null) { return(errorResult); } return(this.Ok()); }
public async Task <IHttpActionResult> ResetPassword(SetPasswordBindingModel model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } string token = await UserManager.GeneratePasswordResetTokenAsync(model.UserId); IdentityResult result = await UserManager.ResetPasswordAsync(model.UserId, token, model.NewPassword); if (!result.Succeeded) { return(GetErrorResult(result)); } return(Ok(new { Message = "SUCCESS" })); }
public async Task <IHttpActionResult> SetPassword(SetPasswordBindingModel model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } IdentityResult result = await UserManager.AddPasswordAsync(CurrentUser.UserId, model.NewPassword); IHttpActionResult errorResult = GetErrorResult(result); if (errorResult != null) { return(errorResult); } return(Ok()); }
public async Task <IActionResult> SetPassword([FromBody] SetPasswordBindingModel model) { var user = await GetCurrentUserAsync(); if (user == null) { return(this.BadRequest()); } var result = await userManager.AddPasswordAsync(user, model.NewPassword); if (result.Succeeded) { await signInManager.SignInAsync(user, isPersistent : false); } return(this.CheckResult(result)); }
public async Task <IHttpActionResult> SetPassword(SetPasswordBindingModel model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } IdentityResult result = await IdentityManager.Logins.AddLocalLoginAsync(User.Identity.GetUserId(), User.Identity.GetUserName(), model.NewPassword); IHttpActionResult errorResult = GetErrorResult(result); if (errorResult != null) { return(errorResult); } return(Ok()); }
public async Task <IHttpActionResult> SetPassword(SetPasswordBindingModel model) { // Пока запрещенный метод. return(BadRequest()); if (model == null || !ModelState.IsValid) { return(BadRequest(ModelState)); } IdentityResult result = await Repo.SetUserPassword(User.Identity.GetUserId <int>(), model.NewPassword); if (!result.Succeeded) { return(GetErrorResult(result)); } return(Ok()); }
public async Task <IHttpActionResult> SetPassword(SetPasswordBindingModel model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var validationResult = await UserManager.PasswordValidator.ValidateAsync(model.NewPassword); if (validationResult.Succeeded) { var user = UserManager.FindByEmail(model.EmailAddress); var codeValidationResult = await UserManager.UserTokenProvider.ValidateAsync("SetPassword", model.Code, UserManager, user); if (codeValidationResult) { var result = await UserManager.AddPasswordAsync(user.Id, model.NewPassword); if (!result.Succeeded) { return(GetErrorResult(result)); } return(Ok()); } else { var setPasswordCodeValidationResult = await UserManager.ResetPasswordAsync(user.Id, model.Code, model.NewPassword); if (!setPasswordCodeValidationResult.Succeeded) { return(BadRequest()); } return(Ok()); } } else { var modelState = new ModelStateDictionary(); modelState.AddModelError("", validationResult.Errors.First()); return(BadRequest(modelState)); } }
public async Task <IHttpActionResult> SetPassword(SetPasswordBindingModel model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } string Id = string.IsNullOrEmpty(model.UserId) ? User.Identity.GetUserId() : model.UserId; UserManager.RemovePassword(Id); IdentityResult result = await UserManager.AddPasswordAsync(Id, model.NewPassword); if (!result.Succeeded) { return(GetErrorResult(result)); } return(Ok()); }
public async Task <IHttpActionResult> SetPassword(SetPasswordBindingModel model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } User user = UserManager.FindById(model.Id); if (user == null || user.PasswordHash != null) { return(BadRequest("This request is invalid")); } IdentityResult result = await UserManager.AddPasswordAsync(model.Id, model.NewPassword); if (!result.Succeeded) { return(GetErrorResult(result)); } return(Ok()); }
public async Task <IHttpActionResult> SetPassword(SetPasswordBindingModel model) { Response response = new Response(); if (!ModelState.IsValid) { response.code = "400"; response.status = "Mật khẩu không hợp lệ"; response.results = ModelState; return(Content <Response>(HttpStatusCode.BadRequest, response)); } IdentityUser user = await Service._userManager.FindByEmailAsync(model.email); if (user.Id != null) { IdentityResult result = await Service._userManager.AddPasswordAsync(user.Id, model.newPassword); if (!result.Succeeded) { response.code = "500"; response.status = "Internal Error Can't Set New Password"; response.results = result; return(Content <Response>(HttpStatusCode.InternalServerError, response)); } } else { response.code = "404"; response.status = "Email không tồn tại"; return(Content <Response>(HttpStatusCode.NotFound, response)); } response.code = "200"; response.status = "Đặt lại mật khẩu thành công"; return(Content <Response>(HttpStatusCode.OK, response)); }
public async Task <IHttpActionResult> SetPassword(SetPasswordBindingModel model) { _logger.Debug("ini SetPassword process"); if (!ModelState.IsValid) { _logger.Debug("ini SetPassword BadRequest"); return(BadRequest(ModelState)); } IdentityResult result = await _appUserManager.AddPasswordAsync(User.Identity.GetUserId <int>(), model.NewPassword); if (!result.Succeeded) { _logger.Debug("ini SetPassword GetErrorResult"); return(GetErrorResult(result)); } _logger.Debug("ini SetPassword Ok"); return(Ok(new JsonResponse { Success = true, Message = "Password setted" })); }
public async Task <IHttpActionResult> SetPassword(SetPasswordBindingModel model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } try { // Create the local login info and link the local account to the user if (!await IdentityStore.CreateLocalLogin(User.Identity.GetUserId(), User.Identity.GetUserName(), model.NewPassword)) { return(BadRequest("Failed to set password.")); } } catch (IdentityException e) { return(BadRequest(e.ToString())); } return(OK()); }
public async Task <IHttpActionResult> SetPassword(SetPasswordBindingModel model) { if (!ModelState.IsValid) { //return BadRequest(ModelState); return(Content <object>(HttpStatusCode.BadRequest, ModelState)); } var userId = User.Identity.GetUserId(); IdentityUser user = await UserManager.FindByIdAsync(userId); IdentityResult result = await UserManager.AddPasswordAsync(userId, model.NewPassword); if (!result.Succeeded) { return(Content <IdentityResult>(HttpStatusCode.BadRequest, result)); } // 记录日志 logger.Info("设置用户密码:{0}", JsonConvert.SerializeObject(user)); return(Content <SetPasswordBindingModel>(HttpStatusCode.OK, model)); }
public async Task <ResponseMessage> SetPassword(SetPasswordBindingModel model) { //string ip = StaticTools.GetIp(Request); try { if (!ModelState.IsValid) { return(new ResponseMessage(Tools.ResponseMessage.ResponseCode.AuthenticationFailed, ErrorMessages.RegisterError, ModelState));; } IdentityResult result = await UserManager.AddPasswordAsync(User.Identity.GetUserId(), model.NewPassword); if (!result.Succeeded) { return(new ResponseMessage(Tools.ResponseMessage.ResponseCode.AuthenticationFailed, ErrorMessages.RegisterError, result)); } return(Tools.ResponseMessage.Ok); } catch { return(Tools.ResponseMessage.InternalError); } }
public async Task <IActionResult> SetUserPassword(SetPasswordBindingModel model) { if (string.IsNullOrEmpty(model.NewPassword)) { ModelState.AddModelError("", "Password missing"); return(BadRequest(ModelState)); } if (!IsPasswordValid(model.NewPassword)) { ModelState.AddModelError("Password", PasswordRequirementMessage(model.NewPassword)); return(BadRequest(ModelState)); } applicationUser.ForcedPasswordChange = false; applicationUser.PasswordHash = userManager.PasswordHasher.HashPassword(applicationUser, model.NewPassword); var result = await userManager.UpdateAsync(applicationUser).ConfigureAwait(true); if (!result.Succeeded) { return(GetErrorResult(result)); } return(Ok()); }
public async Task<IHttpActionResult> SetPassword(SetPasswordBindingModel model) { if (!ModelState.IsValid) { return BadRequest(ModelState); } IdentityResult result = await UserManager.AddPasswordAsync(User.Identity.GetUserId(), model.NewPassword); if (!result.Succeeded) { return GetErrorResult(result); } return Ok(); }
public async Task<IHttpActionResult> SetPassword(SetPasswordBindingModel model) { if (!this.ModelState.IsValid) { return this.BadRequest(this.ModelState); } var result = await this.UserManager.AddPasswordAsync(this.User.Identity.GetUserId(), model.NewPassword); return result.Succeeded ? this.Ok() : this.GetErrorResult(result); }
public void Init() { instance = new SetPasswordBindingModel(); }
public override Task <IHttpActionResult> SetPassword(SetPasswordBindingModel model) { return(base.SetPassword(model)); }