Ejemplo n.º 1
0
        public async Task <IActionResult> PasswordChange(PasswordChangeViewModel passwordChangeViewModel)
        {
            if (ModelState.IsValid)
            {
                var user = await CurrentUser;

                var result = await _userManager.ChangePasswordAsync(user, passwordChangeViewModel.OldPassword,
                                                                    passwordChangeViewModel.NewPassword);

                if (result.Succeeded)
                {
                    if ((await _userManager.UpdateSecurityStampAsync(user)).Succeeded)
                    {
                        await _signInManager.SignOutAsync();

                        await _signInManager.PasswordSignInAsync(user, passwordChangeViewModel.NewPassword, true, false);

                        ViewBag.Success = "true";
                        return(View());
                    }
                    else
                    {
                        AddModelErrors((await _userManager.UpdateSecurityStampAsync(user)).Errors);
                    }
                }
                else
                {
                    AddModelErrors(result.Errors);
                }
            }
            return(View());
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> PasswordChange(PasswordChangeViewModel passwordChangeViewModel)
        {
            if (ModelState.IsValid)
            {
                AppUser user = CurrentUser;

                bool exist = userManager.CheckPasswordAsync(user, passwordChangeViewModel.PasswordOld).Result;

                if (exist)
                {
                    IdentityResult result = userManager.ChangePasswordAsync(user, passwordChangeViewModel.PasswordOld, passwordChangeViewModel.PasswordNew).Result;

                    if (result.Succeeded)
                    {
                        await userManager.UpdateSecurityStampAsync(user);

                        await signInManager.SignOutAsync();

                        await signInManager.PasswordSignInAsync(user, passwordChangeViewModel.PasswordNew, true, false);

                        ViewBag.success = "true";
                    }
                    else
                    {
                        AddModelError(result);
                    }
                }
                else
                {
                    ModelState.AddModelError("", "Eski şifreniz yanlış");
                }
            }

            return(View(passwordChangeViewModel));
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> PasswordChange(PasswordChangeViewModel passwordChangeViewModel)
        {
            if (ModelState.IsValid)
            {
                var user = await _userManager.GetUserAsync(User);

                if (user == null)
                {
                    return(RedirectToAction("Login"));
                }
                var result = await _userManager.ChangePasswordAsync(
                    user,
                    passwordChangeViewModel.CurrentPassword,
                    passwordChangeViewModel.NewPassword);

                if (!result.Succeeded)
                {
                    foreach (var error in result.Errors)
                    {
                        ModelState.AddModelError(string.Empty, error.Description);
                    }

                    return(View());
                }
                await _signManager.RefreshSignInAsync(user);

                return(View("UserInformation"));
            }
            return(View());
        }
Ejemplo n.º 4
0
        public async Task <IActionResult> PasswordChange(PasswordChangeViewModel passwordChangeViewModel)
        {
            AppUser appUser = _userManager.FindByNameAsync(User.Identity.Name).Result;
            bool    exist   = _userManager.CheckPasswordAsync(appUser, passwordChangeViewModel.PasswordOld).Result;

            if (exist)
            {
                var result = _userManager.ChangePasswordAsync(appUser, passwordChangeViewModel.PasswordOld, passwordChangeViewModel.PasswordNew).Result;
                if (result.Succeeded)
                {
                    await _userManager.UpdateSecurityStampAsync(appUser);

                    await _signInManager.SignOutAsync();

                    await _signInManager.PasswordSignInAsync(appUser, passwordChangeViewModel.PasswordNew, true, false);

                    ViewBag.success = "true";
                }
                else
                {
                    AddModelError(result);
                }
            }
            else
            {
                ModelState.AddModelError("", "Girdiğiniz eski şifreniz yanlıştır.");
            }


            return(View(passwordChangeViewModel));
        }
Ejemplo n.º 5
0
        public async Task <IActionResult> PasswordChange([FromBody] PasswordChangeViewModel password)
        {
            var user = await this.userManager.FindByEmailAsync(password.email);

            if (user != null)
            {
                var result = await this.userManager.ChangePasswordAsync(user, password.old_password, password.new_password);

                if (result.Succeeded)
                {
                    user.initialLogin = false;
                    _ctx.SaveChanges();

                    var change_result = new
                    {
                        message = "success"
                    };

                    return(Created("", change_result));
                }

                return(BadRequest("Password change wasn't successful"));
            }

            return(BadRequest("The user email doesn't exist. Please try another"));
        }
Ejemplo n.º 6
0
        public IActionResult PasswordChange(PasswordChangeViewModel passwordChangeViewModel)
        {
            if (ModelState.IsValid)
            {
                AppUser user = CurrentUser;


                bool passwordExist = _userManager.CheckPasswordAsync(user, passwordChangeViewModel.PasswordOld).Result;
                if (passwordExist)
                {
                    IdentityResult result = _userManager.ChangePasswordAsync
                                                (user, passwordChangeViewModel.PasswordOld, passwordChangeViewModel.PasswordNew).Result;

                    if (result.Succeeded)
                    {
                        _userManager.UpdateSecurityStampAsync(user);
                        _signInManager.SignOutAsync();
                        _signInManager.PasswordSignInAsync(user, passwordChangeViewModel.PasswordNew, true, false);
                        ViewBag.success = true;
                    }
                    else
                    {
                        AddModelError(result);
                    }
                }
                else
                {
                    ModelState.AddModelError("", "Girmiş olduğunuz eski şifreniz hatalıdır");
                }
            }


            return(View(passwordChangeViewModel));
        }
Ejemplo n.º 7
0
        public async Task <ActionResult> Change(PasswordChangeViewModel model)
        {
            if (this.ModelState.IsValid)
            {
                var user = await _userManager.FindByNameOrEmailAsync(model.UserName);

                if (user == null)
                {
                    // Don't reveal that the user does not exist
                    return(this.RedirectToAction(nameof(Password.Changed)));
                }

                var result = await _userManager.ResetPasswordAsync(user, model.Code, model.Password);

                if (result.Succeeded)
                {
                    return(this.RedirectToAction(nameof(Password.Changed)));
                }

                foreach (var error in result.Errors)
                {
                    this.ModelState.AddModelError(string.Empty, error.Description);
                }
            }

            return(this.View(model));
        }
Ejemplo n.º 8
0
        public ActionResult ChangePassword(PasswordChangeViewModel model)
        {
            var usermanager = IdentityTools.NewUserManager();
            var kullanici   = usermanager.FindById(HttpContext.User.Identity.GetUserId());

            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            else if (!usermanager.CheckPassword(kullanici, model.OldPassword))
            {
                ModelState.AddModelError("", "Mevcut şifren bu değil!");
                return(View(model));
            }
            var result = usermanager.ChangePassword(kullanici.Id, model.OldPassword, model.NewPassword);

            if (result.Succeeded)
            {
                IdentityMessage msg = new IdentityMessage();
                msg.Subject     = "Şifren değiştirildi!";
                msg.Destination = kullanici.Email;
                msg.Body        = "Merhaba " + kullanici.Name + " az önce sitemiz üzerinden bir şifre yenileme işlemi gerçekleştirdin. Yeni şifreni sitemize bol bol giriş yaparak iyi günlerde kullanmanı dileriz.";
                mail.SendMail(msg);
                HttpContext.GetOwinContext().Authentication.SignOut();
                return(View("PasswordResetSuccess"));
            }
            else
            {
                return(View("Error"));
            }
        }
Ejemplo n.º 9
0
        public async Task <IActionResult> ChangePassword(PasswordChangeViewModel passwordChange)
        {
            if (ModelState.IsValid)
            {
                if (passwordChange.New != passwordChange.NewRepeated)
                {
                    passwordChange.ErrorMsg = "La contraseña nueva no coincide";
                    return(View(passwordChange));
                }
                IdentityResult result;
                var            currentUser = await _userManager.GetUser(_signInManager);

                if (!await _userManager.HasPasswordAsync(currentUser))
                {
                    result = await _userManager.AddPasswordAsync(currentUser, passwordChange.New);
                }
                else
                {
                    result = await _userManager.ChangePasswordAsync(currentUser, passwordChange.Current, passwordChange.New);
                }

                if (result.Succeeded)
                {
                    return(RedirectToAction("Profile", "Account"));
                }
                else
                {
                    passwordChange.ErrorMsg = result.Errors.FirstOrDefault()?.Description ?? string.Empty;
                }
            }
            return(View(passwordChange));
        }
Ejemplo n.º 10
0
 public IActionResult PasswordChange(PasswordChangeViewModel model)
 {
     if (ModelState.IsValid)
     {
         AppUser user  = CurrrentUser;
         bool    exits = userManager.CheckPasswordAsync(user, model.PasswordOld).Result;
         if (exits)
         {
             IdentityResult result = userManager.ChangePasswordAsync(user, model.PasswordOld, model.PasswordNew).Result;
             if (result.Succeeded)
             {
                 userManager.UpdateSecurityStampAsync(user);
                 signInManager.SignOutAsync();
                 signInManager.PasswordSignInAsync(user, model.PasswordNew, true, false);
                 ViewBag.success = true;
             }
             else
             {
                 AddModelError(result);
             }
         }
         else
         {
             ModelState.AddModelError("", "Eski Şifreniz Yanlış");
         }
     }
     return(View(model));
 }
Ejemplo n.º 11
0
        public IActionResult ChangePassword(PasswordChangeViewModel model)
        {
            var role        = _service.ChangePassword(model);
            var redirectUrl = role == "" ? "/" : $"/{role}/home";

            return(Redirect(redirectUrl));
        }
Ejemplo n.º 12
0
        public async Task <IActionResult> PasswordChange(PasswordChangeViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var user = await _userManager.GetUserAsync(User);

            if (user == null)
            {
                throw new ApplicationException($"Unable to load user with ID '{_userManager.GetUserId(User)}'.");
            }

            if (model.OldPassword == model.NewPassword)
            {
                return(RedirectToAction(nameof(ProfileController.ProfileEditView), "Profile", new { statusMessage = "Passwords Equal ~ No Update!" }));
            }

            var changePasswordResult = await _userManager.ChangePasswordAsync(user, model.OldPassword, model.NewPassword);

            if (!changePasswordResult.Succeeded)
            {
                AddErrors(changePasswordResult);
                return(View(model));
            }

            await _signInManager.SignInAsync(user, isPersistent : false);

            _logger.LogInformation("User changed their password successfully.");
            @ViewData["StatusMessage"] = "Password Successfully Updated";

            return(RedirectToAction(nameof(ProfileController.ProfileEditView), "Profile", new { statusMessage = "Password Successfully Updated!" }));
        }
Ejemplo n.º 13
0
 public ChangePasswordPage(int id)
 {
     InitializeComponent();
     BindingContext = model = new PasswordChangeViewModel
     {
         KlijentID = id
     };
 }
Ejemplo n.º 14
0
        public ActionResult ChangePassword(int id, HomeIndexViewModel navModel)
        {
            var model = new PasswordChangeViewModel {
            };

            model.NavigationModel = navModel;
            return(View(model));
        }
Ejemplo n.º 15
0
        public async Task <Answer> ChangePassword(PasswordChangeViewModel viewmodel)
        {
            var user = await _facade.GetUserByUserIdAsync(Actor.Me.Id);

            var result = await _facade.ChangePasswordAsync(user, viewmodel.OldPassword, viewmodel.newPassword);

            return(result.IsSuccess ? Answer.Success : Answer.Error(result.Errors.FirstOrDefault()));
        }
Ejemplo n.º 16
0
        public ActionResult ChangePassword(int id)
        {
            var model = new PasswordChangeViewModel {
            };

            model.NavigationModel = HomeIndexViewModelLoader.Create(id, _service);
            return(View(model));
        }
Ejemplo n.º 17
0
        public ActionResult ChangePassword(PasswordChangeViewModel model)
        {
            var userId = User.Identity.GetUserId();

            if (UserManager.HasPassword(userId))
            {
                UserManager.RemovePassword(userId);
            }

            UserManager.AddPassword(userId, model.NewPassword);
            return(RedirectToAction("Index", "Home"));
        }
Ejemplo n.º 18
0
        public async Task <IActionResult> ChangePassword(PasswordChangeViewModel model)
        {
            if (ModelState.IsValid)
            {
                model = await UsersBL.ChangePassword(_context, _userManager, User, model);

                if (!string.IsNullOrEmpty(model.ErrorText))
                {
                    ModelState.AddModelError("", model.ErrorText);
                }
            }
            return(PartialView("ChangePassword", model));
        }
Ejemplo n.º 19
0
        public async Task <IActionResult> ChangePassword([FromBody] PasswordChangeViewModel model)
        {
            string id   = User.FindFirst("id").Value;
            User   user = await UserManager.FindByIdAsync(id);

            IdentityResult result = await UserManager.ChangePasswordAsync(user,
                                                                          model.CurrentPassword, model.NewPassword);

            if (result.Succeeded)
            {
                return(Ok());
            }
            return(BadRequest());
        }
Ejemplo n.º 20
0
        public ActionResult PasswordChange(String code)
        {
            if (String.IsNullOrEmpty(code))
            {
                return(Redirect("/"));
            }

            var model = new PasswordChangeViewModel()
            {
                Code = code,
            };

            return(View(model));
        }
Ejemplo n.º 21
0
 public async Task <AccountResponse> ChangePasswordAsync(User user, PasswordChangeViewModel passwordChangeViewModel)
 {
     if (user != null)
     {
         if (passwordChangeViewModel.Password != null && passwordChangeViewModel.ConfirmPassword != null)
         {
             if (passwordChangeViewModel.Password.Equals(passwordChangeViewModel.ConfirmPassword))
             {
                 var passwordChangeToken = await userManager.GeneratePasswordResetTokenAsync(user);
             }
         }
     }
     return(null);
 }
        public ActionResult ChangePassword(PasswordChangeViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user       = _repositoryServices.GetUserByName(User.Identity.Name);
                var aspNetUser = user.AspNetUser;

                UserManager.RemovePassword(user.ASPNetUserId);

                UserManager.AddPassword(user.ASPNetUserId, model.Password);
                return(View("Success"));
            }

            return(View(model));
        }
Ejemplo n.º 23
0
 public ActionResult EditUserPassword(PasswordChangeViewModel model)
 {
     if (ModelState.IsValid)
     {
         var user = _userService.GetUserEntityByLogin(User.Identity.Name);
         if (Crypto.VerifyHashedPassword(user.Password, model.OldPassword) &&
             String.Compare(model.Password, model.ConfirmPassword) == 0)
         {
             user.Password = Crypto.HashPassword(model.Password);
             _userService.UpdateUser(user);
             return(RedirectToAction("Index", "Lot"));
         }
     }
     return(RedirectToAction("EditUserProfile", "User"));
 }
Ejemplo n.º 24
0
        protected override ValidationResult IsValid(object value, ValidationContext validationContext)
        {
            PasswordChangeViewModel model = (PasswordChangeViewModel)validationContext.ObjectInstance;
            string oldPassword            = model.Password;
            string newPassword            = (string)value;

            if (oldPassword.Equals(newPassword))
            {
                return(new ValidationResult($"Selected password is the same as the previous one . Enter another one!", new[] { validationContext.MemberName }));
            }
            else
            {
                return(ValidationResult.Success);
            }
        }
Ejemplo n.º 25
0
        public ActionResult ChangePassword(PasswordChangeViewModel model)
        {
            if (!Membership.ValidateUser(Membership.GetUser().UserName, model.OldPassword))
            {
                ModelState.AddModelError("OldPassword", "Incorrect Password");
            }

            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            _service.ChangePassword(model.OldPassword, model.NewPassword);
            TempData["message"] = "Password has been changed";
            return(RedirectToAction("Index", "Home", new { id = model.NavigationModel.Page.PageNavigation.Id }));
        }
Ejemplo n.º 26
0
        public async Task <IActionResult> ChangePassword([FromBody] PasswordChangeViewModel passwordChange)
        {
            var principal = contextAccessor.HttpContext.User;
            var user      = await userManager.FindByNameAsync(principal.Identity.Name);

            var result = await userManager.ChangePasswordAsync(user, passwordChange.CurrentPassword, passwordChange.Password);

            if (result.Succeeded)
            {
                await signInManager.SignOutAsync();

                return(Ok());
            }

            return(Unauthorized());
        }
Ejemplo n.º 27
0
        public IActionResult ResetPassword(PasswordChangeViewModel model)
        {
            if (model.Email == null)
            {
                return(RedirectToAction("ResetPassword", new { message = "Email girilmedi" }));
            }

            var user = _userService.GetByMail(model.Email);

            if (user == null)
            {
                return(RedirectToAction("ResetPassword", new { email = model.Email, message = "Email sistemde kayıtlı değil." }));
            }
            _userPasswordChangeService.AddByUser(user);
            return(RedirectToAction("StartResetPassword", model));
        }
Ejemplo n.º 28
0
        public IActionResult PasswordChange(PasswordChangeViewModel passwordChangeViewModel)
        {
            if (ModelState.IsValid)
            {
                AppUser user = userManager.FindByNameAsync(User.Identity.Name).Result;

                if (user != null)
                {
                    bool exit = userManager.CheckPasswordAsync(user, passwordChangeViewModel.PasswordOld).Result;
                }
            }



            return(View());
        }
Ejemplo n.º 29
0
        public async Task <IActionResult> ChangePassword(PasswordChangeViewModel viewmodel)
        {
            if (ModelState.IsValid)
            {
                var result = await Gateway.ChangePassword(viewmodel);

                var user            = Gateway.GetParticipant(Actor.Me.Id);
                var updateViewModel = new UpdateAccountViewModel();
                updateViewModel.Password = new PasswordChangeViewModel();
                updateViewModel.Details  = new DetailsUpdateViewModel
                {
                    YearOfBirth          = user.YearOfBirth,
                    FullName             = user.FullName,
                    Email                = user.Email,
                    IsAllowingPromotions = user.IsAllowingPromotions,
                    PhoneNumber          = user.PhoneNumber
                };

                if (result.AnswerType == AnswerType.Success)
                {
                    SetUserSuccess("שינוי סיסמה", "הסיסמה שונתה בהצלחה");
                    return(View("UpdateAccount", updateViewModel));
                }
                else
                {
                    SetUserSuccess("שינוי סיסמה", "תקלה - " + result.Message);
                    return(View("UpdateAccount", updateViewModel));
                }
            }
            else
            {
                var user            = Gateway.GetParticipant(Actor.Me.Id);
                var updateViewModel = new UpdateAccountViewModel();
                updateViewModel.Password = new PasswordChangeViewModel();
                updateViewModel.Details  = new DetailsUpdateViewModel
                {
                    YearOfBirth          = user.YearOfBirth,
                    FullName             = user.FullName,
                    Email                = user.Email,
                    IsAllowingPromotions = user.IsAllowingPromotions,
                    PhoneNumber          = user.PhoneNumber
                };
                var invalidProperty = ModelState.First(x => x.Value.ValidationState == ModelValidationState.Invalid);
                SetUserError("תקלה במידע שהתקבל", invalidProperty.Value.Errors.FirstOrDefault()?.ErrorMessage ?? "אנא נסו שוב");
                return(View("UpdateAccount", updateViewModel));
            }
        }
        public static async Task <PasswordChangeViewModel> ChangePassword(FrontEditorContext _context, UserManager <User> _userManager, System.Security.Claims.ClaimsPrincipal User, PasswordChangeViewModel model)
        {
            User user = await _userManager.GetUserAsync(User);

            await _userManager.RemovePasswordAsync(user);

            var result = await _userManager.AddPasswordAsync(user, model.NewPassword);

            if (result.Succeeded)
            {
                model = new PasswordChangeViewModel()
                {
                    PasswordChanged = true
                };
            }
            else
            {
                foreach (var error in result.Errors)
                {
                    if (error.Code == "PasswordTooShort")
                    {
                        model.ErrorText += "A jelszó legalább 6 karakter!<br />";
                    }
                    else if (error.Code == "PasswordRequiresNonAlphanumeric")
                    {
                        model.ErrorText += "A jelszó tartalmaz legalább egy nem alfanumerikus karaktert!<br />";
                    }
                    else if (error.Code == "PasswordRequiresDigit")
                    {
                        model.ErrorText += "A jelszó legalább egy számot tartalmaz!<br />";
                    }
                    else if (error.Code == "PasswordRequiresUpper")
                    {
                        model.ErrorText += "A jelszó legalább egy nagybetűt tartalmaz!<br />";
                    }
                    else if (error.Code == "PasswordRequiresLower")
                    {
                        model.ErrorText += "A jelszó legalább egy kisbetűt tartalmaz!<br />";
                    }
                    else
                    {
                        model.ErrorText += error.Description + "<br />";
                    }
                }
            }
            return(model);
        }