Пример #1
0
        public async Task <IActionResult> ResetPassword(ResetPasswordViewModel resetPasswordViewModel)
        {
            if (!ModelState.IsValid)
            {
                return(View(resetPasswordViewModel));
            }

            if (resetPasswordViewModel.Password != resetPasswordViewModel.ConfirmPassword)
            {
                ModelState.AddModelError(string.Empty, "Les mots de passes ne correspondent pas");
                return(View(resetPasswordViewModel));
            }

            var User = await _userManager.FindByIdAsync(resetPasswordViewModel.userId);

            if (User == null)
            {
                ModelState.AddModelError(string.Empty, "L'utilisateur n'existe pas !");
                return(View(resetPasswordViewModel));
            }

            var result = await _userManager.ResetPasswordAsync(User, resetPasswordViewModel.code, resetPasswordViewModel.Password);

            if (!result.Succeeded)
            {
                // Retour des erreurs
                foreach (var error in result.Errors)
                {
                    ModelState.AddModelError(string.Empty, error.Description);
                }
                return(View(resetPasswordViewModel));
            }

            return(Redirect("/"));
        }
Пример #2
0
        public async Task <IActionResult> Modifier(string Id)
        {
            var User = await _userManager.FindByIdAsync(Id);

            return(View(User));
        }