统一单入口 Go 工程与前端依赖目录,增加后台供应商配置、候选审核、计划预算、成交冲正、持仓复盘和站内通知。接入策略版本、Python 回测、可配置 A 股公开行情及 zap 文件轮转日志,补充迁移、契约与验证。
This commit is contained in:
@@ -23,7 +23,7 @@ import (
|
||||
type AuthRepository interface {
|
||||
CreateUser(context.Context, model.User, model.Credential) (model.User, error)
|
||||
FindCredential(context.Context, string) (model.User, model.Credential, error)
|
||||
CreateSession(context.Context, model.Session) error
|
||||
CreateSession(context.Context, model.Session, string) error
|
||||
FindSessionUser(context.Context, string, string, time.Time) (model.User, error)
|
||||
RevokeSession(context.Context, string, string, time.Time) error
|
||||
ListUsers(context.Context, int) ([]model.User, error)
|
||||
@@ -49,7 +49,11 @@ var loginPattern = regexp.MustCompile(`^[a-z0-9_]{3,64}$`)
|
||||
func (s *AuthService) ProvisionUser(ctx context.Context, login, password, name, role string) (model.User, error) {
|
||||
login = strings.ToLower(strings.TrimSpace(login))
|
||||
name = strings.TrimSpace(name)
|
||||
if !loginPattern.MatchString(login) || len(password) < 12 || len(password) > 72 || utf8.RuneCountInString(name) > 80 || name == "" || (role != "USER" && role != "ADMIN") {
|
||||
minimumPasswordLength := 12
|
||||
if role == "ADMIN" {
|
||||
minimumPasswordLength = 8
|
||||
}
|
||||
if !loginPattern.MatchString(login) || len(password) < minimumPasswordLength || len(password) > 72 || utf8.RuneCountInString(name) > 80 || name == "" || (role != "USER" && role != "ADMIN") {
|
||||
return model.User{}, apperror.ErrInvalidInput
|
||||
}
|
||||
if s.repo == nil {
|
||||
@@ -99,7 +103,7 @@ func (s *AuthService) Login(ctx context.Context, login, password, audience strin
|
||||
token := base64.RawURLEncoding.EncodeToString(raw)
|
||||
expires := s.now().UTC().Add(8 * time.Hour)
|
||||
session := model.Session{ID: uuid.NewString(), UserID: user.ID, TokenHash: TokenHash(token), Audience: audience, ExpiresAt: expires}
|
||||
if err := s.repo.CreateSession(ctx, session); err != nil {
|
||||
if err := s.repo.CreateSession(ctx, session, credential.PasswordHash); err != nil {
|
||||
return LoginResult{}, err
|
||||
}
|
||||
return LoginResult{User: user, Token: token, ExpiresAt: expires}, nil
|
||||
|
||||
Reference in New Issue
Block a user