统一单入口 Go 工程与前端依赖目录,增加后台供应商配置、候选审核、计划预算、成交冲正、持仓复盘和站内通知。接入策略版本、Python 回测、可配置 A 股公开行情及 zap 文件轮转日志,补充迁移、契约与验证。
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"git.sundynix.cn/Blizzard/Veyra/internal/apperror"
|
||||
"golang.org/x/crypto/bcrypt"
|
||||
)
|
||||
|
||||
type AdminCredentialRepository interface {
|
||||
ChangeAdminCredential(context.Context, string, string, string, time.Time) (string, error)
|
||||
}
|
||||
type AdminCredentialService struct {
|
||||
repo AdminCredentialRepository
|
||||
development bool
|
||||
}
|
||||
|
||||
func NewAdminCredentialService(repo AdminCredentialRepository, development bool) *AdminCredentialService {
|
||||
return &AdminCredentialService{repo: repo, development: development}
|
||||
}
|
||||
|
||||
// Set changes only an existing active administrator and revokes its old sessions.
|
||||
func (s *AdminCredentialService) Set(ctx context.Context, previousLogin, login, password string) (string, error) {
|
||||
if !s.development {
|
||||
return "", apperror.ErrForbidden
|
||||
}
|
||||
if s.repo == nil {
|
||||
return "", apperror.ErrUnavailable
|
||||
}
|
||||
previousLogin = strings.ToLower(strings.TrimSpace(previousLogin))
|
||||
login = strings.ToLower(strings.TrimSpace(login))
|
||||
if !loginPattern.MatchString(previousLogin) || !loginPattern.MatchString(login) || len(password) < 8 || len(password) > 72 {
|
||||
return "", apperror.ErrInvalidInput
|
||||
}
|
||||
hash, err := bcrypt.GenerateFromPassword([]byte(password), bcrypt.DefaultCost)
|
||||
if err != nil {
|
||||
return "", apperror.ErrUnavailable
|
||||
}
|
||||
return s.repo.ChangeAdminCredential(ctx, previousLogin, login, string(hash), time.Now().UTC())
|
||||
}
|
||||
Reference in New Issue
Block a user