public async Task<ActionResult> Login(UserLoginViewModel user) { if (!ModelState.IsValid) return View(user); if (ModelState.IsValid) { var userLogin = await UserRepository.LoginAsync(user.Email, user.Password); if (userLogin != null) { var identities = new ClaimsIdentity(new[] { new Claim(ClaimTypes.Name,userLogin.Email), new Claim(ClaimTypes.Role,userLogin.Role.Name), new Claim(ClaimTypes.Email, user.Email), new Claim(ClaimTypes.Country,userLogin.Sites.Name)}, "ApplicationCookie", ClaimTypes.Name, ClaimTypes.Role); AuthenticationManager.SignIn(identities); return Redirect(GetRedirectUrl(user.ReturnUrl)); } else { ModelState.AddModelError("", "Login data is incorrect or User is not yet allowed. Contact System Administrator!"); return View(user); } } return View(); }
public ActionResult LogIn(string ReturnUrl) { var userLogin = new UserLoginViewModel() { ReturnUrl = ReturnUrl }; return View(userLogin); }