Ejemplo n.º 1
0
 public IActionResult ChangePassword(string id)
 {
     var model = new ChangePasswordViewModel { ClassRoom = id };
     return View(model);
 }
Ejemplo n.º 2
0
        public async Task<IActionResult> ChangePassword(ChangePasswordViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return View(model);
            }

            var user = await GetCurrentUserAsync();
            if (user != null)
            {
                var result = await _userManager.ChangePasswordAsync(user, model.OldPassword, model.NewPassword);
                if (result.Succeeded)
                {
                    await _signInManager.SignInAsync(user, isPersistent: false);
                    _logger.LogInformation(3, "User changed their password successfully.");
                    if (string.IsNullOrEmpty(model.ClassRoom)) return RedirectToAction(nameof(Index), new { Message = ManageMessageId.ChangePasswordSuccess });
                    else
                    {
                        var redirectURL = $"/my#!/app/course/{ model.ClassRoom }/setting";
                        return Redirect(redirectURL);
                    }
                }
                AddErrors(result);
                return View(model);
            }
            return RedirectToAction(nameof(Index), new { Message = ManageMessageId.Error });
        }
Ejemplo n.º 3
0
 public async Task<IActionResult> ChangePassword(ChangePasswordViewModel model)
 {
     if (!ModelState.IsValid)
     {
         return View(model);
     }
     var user = await GetCurrentUserAsync();
     var redirectURL = string.Format("/My#/app/course/{0}/setting", model.ClassRoom);
     if (user != null)
     {
         var result = await _userManager.ChangePasswordAsync(user, model.OldPassword, model.NewPassword);
         if (result.Succeeded)
         {
             await _signInManager.SignInAsync(user, isPersistent: false);
             _logger.LogInformation(3, "User changed their password successfully.");
             return Redirect(redirectURL);
         }
         AddErrors(result);
         return View(model);
     }
     return Redirect(redirectURL);
 }