public async Task <IActionResult> Update([DataSourceRequest] DataSourceRequest request, InformationUtilisateurViewModel model)
        {
            if (model.MotDePasse != model.ConfirmationMotDePasse)
            {
                throw new Exception("Mot de passe de confirmation différent.");
            }
            string passwordHash = string.Empty;

            if (!string.IsNullOrWhiteSpace(model.MotDePasse))
            {
                passwordHash = _userManager.PasswordHasher.HashPassword(new ApplicationUser(), model.MotDePasse);
            }

            Utilisateurs.UpdateUtilisateur(model, passwordHash, _userId);
            model.ConfirmationMotDePasse = "**********";
            model.MotDePasse             = "**********";
            _logger.LogWarning("update de User." + JsonConvert.SerializeObject(model) + " par " + User.Identity.Name);
            AddRoles(model);

            return(Json(new[] { model }.ToDataSourceResult(request)));
        }
Example #2
0
        public async Task <IActionResult> ResetPassword(ResetPasswordViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            var user = await _userManager.FindByEmailAsync(model.Email);

            if (user == null)
            {
                // Don't reveal that the user does not exist
                _logger.LogWarning("ResetPassword: A code must be supplied for password reset.");
                return(RedirectToAction(nameof(ResetPasswordConfirmation)));
            }
            //julien: bypass de aspnet car non fonctionnel sur linux ou autre
            if (user.SecurityStamp != model.Code)
            {
                _logger.LogWarning("ResetPassword: SecurityStamp invalide.");
                ModelState.AddModelError(string.Empty, "Token invalide. Valider la procédure...");
            }
            else
            {
                if (string.IsNullOrWhiteSpace(model.Password))
                {
                    ModelState.AddModelError(string.Empty, "Mot de passe invalide. Valider la procédure...");
                }
                else
                {
                    string passwordHash = _userManager.PasswordHasher.HashPassword(new ApplicationUser(), model.Password);
                    InformationUtilisateurViewModel iusr = new InformationUtilisateurViewModel().Map(user);
                    iusr.Actif = !user.AccountDisabled;
                    Utilisateurs.UpdateUtilisateur(iusr, passwordHash, user.Id, true);
                    _logger.LogWarning("ResetPassword: successful pour " + user.UserName);
                    return(RedirectToAction(nameof(ResetPasswordConfirmation)));
                }
            }
            return(View());
        }