Example #1
0
        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());
        }
Example #2
0
        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());
        }
Example #3
0
        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));
        }
Example #4
0
        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" }));
        }
Example #6
0
        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));
        }
Example #8
0
        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());
        }
Example #9
0
        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());
        }
Example #10
0
        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));
            }
        }
Example #11
0
        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());
        }
Example #13
0
        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));
        }
Example #14
0
        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"
            }));
        }
Example #15
0
        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));
        }
Example #17
0
        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);
            }
        }
Example #18
0
        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();
        }
Example #20
0
        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);
        }
Example #21
0
 public void Init()
 {
     instance = new SetPasswordBindingModel();
 }
Example #22
0
 public override Task <IHttpActionResult> SetPassword(SetPasswordBindingModel model)
 {
     return(base.SetPassword(model));
 }