public ActionResult Index(string appKey = "", string username = "") { var viewModel = new PassportLoginRequest { AppKey = appKey, UserName = username }; return View(viewModel); }
public async Task<ActionResult> Index(PassportLoginRequest model) { if (ModelState.IsValid == false) { //实体验证失败 return View(model); } var user = await UserManager.FindAsync(model.UserName, model.Password); if (user == null) { ModelState.AddModelError("", "Invalid username or password."); return View(model); } //获取当前未到期的Session var currentSession = _authSessionService.GetValidAuthSession(model.AppKey, user.UserName); if (currentSession == null) { currentSession = new UserAuthSession { AppKey = model.AppKey, CreateTime = DateTime.Now, InvalidTime = DateTime.Now.AddYears(1), IpAddress = Request.UserHostAddress, SessionKey = Guid.NewGuid().ToString().ToMd5(), UserName = user.UserName }; _authSessionService.Create(currentSession); } else { _authSessionService.RefreshSession(currentSession); } var redirectUrl = string.Format("{0}?SessionKey={1}&SessionUserName={2}", "http://test.com", currentSession.SessionKey, user.UserName); //跳转默认回调页面 return Redirect(redirectUrl); }