public ActionResult LogOff() { AuthenticationManager.SignOut(); logger.Info($"User with name {User.Identity.GetUserName()} logoff"); Infrostructure.StartUpdatingCounters("LogOut"); return(RedirectToAction("Index", "Home")); }
public async Task <ActionResult> Register(RegisterViewModel model) { if (ModelState.IsValid) { var user = new ApplicationUser { UserName = model.UserName }; var result = await _userManager.CreateAsync(user, model.Password); if (result.Succeeded) { await SignInAsync(user, false); logger.Info($"User {user.UserName} successfully registreted"); Infrostructure.StartUpdatingCounters("Registration"); return(RedirectToAction("Index", "Home")); } else { logger.Error($"User {user.UserName} can not register"); } AddErrors(result); } return(View(model)); }
public async Task <ActionResult> Login(LoginViewModel model, string returnUrl) { if (ModelState.IsValid) { var user = await _userManager.FindAsync(model.UserName, model.Password); if (user != null) { await SignInAsync(user, model.RememberMe); logger.Info($"User {user.UserName} successfully authorized"); Infrostructure.StartUpdatingCounters("LogIn"); return(RedirectToLocal(returnUrl)); } logger.Error($"User authorization error"); ModelState.AddModelError("", "Invalid username or password."); } return(View(model)); }