Пример #1
0
        public async Task<ActionResult> ChangePassword(ForgottenPasswordViewModel model)
        {
            var user = this.Data.Users.All()
                .FirstOrDefault(x => x.ForgottenPasswordToken == model.Token);

            if (user == null)
            {
                throw new HttpException((int)HttpStatusCode.BadRequest, "Invalid token!");
            }

            if (this.ModelState.IsValid)
            {
                var removePassword = await this.UserManager.RemovePasswordAsync(user.Id);
                if (removePassword.Succeeded)
                {
                    var changePassword = await this.UserManager.AddPasswordAsync(user.Id, model.Password);
                    if (changePassword.Succeeded)
                    {
                        user.ForgottenPasswordToken = null;
                        this.Data.SaveChanges();

                        this.TempData[GlobalConstants.InfoMessage] = Resources.Account.Views.ChangePasswordView.Password_updated;
                        return this.RedirectToAction("Login");
                    }

                    this.AddErrors(changePassword);
                }

                this.AddErrors(removePassword);
            }

            return this.View(model);
        }
        public async Task<ActionResult> ChangePassword(ForgottenPasswordViewModel model)
        {
            var user = this.Data.Users.All()
                .FirstOrDefault(x => x.ForgottenPasswordToken == model.Token);

            if (user == null)
            {
                throw new HttpException((int)HttpStatusCode.BadRequest, "Invalid token!");
            }

            if (ModelState.IsValid)
            {
                IdentityResult removePassword =
                                        await
                                        this.UserManager.RemovePasswordAsync(user.Id);
                if (removePassword.Succeeded)
                {
                    IdentityResult changePassword =
                                        await
                                        this.UserManager.AddPasswordAsync(user.Id, model.Password);

                    if (changePassword.Succeeded)
                    {
                        user.ForgottenPasswordToken = null;
                        this.Data.SaveChanges();

                        this.TempData["InfoMessage"] = "Паролата ви беше сменена.";
                        return this.RedirectToAction("Login");
                    }

                    this.AddErrors(changePassword);
                }

                this.AddErrors(removePassword);
            }

            return this.View(model);
        }
Пример #3
0
        public ActionResult ChangePassword(string token)
        {
            Guid guid;

            if (!Guid.TryParse(token, out guid))
            {
                throw new HttpException((int)HttpStatusCode.BadRequest, "Invalid token!");
            }

            var user = this.Data.Users.All().FirstOrDefault(x => x.ForgottenPasswordToken == guid);

            if (user == null)
            {
                throw new HttpException((int)HttpStatusCode.BadRequest, "Invalid token!");
            }

            var forgottenPasswordModel = new ForgottenPasswordViewModel
            {
                Token = guid
            };

            return this.View(forgottenPasswordModel);
        }
        public ActionResult ChangePassword(string token)
        {
            Guid guid;

            if (!Guid.TryParse(token, out guid))
            {
                throw new HttpException((int)HttpStatusCode.BadRequest, "Invalid token!");
            }

            var user = this.Data.Users.All().FirstOrDefault(x => x.ForgottenPasswordToken == guid);

            if (user == null)
            {
                throw new HttpException((int)HttpStatusCode.BadRequest, "Invalid token!");
            }

            var forgottenPasswordModel = new ForgottenPasswordViewModel
            {
                Token = guid
            };

            this.TempData["InfoMessage"] = "Password changed successfully - you can now log in using your new password.";
            return this.View(forgottenPasswordModel);
        }