Beispiel #1
0
        public async Task <IActionResult> AddPassword(AddPasswordViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = await _userManager.GetUserAsync(User);

                //为用户添加密码
                var result = await _userManager.AddPasswordAsync(user, model.NewPassword);

                if (!result.Succeeded)
                {
                    foreach (var error in result.Errors)
                    {
                        ModelState.AddModelError(string.Empty, error.Description);
                    }
                    return(View());
                }
                //刷新当前用户的Cookie
                await _signInManager.RefreshSignInAsync(user);

                return(View("AddPasswordConfirmation"));
            }

            return(View(model));
        }
        public async Task <IActionResult> AddPassword(AddPasswordViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var user = await userManager.GetUserAsync(User);

            if (user == null)
            {
                return(RedirectToAction("Login"));
            }

            if (await userManager.HasPasswordAsync(user))
            {
                return(RedirectToAction("ChangePassword"));
            }

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

            if (!result.Succeeded)
            {
                PrintModelErrors(result.Errors);
                return(View());
            }

            await signInManager.RefreshSignInAsync(user);

            return(View("AddPasswordConfirmation"));
        }
        public async Task <IActionResult> AddPassword(AddPasswordViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = await _userManager.GetUserAsync(User);

                if (user == null)
                {
                    return(RedirectToAction("Login"));
                }

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

                if (!result.Succeeded)
                {
                    foreach (var error in result.Errors)
                    {
                        ModelState.AddModelError("", error.Description);
                    }
                    return(View());
                }

                await _signInManager.RefreshSignInAsync(user);

                return(View("AddPasswordConfirmation"));
            }

            return(View(model));
        }
        public async Task <IActionResult> AddPasswordAsync(AddPasswordViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = await userManager.GetUserAsync(User);

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

                if (result.Succeeded)
                {
                    await signInManager.RefreshSignInAsync(user);

                    return(View("AddPasswordConfirmation"));
                }

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


            return(View(model));
        }
Beispiel #5
0
        public async Task <IActionResult> AddPasswordAsync(AddPasswordViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = await userManager.GetUserAsync(User);

                if (user == null)
                {
                    return(RedirectToAction("Login"));
                }

                var hasPassword = await userManager.HasPasswordAsync(user);

                if (hasPassword)
                {
                    return(RedirectToAction("ChangePassword"));
                }

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

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

                return(RedirectToAction("ChangePasswordConfirmation"));
            }

            return(View(model));
        }
        public async Task <ActionResult> AddPassword(AddPasswordViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            string userId = User.Identity.GetUserId();

            if (!await UserManager.HasPasswordAsync(userId))
            {
                var addResult = await UserManager.AddPasswordAsync(userId, model.Password);

                if (addResult.Succeeded)
                {
                    return(RedirectToAction("IzmeniProfil", "Admin"));
                }
                AddErrorsFromResult(addResult);
            }
            // Korisnik vec ima lozinku
            return(View(model));
        }
Beispiel #7
0
        public async Task <IActionResult> AddPassword(AddPasswordViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = await userManager.GetUserAsync(User);

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

                if (!result.Succeeded)
                {
                    //foreach (var error in result.Errors)
                    //{
                    //    ModelState.AddModelError(string.Empty, error.Description);
                    //}
                    return(BadRequest());
                }
                await signInManager.RefreshSignInAsync(user);

                //return View("AddPasswordConfirmation");
                return(Ok());
            }
            return(BadRequest(model));
        }
Beispiel #8
0
        public async Task <IActionResult> AddPassword(AddPasswordViewModel model)
        {
            if (ModelState.IsValid)
            {
                ApplicationUser user = await userManager.GetUserAsync(User);

                IdentityResult result = await userManager.AddPasswordAsync(user, model.NewPassword);

                if (result.Succeeded)
                {
                    await signInManager.RefreshSignInAsync(user);

                    return(View("AddPasswordConfirmation"));
                }

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

            return(View(model));
        }
Beispiel #9
0
        public async Task <IActionResult> AddPassword(AddPasswordViewModel model)
        {
            if (ModelState.IsValid)
            {
                // The User property is set upon successful login
                ApplicationUser user = await userManager.GetUserAsync(User);

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

                if (!result.Succeeded)
                {
                    // The errors that can prevent us from changing password are incorrect current password or the new password is not of the required format
                    foreach (var error in result.Errors)
                    {
                        ModelState.AddModelError(string.Empty, error.Description);
                    }
                    return(View());
                }
                await signInManager.RefreshSignInAsync(user);

                return(View("AddPasswordConfirmation"));
            }
            return(View());
        }
Beispiel #10
0
        public async Task <IActionResult> AddPassword(AddPasswordViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = await userManager.GetUserAsync(User);

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

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

                await signInManager.RefreshSignInAsync(user);

                return(RedirectToAction("Index", "Home", new { msg = "sucess" }));
            }

            return(View(model));
        }