fix 更新密码
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
using Dlhis.Entity.Basic.Entity;
|
||||
using Dlhis.Entity.Sys.Entities;
|
||||
using Kurisu.AspNetCore.Authentication.Options;
|
||||
using Kurisu.AspNetCore.Utils.Extensions;
|
||||
using Kurisu.Core.DataAccess.Entity;
|
||||
using Kurisu.SqlSugar.Services;
|
||||
using Microsoft.AspNetCore.Identity;
|
||||
@@ -32,57 +33,78 @@ namespace Dlhis.ScheduledTask.CommonJobs
|
||||
_dbContext.Client.QueryFilter.ClearAndBackup<ITenantId>();
|
||||
try
|
||||
{
|
||||
|
||||
var identityDbContext = _dbContext.ChangeDb("identity");
|
||||
|
||||
var userNames = await identityDbContext.Queryable<UserEntity>().Select(x => x.UserName).ToListAsync();
|
||||
var newUser = await _dbContext.Queryable<GainfoEntity>()
|
||||
.Where(x => !string.IsNullOrEmpty(x.Code))
|
||||
.Where(x => !userNames.Contains(x.Code))
|
||||
.Select(x => new
|
||||
{
|
||||
x.Code,
|
||||
x.Factory,
|
||||
x.Name,
|
||||
})
|
||||
.ToListAsync();
|
||||
//HST0001
|
||||
var users = await identityDbContext.Queryable<UserEntity>().Where(x => x.UserName != "HST0001")
|
||||
.Where(x => x.Id > 21)
|
||||
.ToListAsync();
|
||||
|
||||
var httpClient = _httpClientFactory.CreateClient();
|
||||
httpClient.BaseAddress = new Uri(_identityServerOptions.Authority);
|
||||
var gainfos = await _dbContext.Queryable<GainfoEntity>().ToListAsync();
|
||||
|
||||
var hasher = new PasswordHasher<UserEntity>();
|
||||
foreach (var item in newUser)
|
||||
foreach (var user in users)
|
||||
{
|
||||
var userName = item.Code;
|
||||
var password = item.Code;
|
||||
var factory = item.Factory;
|
||||
|
||||
if (password.Length > 6)
|
||||
var gainfo = gainfos.FirstOrDefault(x => x.Code == user.UserName);
|
||||
if (gainfo != null && gainfo.IdNo.IsPresent())
|
||||
{
|
||||
password = string.Join("", password.TakeLast(6));
|
||||
var password = gainfo.IdNo.TakeLast(6).Join("");
|
||||
password = hasher.HashPassword(user, password);
|
||||
user.PasswordHash = password;
|
||||
await identityDbContext.UpdateAsync(user);
|
||||
}
|
||||
else
|
||||
{
|
||||
password = password.PadLeft(6, '0');
|
||||
}
|
||||
var user = new UserEntity
|
||||
{
|
||||
UserName = userName,
|
||||
NormalizedUserName = userName.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 identityDbContext.InsertAsync(new UserTenantEntity() { UserId = id, TenantCode = factory });
|
||||
await identityDbContext.InsertAsync(new List<UserClaimEntity>
|
||||
{
|
||||
new UserClaimEntity{ UserId = id , ClaimType ="preferred_username", ClaimValue = item.Name},
|
||||
new UserClaimEntity{ UserId = id , ClaimType ="jinko-code", ClaimValue = item.Code},
|
||||
});
|
||||
}
|
||||
|
||||
//var userNames = await identityDbContext.Queryable<UserEntity>().Select(x => x.UserName).ToListAsync();
|
||||
//var newUser = await _dbContext.Queryable<GainfoEntity>()
|
||||
// .Where(x => !string.IsNullOrEmpty(x.Code))
|
||||
// .Where(x => !userNames.Contains(x.Code))
|
||||
// .Select(x => new
|
||||
// {
|
||||
// x.Code,
|
||||
// x.Factory,
|
||||
// x.Name,
|
||||
// })
|
||||
// .ToListAsync();
|
||||
|
||||
//var httpClient = _httpClientFactory.CreateClient();
|
||||
//httpClient.BaseAddress = new Uri(_identityServerOptions.Authority);
|
||||
|
||||
//var hasher = new PasswordHasher<UserEntity>();
|
||||
//foreach (var item in newUser)
|
||||
//{
|
||||
// var userName = item.Code;
|
||||
// var password = item.Code;
|
||||
// var factory = item.Factory;
|
||||
|
||||
// if (password.Length > 6)
|
||||
// {
|
||||
// password = string.Join("", password.TakeLast(6));
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// password = password.PadLeft(6, '0');
|
||||
// }
|
||||
// var user = new UserEntity
|
||||
// {
|
||||
// UserName = userName,
|
||||
// NormalizedUserName = userName.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 identityDbContext.InsertAsync(new UserTenantEntity() { UserId = id, TenantCode = factory });
|
||||
// await identityDbContext.InsertAsync(new List<UserClaimEntity>
|
||||
// {
|
||||
// new UserClaimEntity{ UserId = id , ClaimType ="preferred_username", ClaimValue = item.Name},
|
||||
// new UserClaimEntity{ UserId = id , ClaimType ="jinko-code", ClaimValue = item.Code},
|
||||
// });
|
||||
//}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user