public async Task <IActionResult> LoginResponse(string data) { var clinetResponse = ClientResponse.FromJSON(data); var challenge = ePass.GetServerChallenge(clinetResponse.Id); var result = await ePass.VerifyClientResponse(clinetResponse, false); StringBuilder stringBuilder = new StringBuilder(); foreach (var item in Request.Headers) { stringBuilder.Append(item.Key + "=" + item.Value.ToString() + "\r\n"); } LoggingLogin logg = new LoggingLogin() { Id = this.idGenerator.NextId(), LoginDateTime = DateTime.Now, LoginMethod = "SmartToken", Ip = Request.Host.Host, BrowserRequestHeader = stringBuilder.ToString(), }; ApiRe apiRe = new ApiRe(); try { if (result) { var userId = challenge.UserId; var user = userService.GetUserByUserId(userId); // var token = tokenSerivce.GenerateToken(user.UserId, user.Email); //tokenSerivce.SaveToken(token); //登录日志 logg.UserId = user.UserId; logg.IsLoginSuccess = true; apiRe.Ok = true; this.distributedCache.SetBool("USBKEY" + challenge.RequestNumber, true); //apiRe.Data = userToken; return(LeanoteJson(apiRe)); } else { return(LeanoteJson(apiRe)); } } finally { await logg.AddMac(this.cryptographyProvider); this.logging.Save(logg); } }
public async Task <IActionResult> Login(string email, string pwd, string requestNumber) { string tokenValue = ""; var re = new ApiRe(); StringBuilder stringBuilder = new StringBuilder(); foreach (var item in Request.Headers) { stringBuilder.Append(item.Key + "=" + item.Value.ToString() + "\r\n"); } LoggingLogin logg = new LoggingLogin() { Id = this.idGenerator.NextId(), LoginDateTime = DateTime.Now, LoginMethod = "PassWord", Ip = Request.Host.Host, BrowserRequestHeader = stringBuilder.ToString(), }; try { var tokenStr = await authService.LoginByPWD(email, pwd); if (!string.IsNullOrEmpty(tokenStr)) { var user = userService.GetUserByEmail(email); if (this.config.SecurityConfig.LogNeedHmac) { user.VerifyHmac(this.cryptographyProvider); if (!user.Verify) { re.Msg = "VerifyHmac is Error"; return(LeanoteJson(re)); } } var userToken = new UserToken() { Token = tokenStr, UserId = user.UserId, Email = user.Email, Username = user.Username }; re.Ok = true; //re.Data = userToken; this.distributedCache.SetBool("Password" + requestNumber, true); logg.UserId = user.UserId; logg.IsLoginSuccess = true; return(LeanoteJson(re)); } else { re.Msg = "用户名或密码有误"; logg.ErrorMessage = "用户名或密码有误"; return(LeanoteJson(re)); } } catch (Exception ex) { re.Msg = ex.Message; re.Ok = false; return(LeanoteJson(re)); } finally { await logg.AddMac(this.cryptographyProvider); this.logging.Save(logg); } }