Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <...>
- [HttpPost]
- public ActionResult Logout()
- {
- Request.GetOwinContext()
- .Authentication
- .SignOut(HttpContext.GetOwinContext()
- .Authentication.GetAuthenticationTypes()
- .Select(o => o.AuthenticationType).ToArray());
- return RedirectToAction("Index", "Home");
- }
- public ActionResult Login(string returnUrl)
- {
- if (Request.IsAuthenticated)
- {
- return RedirectToAction("Index", "Home");
- }
- ViewBag.ReturnUrl = returnUrl;
- return View();
- }
- [HttpPost]
- public ActionResult Login(UserModel user, string returnUrl)
- {
- if (Request.IsAuthenticated)
- {
- return RedirectToAction("Index", "Home");
- }
- var username = user.Alias;
- var password = user.Password;
- var userMgr = new UserManager();
- if (userMgr.IsValid(username, password))
- {
- var ident = new ClaimsIdentity(
- new[] {
- new Claim(ClaimTypes.NameIdentifier, username),
- new Claim("http://schemas.microsoft.com/accesscontrolservice/2010/07/claims/identityprovider", "ASP.NET Identity", "http://www.w3.org/2001/XMLSchema#string"),
- new Claim(ClaimTypes.Name, username),
- new Claim(ClaimTypes.Role, userMgr.Role(username, password)),
- },
- DefaultAuthenticationTypes.ApplicationCookie
- );
- HttpContext.GetOwinContext().Authentication.SignIn(
- new AuthenticationProperties { IsPersistent = false }, ident);
- if (Url.IsLocalUrl(returnUrl))
- {
- return Redirect(returnUrl);
- }
- else
- {
- return RedirectToAction("Index", "Home");
- }
- }
- ModelState.AddModelError("", "Не удалось выполнить вход");
- return View();
- }
- <...>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement