public ActionResult ULogin(string username, string password) { var Account = _userService.Login(username, password); if (Account == null) { return(RedirectToAction("ULogin")); } else { Session["UserId"] = Account.Id; Session["Role"] = Account.Role.Id; if (Account.Role.Id == 1) { return(RedirectToAction("Index", "Admin")); } else if (Account.Role.Id == 2) { return(RedirectToAction("Index", "Delivery")); } else { return(RedirectToAction("ULogin")); } } }
public override Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context) { try { var _userService = new SystemUserService(); var user = _userService.Login(context.UserName, context.Password); var ticket = GenerateTicket(context.ClientId, user); context.Validated(ticket); } catch (Exception ex) { var err = new CatchError(ex); context.SetError(err.name, err.message); } return(Task.FromResult <object>(null)); }
public async Task <IActionResult> DoLogin(LoginRequest request) { var ro = systemUserBusiness.Login(request); if (ro.Success) { var claims = new List <Claim> { new Claim("userid", ro.Result.Id.ToString()), new Claim("nickname", ro.Result.Nickname) }; var claimsIdentity = new ClaimsIdentity(claims, CookieAuthenticationDefaults.AuthenticationScheme); await HttpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, new ClaimsPrincipal(claimsIdentity)); ro.Result = null; return(Json(ro)); } else { return(Json(ro)); } }