public ActionResult LogOn(LogOnModel model) { var returnUrl = model.ReturnUrl; if (ModelState.IsValid) { var user = userManager.ValidateAndReturnUser(model.UserName, model.Password); if (user != null && !user.IsLockedOut) { userManager.Lock(user.Id, false); SignIn(user, true); if (Url.IsLocalUrl(returnUrl) && returnUrl.Length > 1 && returnUrl.StartsWith("/") && !returnUrl.StartsWith("//") && !returnUrl.StartsWith("/\\") && !returnUrl.Contains("/Account/LogOn")) { return(Redirect(returnUrl)); } else { return(RedirectToAction("Index", "Home")); } } else { ModelState.AddModelError("password", "Felaktigt användarnamn eller lösenord."); //turn LogOn(model.ReturnUrl); } } // If we got this far, something failed, redisplay form return(View(model)); }
public IHttpActionResult GetAccessToken(string username, string password) { var user = userManager.ValidateAndReturnUser(username, password); if (user != null && !user.IsLockedOut) { userManager.Lock(user.Id, false); var userId = user.Id; var clientId = user.ClientId; var newToken = tokenGenerator.GetToken(userId); var accessTokenForClient = new AcccessTokenForClient(newToken, (int)clientId); return(Ok(accessTokenForClient)); } else { return(Unauthorized()); } }