go-platform/services/platform_auth.go
2026-03-31 17:49:09 +08:00

38 lines
946 B
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 services
import (
"errors"
"server/pkg/jwtutil"
)
// PlatformLogin 平台登录业务
// TODO: 后续接真实用户/租户表,这里先做最小可用实现。
func PlatformLogin(username, password string) (string, error) {
// 临时简单校验:用户名和密码非空
if username == "" || password == "" {
return "", errors.New("用户名或密码不能为空")
}
// 测试账号admin / admin123
if username != "admin" || password != "admin123" {
return "", errors.New("用户名或密码错误")
}
// 这里后续应:
// 1. 从平台用户表查询用户
// 2. 校验密码(含加盐加密)
// 3. 绑定平台/租户信息
// 目前先返回一个平台用户的 JWT 占位 token
const fakeUserID = 1
const fakeTenantID = 0
const userType = "platform"
token, err := jwtutil.GenerateToken(fakeUserID, username, fakeTenantID, userType)
if err != nil {
return "", err
}
return token, nil
}