public async Task<ActionResult> SetPassword(SetPasswordViewModel model)
        {
            if (ModelState.IsValid)
            {
                var result = await UserManager.AddPasswordAsync(User.Identity.GetUserId(), model.NewPassword);
                if (result.Succeeded)
                {
                    var user = await UserManager.FindByIdAsync(User.Identity.GetUserId());
                    if (user != null)
                    {
                        await SignInManager.SignInAsync(user, isPersistent: false, rememberBrowser: false);
                    }
                    return RedirectToAction("Index", new { Message = ManageMessageId.SetPasswordSuccess });
                }
                AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            return View(model);
        }
Exemplo n.º 2
0
        public async Task<ActionResult> SetPassword(SetPasswordViewModel model)
        {
            if (Session["usuario"] == null)
            {
                return RedirectToAction("Index", "Usuarios");
            }

            if (ModelState.IsValid)
            {
                var usuario = Session["usuario"] as User;
                var IdUsuario = usuario.ss_id_usr.ToString();
                //ELIMINA EL PASSWORD PARA SER SETEADO
                pcUpmeCnx dbUsr = new pcUpmeCnx();
                    dbUsr.Database.ExecuteSqlCommand("UPDATE MUB_USUARIOS SET PWDHASH = NULL WHERE ID_USUARIO = :ID_USR",
                        new[] { new OracleParameter("ID_USR", IdUsuario) });

                //CAMBIA EL PASSWORD
                var result = await UserManager.AddPasswordAsync(IdUsuario, model.NewPassword);
                if (result.Succeeded)
                {
                    return RedirectToAction("Index", "Usuarios");
                }
                AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            return View(model);
        }