更新密码找回uniapp
This commit is contained in:
1 parent
7f9a66da0f
commit
3fdda89833
1304 files changed
+3503
-26132
No files matched your search
@@ -53,7 +53,6 @@ func toPlatformLoginUser(user *models.AdminUser) *PlatformLoginUser {
|
||||
}
|
||||
}
|
||||
|
||||
// PlatformAdminLogin 平台端登录:仅校验 yz_system_admin_user,不需要租户。
|
||||
func PlatformAdminLogin(account, password, ip string) (string, *PlatformLoginUser, error) {
|
||||
account = strings.TrimSpace(account)
|
||||
password = strings.TrimSpace(password)
|
||||
@@ -74,7 +73,6 @@ func PlatformAdminLogin(account, password, ip string) (string, *PlatformLoginUse
|
||||
if !passwordutil.Verify(user.Password, password) {
|
||||
return "", nil, errors.New("用户名或密码错误")
|
||||
}
|
||||
// 历史 sha256 密码:本次登录成功后自动升级为 argon2id(失败不影响登录)
|
||||
upgradePasswordIfNeeded(user.Password, password, func(hashed string) error {
|
||||
_, err := models.Orm.QueryTable(new(models.AdminUser)).
|
||||
Filter("id", user.ID).
|
||||
@@ -89,7 +87,6 @@ func PlatformAdminLogin(account, password, ip string) (string, *PlatformLoginUse
|
||||
return "", nil, err
|
||||
}
|
||||
|
||||
// 回写最后登录 IP 与登录次数(失败不影响登录)
|
||||
_, _ = models.Orm.QueryTable(new(models.AdminUser)).
|
||||
Filter("id", user.ID).
|
||||
Update(map[string]interface{}{
|
||||
@@ -101,7 +98,6 @@ func PlatformAdminLogin(account, password, ip string) (string, *PlatformLoginUse
|
||||
return token, loginUser, nil
|
||||
}
|
||||
|
||||
// BackendLogin backend 登录:先校验租户,再校验租户下用户账号和密码。
|
||||
func BackendLogin(tenantName, account, password string) (string, *PlatformLoginUser, error) {
|
||||
tenantName = strings.TrimSpace(tenantName)
|
||||
account = strings.TrimSpace(account)
|
||||
@@ -132,7 +128,6 @@ func BackendLogin(tenantName, account, password string) (string, *PlatformLoginU
|
||||
if tenantUser.Password == nil || !passwordutil.Verify(*tenantUser.Password, password) {
|
||||
return "", nil, errors.New("用户名或密码错误")
|
||||
}
|
||||
// 历史 sha256 密码:本次登录成功后自动升级为 argon2id(失败不影响登录)
|
||||
upgradePasswordIfNeeded(*tenantUser.Password, password, func(hashed string) error {
|
||||
_, err := models.Orm.QueryTable(new(models.SystemTenantUser)).
|
||||
Filter("id", tenantUser.ID).
|
||||
@@ -143,8 +138,6 @@ func BackendLogin(tenantName, account, password string) (string, *PlatformLoginU
|
||||
tenantID := int(tenant.ID)
|
||||
const userType = "backend"
|
||||
|
||||
// 令牌中的 user_id 统一使用认证中心 identity_id(与统一登录签发的一致)。
|
||||
// 业务表的 uid 已全量迁移为同一套 ID,因此老登录入口无需停用也不会错位。
|
||||
userID := int(tenantUser.Uid)
|
||||
if identityID := authsvc.FindIdentityIDByAccount(tenant.ID, account); identityID > 0 {
|
||||
userID = int(identityID)
|
||||
@@ -174,11 +167,6 @@ func BackendLogin(tenantName, account, password string) (string, *PlatformLoginU
|
||||
return token, loginUser, nil
|
||||
}
|
||||
|
||||
// upgradePasswordIfNeeded 旧算法(legacy sha256)密码在登录成功后自动重新哈希为 argon2id。
|
||||
//
|
||||
// 旧哈希无法离线转换成新算法(无法反推明文),只能借登录时拿到的明文重新哈希,
|
||||
// 因此采用「首次登录自动升级」的渐进方式,无需强制全员重置密码。
|
||||
// 重新哈希失败不影响本次登录,仅下次登录时重试。
|
||||
func upgradePasswordIfNeeded(stored, plain string, update func(hashed string) error) {
|
||||
if !passwordutil.NeedsRehash(stored) {
|
||||
return
|
||||
@@ -190,7 +178,6 @@ func upgradePasswordIfNeeded(stored, plain string, update func(hashed string) er
|
||||
_ = update(hashed)
|
||||
}
|
||||
|
||||
// PlatformGetCurrentUser 根据平台管理员用户 ID 返回登录用户信息(含角色名称)。
|
||||
func PlatformGetCurrentUser(uid uint64) (*PlatformLoginUser, error) {
|
||||
u, err := GetAdminUserByID(uid)
|
||||
if err != nil {
|
||||
|
||||
Reference in new issue
Block a user