fix 用户同步和设备ignoreTenant
This commit is contained in:
@@ -75,6 +75,7 @@ public class DevicesConnectController : ControllerBase
|
||||
/// <param name="factory"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("brand-devices")]
|
||||
[IgnoreTenant]
|
||||
public async Task<List<DeviceUniqueWithConnectionInfoDto>> GetDeviceUniqueInfoByBrandAsync(
|
||||
[Required(ErrorMessage = "请明确设备品牌")] string brand,
|
||||
[Required(ErrorMessage = "请明确厂区")] string factory)
|
||||
|
||||
@@ -19,71 +19,69 @@ public class UpdateUserPasswordJob : BaseJob
|
||||
|
||||
protected override async Task RunAsync(IServiceProvider serviceProvider)
|
||||
{
|
||||
|
||||
var identityDbContext = DbContext.ChangeDb("identity");
|
||||
|
||||
var whitelist = new List<string>() { "admin", "WB-0741", "WB-1091", "0123456" };
|
||||
|
||||
var users = await identityDbContext.Queryable<UserEntity>()
|
||||
.Where(x => !whitelist.Contains(x.UserName))
|
||||
.ToListAsync();
|
||||
.Where(x => !whitelist.Contains(x.UserName))
|
||||
.ToListAsync();
|
||||
|
||||
var gainfos = await DbContext.Queryable<GainfoEntity>().Where(x => !whitelist.Contains(x.Code)).ToListAsync();
|
||||
|
||||
var hasher = new PasswordHasher<UserEntity>();
|
||||
foreach (var gainfo in gainfos)
|
||||
{
|
||||
if (gainfo.IdNo.IsPresent())
|
||||
if (gainfo.IdNo.IsEmpty()) continue;
|
||||
|
||||
try
|
||||
{
|
||||
try
|
||||
{
|
||||
var password = gainfo.IdNo.TakeLast(6).Join("");
|
||||
var password = gainfo.IdNo.TakeLast(6).Join("");
|
||||
|
||||
var user = users.FirstOrDefault(x => x.UserName == gainfo.Code);
|
||||
if (user == null)
|
||||
{
|
||||
user = new UserEntity
|
||||
{
|
||||
UserName = gainfo.Code,
|
||||
NormalizedUserName = gainfo.Code.ToUpper(),
|
||||
ConcurrencyStamp = Guid.NewGuid().ToString(),
|
||||
SecurityStamp = Guid.NewGuid().ToString(),
|
||||
};
|
||||
password = hasher.HashPassword(user, password);
|
||||
user.PasswordHash = password;
|
||||
var user = users.FirstOrDefault(x => x.UserName == gainfo.Code);
|
||||
if (user != null) continue;
|
||||
|
||||
var id = (int)await identityDbContext.InsertReturnIdentityAsync(user);
|
||||
await AddUserClaim(identityDbContext, id, "jinko-code", gainfo.Code);
|
||||
await AddUserClaim(identityDbContext, id, "name", gainfo.Name);
|
||||
if (!string.IsNullOrEmpty(gainfo.Factory))
|
||||
{
|
||||
var userTenant = await identityDbContext.Queryable<UserTenantEntity>().Where(x => x.UserId == user.Id).FirstAsync();
|
||||
if (userTenant == null)
|
||||
{
|
||||
userTenant = new UserTenantEntity
|
||||
{
|
||||
UserId = user.Id,
|
||||
TenantCode = gainfo.Factory
|
||||
};
|
||||
await identityDbContext.InsertAsync(userTenant);
|
||||
}
|
||||
else
|
||||
{
|
||||
userTenant.TenantCode = gainfo.Factory;
|
||||
await identityDbContext.UpdateAsync(userTenant);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//password = hasher.HashPassword(user, password);
|
||||
//user.PasswordHash = password;
|
||||
//await identityDbContext.UpdateAsync(user);
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
user = new UserEntity
|
||||
{
|
||||
UserName = gainfo.Code,
|
||||
NormalizedUserName = gainfo.Code.ToUpper(),
|
||||
ConcurrencyStamp = Guid.NewGuid().ToString(),
|
||||
SecurityStamp = Guid.NewGuid().ToString(),
|
||||
};
|
||||
password = hasher.HashPassword(user, password);
|
||||
user.PasswordHash = password;
|
||||
|
||||
var id = (int)await identityDbContext.InsertReturnIdentityAsync(user);
|
||||
await AddUserClaim(identityDbContext, id, "jinko-code", gainfo.Code);
|
||||
await AddUserClaim(identityDbContext, id, "name", gainfo.Name);
|
||||
|
||||
if (string.IsNullOrEmpty(gainfo.Factory)) continue;
|
||||
|
||||
var userTenant = await identityDbContext.Queryable<UserTenantEntity>().Where(x => x.UserId == user.Id).FirstAsync();
|
||||
if (userTenant == null)
|
||||
{
|
||||
userTenant = new UserTenantEntity
|
||||
{
|
||||
UserId = user.Id,
|
||||
TenantCode = gainfo.Factory
|
||||
};
|
||||
await identityDbContext.InsertAsync(userTenant);
|
||||
}
|
||||
else
|
||||
{
|
||||
userTenant.TenantCode = gainfo.Factory;
|
||||
await identityDbContext.UpdateAsync(userTenant);
|
||||
}
|
||||
// else
|
||||
// {
|
||||
// password = hasher.HashPassword(user, password);
|
||||
// user.PasswordHash = password;
|
||||
// await identityDbContext.UpdateAsync(user);
|
||||
// }
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
//ignore
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -107,4 +105,4 @@ public class UpdateUserPasswordJob : BaseJob
|
||||
await dbContext.UpdateAsync(claim);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user