Files
yunzerwebsiteallinone/go/models/auth_identity.go
T
2026-09-19 21:44:04 +08:00

73 lines
3.4 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package models
import "time"
// 身份状态
const (
AuthIdentityStatusEnabled = 1 // 启用
AuthIdentityStatusDisabled = 0 // 禁用
AuthIdentityStatusLocked = 2 // 锁定(连续失败过多)
)
// AuthIdentity 统一身份(自然人):yz_auth_identity
//
// 统一认证中心的核心表。密码上提到这一层,一个自然人一份密码,
// 通过 yz_auth_tenant_user 绑定到多家企业(一人可在多家企业任职)。
//
// password_hash 存储 PHC 格式($argon2id$v=19$m=...,t=...,p=...$salt$hash),
// 盐与参数内联,无需独立 salt 列;历史数据为 salt$sha256(legacy),
// 首次登录成功时自动重新哈希为 argon2id。
type AuthIdentity struct {
ID uint64 `orm:"column(id);pk;auto" json:"id"`
UnionID string `orm:"column(union_id);size(32)" json:"union_id"`
Mobile *string `orm:"column(mobile);size(20);null" json:"mobile"`
Email *string `orm:"column(email);size(128);null" json:"email"`
PasswordAlgo string `orm:"column(password_algo);size(16);default(argon2id)" json:"password_algo"`
PasswordHash *string `orm:"column(password_hash);size(255);null" json:"-"`
PasswordVer int `orm:"column(password_ver);default(1)" json:"password_ver"`
Nickname *string `orm:"column(nickname);size(64);null" json:"nickname"`
Avatar *string `orm:"column(avatar);size(500);null" json:"avatar"`
MfaEnabled int8 `orm:"column(mfa_enabled);default(0)" json:"mfa_enabled"`
MfaSecret *string `orm:"column(mfa_secret);size(128);null" json:"-"`
Status int8 `orm:"column(status);default(1)" json:"status"`
FailCount int `orm:"column(fail_count);default(0)" json:"fail_count"`
LockedUntil *time.Time `orm:"column(locked_until);type(datetime);null" json:"locked_until"`
LastLoginAt *time.Time `orm:"column(last_login_at);type(datetime);null" json:"last_login_at"`
LastLoginIP *string `orm:"column(last_login_ip);size(45);null" json:"last_login_ip"`
CreateTime time.Time `orm:"column(create_time);auto_now_add;type(datetime)" json:"create_time"`
UpdateTime time.Time `orm:"column(update_time);auto_now;type(datetime)" json:"update_time"`
DeleteTime *time.Time `orm:"column(delete_time);type(datetime);null" json:"delete_time"`
}
func (m *AuthIdentity) TableName() string {
return "yz_auth_identity"
}
// 第三方登录 provider 常量
const (
IdPWechat = "wechat"
IdPDingTalk = "dingtalk"
IdPFeishu = "feishu"
IdPQQ = "qq"
IdPGitHub = "github"
IdPGoogle = "google"
)
// AuthIdentityThird 第三方身份绑定:yz_auth_identity_third
// 同一身份可绑定多个第三方账号;同一 provider 的 open_id 全局唯一。
type AuthIdentityThird struct {
ID uint64 `orm:"column(id);pk;auto" json:"id"`
IdentityID uint64 `orm:"column(identity_id)" json:"identity_id"`
Provider string `orm:"column(provider);size(32)" json:"provider"`
OpenID string `orm:"column(open_id);size(128)" json:"open_id"`
UnionID *string `orm:"column(union_id);size(128);null" json:"union_id"`
Nickname *string `orm:"column(nickname);size(128);null" json:"nickname"`
Avatar *string `orm:"column(avatar);size(500);null" json:"avatar"`
Raw *string `orm:"column(raw);type(text);null" json:"raw"`
BindTime time.Time `orm:"column(bind_time);auto_now_add;type(datetime)" json:"bind_time"`
}
func (m *AuthIdentityThird) TableName() string {
return "yz_auth_identity_third"
}