/// <summary> /// 登录接口 /// </summary> /// <param name="appKey">应用程序key.</param> /// <param name="username">用户名</param> /// <param name="pwd">密码</param> /// <returns>System.String.</returns> public LoginResult Login(string appKey, string username, string pwd) { var loginRequest = new PassportLoginRequest() { AppKey = appKey, Account = username, Password = pwd }; return(_loginParse.Do(loginRequest)); }
public LoginResult Do(PassportLoginRequest model) { var result = new LoginResult(); try { model.Trim(); //获取应用信息 var appInfo = _appInfoService.Get(model.AppKey); if (appInfo == null) { throw new Exception("应用不存在"); } //获取用户信息 var userInfo = _app.FindSingle(u => u.Account == model.Account); if (userInfo == null) { throw new Exception("用户不存在"); } if (userInfo.Password != Md5.GetMD5String(model.Password)) { throw new Exception("密码错误"); } var currentSession = new UserAuthSession { Account = model.Account, Name = userInfo.Name, Token = Guid.NewGuid().ToString().GetHashCode().ToString("x"), AppKey = model.AppKey, CreateTime = DateTime.Now // , IpAddress = HttpContext.Current.Request.UserHostAddress }; //创建Session _cacheContext.Set(currentSession.Token, currentSession, DateTime.Now.AddDays(10)); result.Code = 200; result.ReturnUrl = appInfo.ReturnUrl; result.Token = currentSession.Token; } catch (Exception ex) { result.Code = 500; result.Message = ex.Message; } return(result); }