public async Task <ActionResult> Login(LoginViewModel model, string returnUrl) { if (!ModelState.IsValid) { return(View(model)); } // This doesn't count login failures towards account lockout // To enable password failures to trigger account lockout, change to shouldLockout: true var result = await SignInManager.PasswordSignInAsync(model.Email, model.Password, model.RememberMe, shouldLockout : false); switch (result) { case SignInStatus.Success: logService.LogInDb(model.Email, LogAction.LogInSuccess); return(RedirectToLocal(returnUrl)); case SignInStatus.LockedOut: logService.LogInDb(model.Email, LogAction.LogInLockedOut); return(View("Lockout")); case SignInStatus.RequiresVerification: return(RedirectToAction("SendCode", new { ReturnUrl = returnUrl, RememberMe = model.RememberMe })); case SignInStatus.Failure: default: ModelState.AddModelError("", "Invalid login attempt."); logService.LogInDb(model.Email, LogAction.LogInFailure); return(View(model)); } }
public async Task <ActionResult> RegisterByAdmin(string id) { var user = db.Users.SingleOrDefault(u => u.Id == id); if (user == null) { return(HttpNotFound()); } user.AccountStatus = AccountStatus.ActivatedByAdmin; var result = db.SaveChangesAsync(); // Save activation link to user string codeForUser = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id); var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, codeForUser = codeForUser }, protocol: Request.Url.Scheme); logService.LogInDb(user.Email, LogAction.UserRegistrationAccept); await UserManager.SendEmailAsync(user.Id, "Bekræft oprettelse af brugerkonto", "Bekræft oprettelse af din bruger ved at klikke <a href=\"" + callbackUrl + "\">her</a>"); return(RedirectToAction("Index")); }
public async Task <ActionResult> ChangePassword(ChangePasswordViewModel model) { if (!ModelState.IsValid) { return(View(model)); } var result = await UserManager.ChangePasswordAsync(User.Identity.GetUserId(), model.OldPassword, model.NewPassword); if (result.Succeeded) { logService.LogInDb(User.Identity.GetUserName(), LogAction.PasswordChange); 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.ChangePasswordSuccess })); } logService.LogInDb(User.Identity.GetUserName(), LogAction.PasswordChangeFailure); AddErrors(result); return(View(model)); }