111
This commit is contained in:
@@ -5,6 +5,9 @@ public interface IUnitUserService
|
||||
#region 用户信息
|
||||
|
||||
Task<List<unit_user>> GetUserDataByAccId(string accId);
|
||||
Task<unit_user> GetUserInfoByUserId(string userId);
|
||||
Task<unit_user> GetUserInfoByUserNo(string userNo);
|
||||
Task<unit_user> GetUserInfoByToken(string token);
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -18,5 +21,7 @@ public interface IUnitUserService
|
||||
/// <returns></returns>
|
||||
Task<unit_user> Register(int areaId, string accId);
|
||||
|
||||
Task<bool> RegisterUserInfo(string userId, string nick, string sex);
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -19,6 +19,22 @@ public class UnitUserService : IUnitUserService, ITransient
|
||||
var db = _dbClient.AsTenant().GetConnectionWithAttr<unit_user>();
|
||||
return await db.Queryable<unit_user>().Where(it => it.accId == accId).ToListAsync();
|
||||
}
|
||||
public async Task<unit_user> GetUserInfoByUserId(string userId)
|
||||
{
|
||||
string key = string.Format(UserCache.BaseCacheKeys, "UserInfo", "UserId");
|
||||
var data = await _redisClient.GetHashAsync<unit_user>(key, userId);
|
||||
if (data == null)
|
||||
{
|
||||
var db = _dbClient.AsTenant().GetConnectionWithAttr<unit_user>();
|
||||
data = await db.Queryable<unit_user>().Where(it => it.userId == userId).SingleAsync();
|
||||
if (data != null)
|
||||
{
|
||||
await _redisClient.AddHashAsync(key, userId, data);
|
||||
}
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
public async Task<unit_user> GetUserInfoByUserNo(string userNo)
|
||||
{
|
||||
string key = string.Format(UserCache.BaseCacheKeys, "UserInfo", "UserNo");
|
||||
@@ -36,9 +52,9 @@ public class UnitUserService : IUnitUserService, ITransient
|
||||
return data;
|
||||
}
|
||||
|
||||
public async Task<unit_user> GetUserInfoBySid(string token)
|
||||
public async Task<unit_user> GetUserInfoByToken(string token)
|
||||
{
|
||||
string key = string.Format(UserCache.BaseCacheKeys, "UserInfo", "Sid");
|
||||
string key = string.Format(UserCache.BaseCacheKeys, "UserInfo", "token");
|
||||
var data = await _redisClient.GetHashAsync<unit_user>(key, token);
|
||||
if (data == null)
|
||||
{
|
||||
@@ -52,6 +68,23 @@ public class UnitUserService : IUnitUserService, ITransient
|
||||
|
||||
return data;
|
||||
}
|
||||
private async Task ClearUserInfo(int type, string id)
|
||||
{
|
||||
unit_user result = new unit_user();
|
||||
switch (type)
|
||||
{
|
||||
case 0:
|
||||
result = await GetUserInfoByUserId(id);
|
||||
break;
|
||||
|
||||
case 1:
|
||||
result = await GetUserInfoByToken(id);
|
||||
break;
|
||||
}
|
||||
await _redisClient.DelHashAsync(string.Format(UserCache.BaseCacheKeys, "UserInfo","UserId"), result.userId);
|
||||
await _redisClient.DelHashAsync(string.Format(UserCache.BaseCacheKeys, "UserInfo","UserNo"), result.userNo);
|
||||
await _redisClient.DelHashAsync(string.Format(UserCache.BaseCacheKeys, "UserInfo","Sid"), result.token);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -98,8 +131,27 @@ public class UnitUserService : IUnitUserService, ITransient
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public async Task<int> GetUserNo()
|
||||
public async Task<bool> RegisterUserInfo(string userId, string nick, string sex)
|
||||
{
|
||||
var db = _dbClient.AsTenant().GetConnectionWithAttr<unit_user>();
|
||||
bool result = await db.Updateable<unit_user>().SetColumns(it => it.nick == nick)
|
||||
.SetColumns(it => it.sex == sex)
|
||||
.SetColumns(it => it.regOk == 1)
|
||||
.Where(it => it.userId == userId).ExecuteCommandAsync() > 0;
|
||||
if (result)
|
||||
{
|
||||
//注册配置信息
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
await ClearUserInfo(0, userId);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
private async Task<int> GetUserNo()
|
||||
{
|
||||
int No = 0;
|
||||
bool ok = true;
|
||||
@@ -117,18 +169,18 @@ public class UnitUserService : IUnitUserService, ITransient
|
||||
|
||||
private async Task<string> GetToken()
|
||||
{
|
||||
string sid = string.Empty;
|
||||
string token = string.Empty;
|
||||
bool ok = true;
|
||||
while (ok)
|
||||
{
|
||||
sid = StringAssist.RandomString(32);
|
||||
if (await GetUserInfoBySid(sid) == null)
|
||||
token = StringAssist.RandomString(32);
|
||||
if (await GetUserInfoByToken(token) == null)
|
||||
{
|
||||
ok = false;
|
||||
}
|
||||
}
|
||||
|
||||
return sid;
|
||||
return token;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
Reference in New Issue
Block a user