public IdentityInfo GetAuthInfo() { if (string.IsNullOrEmpty(this._token)) { return(null); } if (this._identity == null) { this._identity = CacheHelper.GetCache <IdentityInfo>(string.Format(RedisKeyConst.Login_LoginApiToken, _token)); if (this._identity == null) { return(null); } } this._identity.Token = this._token; DateTime expireTime = DateTime.Now.AddMinutes(43200.0); TimeSpan span = (TimeSpan)(expireTime - this._identity.ExpireTime); if (span.TotalMinutes > 21600.0) { this._identity.ExpireTime = expireTime; CacheHelper.SetCache(string.Format(RedisKeyConst.Login_LoginApiToken, _token), _identity, expireTime); this._container.SetToken(this._token, expireTime); } return(this._identity); }
public void Update(IdentityInfo identity, DateTime expireTime) { identity.ExpireTime = expireTime; try { //CacheHelper.SetCache("identity_" + _token, identity, identity.ExpireTime); CacheHelper.SetCache(string.Format(RedisKeyConst.Login_LoginApiToken, _token), identity, identity.ExpireTime); } catch (Exception ex) { throw new ApiException(-100, "缓存设置失败,身份标识操作无效"); } }
public static IdentityInfo GetAuthInfo(string token) { if (string.IsNullOrEmpty(token)) { return(null); } IdentityInfo info = CacheHelper.GetCache <IdentityInfo>(string.Format(RedisKeyConst.Login_LoginApiToken, token)); if (info == null) { return(null); } return(info); }
public void Authorize(IdentityInfo identity) { DateTime now = DateTime.Now; DateTime expireTime = now.AddMinutes(43200.0); identity.AuthTime = now; identity.ExpireTime = expireTime; this._token = PermissionHelper.EncryptToken(identity.UserId, now); identity.Token = this._token; try { //CacheHelper.WriteCache("identity_" + _token, identity, 43200); CacheHelper.AddCache(string.Format(RedisKeyConst.Login_LoginApiToken, _token), identity, 43200); } catch (Exception ex) { throw new ApiException(-100, "缓存设置失败,身份标识操作无效"); } this._container.SetToken(this._token, expireTime); }
private static IdentityInfo AuthCheckingOfDefault(string userAccount, string loginPassword) { UserInfoService service = new UserInfoService(); UserInfo accountInfo = service.GetUserInfoByMobile(userAccount); if (accountInfo == null) { throw new ApiException(15023, "用户名不存在或密码错误"); } if (accountInfo.Password.StartsWith("$2y")) { if (!Crypter.CheckPassword(loginPassword, accountInfo.Password)) { throw new ApiException(15023, "用户名不存在或密码错误"); } if (Tool.GetMD5(loginPassword) != accountInfo.Password) { throw new ApiException(15023, "用户名不存在或密码错误"); } //if (HashHelper.Encrypt(HashCryptoType.MD5, loginPassword, "") != accountInfo.Password) //{ // throw new ApiException(15023, "用户名不存在或密码错误"); //} } IdentityInfo info = accountInfo.ToIdentityInfo(); if (info != null) { //TODO:查询第三方绑定信息 } return(info); }