- 修改端口配置:将 .vscode/launch.json 中的端口从 27777 改为 27000 - 优化会话管理:更新 session 包中的 GetSession 和 SaveSession 函数,使用新的 sessionprx 变量 - 调整登录逻辑:修改 login 控制器中的 Login 函数,优化会话验证流程 - 扩展服务器信息结构:在 CommendSvrInfo 结构中添加好友和黑名单信息字段 - 修复 GetSessionId 函数:改进错误处理,确保返回值的一致性 - 更新服务器配置:修改 ServerR.xml 中的 EmailLogin URL 为本地地址 - 其他 minor changes:删除了一些不必要的注释和打印语句
87 lines
1.9 KiB
Go
87 lines
1.9 KiB
Go
package admin
|
|
|
|
import (
|
|
"blazing/common/data/session"
|
|
"blazing/cool"
|
|
baseservice "blazing/modules/base/service"
|
|
"blazing/modules/blazing/service"
|
|
|
|
"context"
|
|
"fmt"
|
|
|
|
"github.com/gogf/gf/v2/frame/g"
|
|
"github.com/gogf/gf/v2/util/gconv"
|
|
)
|
|
|
|
type SessionReq struct {
|
|
g.Meta `path:"/getSessionByAuth" method:"GET"`
|
|
Email string `json:"email" v:"required|email"`
|
|
Password string `json:"password" v:"required"`
|
|
}
|
|
type SessionRes struct {
|
|
Msg string `json:"msg"`
|
|
Code int `json:"code"`
|
|
Session string `json:"session"`
|
|
}
|
|
|
|
type BlazingController struct {
|
|
*cool.Controller
|
|
}
|
|
|
|
var biazing_service = service.NewLoginServiceService()
|
|
|
|
func init() {
|
|
var blazing_controller = &BlazingController{
|
|
&cool.Controller{
|
|
Prefix: "/seer/game",
|
|
Api: []string{},
|
|
Service: biazing_service,
|
|
},
|
|
}
|
|
// 注册路由
|
|
cool.RegisterController(blazing_controller)
|
|
}
|
|
func (c *BlazingController) GetSession(ctx context.Context, req *SessionReq) (res *SessionRes, err error) {
|
|
// res = &DemoSampleWelcomeRes{
|
|
// BaseRes: cool.Ok("Welcome to Cool Admin Go"),
|
|
// Data: gjson.New(`{"name": "Cool Admin Go", "age":0}`),
|
|
// }
|
|
res = &SessionRes{
|
|
Msg: "success",
|
|
Code: 200,
|
|
Session: ""}
|
|
if err := g.Validator().Data(req).Run(ctx); err != nil {
|
|
fmt.Println(err)
|
|
res.Code = 400
|
|
res.Msg = err.Error()
|
|
|
|
}
|
|
res1, err := baseservice.NewBaseSysUserService().GetSession(req.Email, req.Password)
|
|
|
|
if err != nil {
|
|
res.Code = 400
|
|
res.Msg = err.Error()
|
|
}
|
|
if res1 == nil {
|
|
res.Code = 400
|
|
res.Msg = err.Error()
|
|
return
|
|
}
|
|
accountID := res1.ID
|
|
retsid, sid, err := biazing_service.GetSessionId(accountID)
|
|
if err != nil {
|
|
res.Code = 400
|
|
res.Msg = err.Error()
|
|
|
|
}
|
|
|
|
res.Session = retsid
|
|
|
|
if err := session.SaveSession(sid, gconv.String(accountID)); err != nil {
|
|
res.Code = 400
|
|
res.Msg = err.Error()
|
|
}
|
|
|
|
return
|
|
}
|