mirror of
https://github.com/tiger1103/gfast.git
synced 2026-10-16 01:41:13 +00:00
42 lines
1.0 KiB
Go
42 lines
1.0 KiB
Go
package controller
|
|
|
|
import (
|
|
"context"
|
|
"github.com/gogf/gf/v2/errors/gerror"
|
|
"github.com/gogf/gf/v2/os/genv"
|
|
"github.com/tiger1103/gfast/v3/apiv1/system"
|
|
commonService "github.com/tiger1103/gfast/v3/internal/app/common/service"
|
|
"github.com/tiger1103/gfast/v3/internal/app/system/model"
|
|
"github.com/tiger1103/gfast/v3/internal/app/system/service"
|
|
)
|
|
|
|
var (
|
|
User = UserController{}
|
|
)
|
|
|
|
type UserController struct {
|
|
baseController
|
|
}
|
|
|
|
func (c *UserController) Login(ctx context.Context, req *system.UserLoginReq) (res *system.UserLoginRes, err error) {
|
|
var user *model.LoginUserRes
|
|
//判断验证码是否正确
|
|
debug := genv.GetWithCmd("gf.debug")
|
|
if debug.Int() != 1 {
|
|
if !commonService.Captcha().VerifyString(req.VerifyKey, req.VerifyCode) {
|
|
err = gerror.New("验证码输入错误")
|
|
return
|
|
}
|
|
}
|
|
//ip := libUtils.GetClientIp(ctx)
|
|
//userAgent := libUtils.GetUserAgent(ctx)
|
|
user, err = service.User().GetAdminUserByUsernamePassword(ctx, req)
|
|
if err != nil {
|
|
return
|
|
}
|
|
res = &system.UserLoginRes{
|
|
UserInfo: user,
|
|
}
|
|
return
|
|
}
|