68 lines
1.7 KiB
Go
68 lines
1.7 KiB
Go
package test
|
|
|
|
import (
|
|
"backend/sdk/login/model/base"
|
|
"backend/util"
|
|
"time"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
type TestModel struct {
|
|
}
|
|
|
|
func Login(c *gin.Context) {
|
|
var p base.Param
|
|
startedAt := time.Now()
|
|
// read parameters from query string for GET requests
|
|
p.Uid = c.Query("uid")
|
|
p.Token = c.Query("token")
|
|
p.AppId = util.Int(c.Query("appId"))
|
|
p.AreaCode = util.Int(c.Query("areaCode"))
|
|
p.Version = c.Query("version")
|
|
if p.Uid == "" || p.Token == "" {
|
|
util.LogStructured("warn", "login request missing required params", map[string]any{
|
|
"appId": p.AppId,
|
|
"areaCode": p.AreaCode,
|
|
"channel": "test",
|
|
"uid": p.Uid,
|
|
"version": p.Version,
|
|
})
|
|
c.JSON(400, gin.H{"error": "missing uid or token"})
|
|
return
|
|
}
|
|
util.LogStructured("info", "login verify started", map[string]any{
|
|
"appId": p.AppId,
|
|
"areaCode": p.AreaCode,
|
|
"channel": "test",
|
|
"uid": p.Uid,
|
|
"version": p.Version,
|
|
})
|
|
if err := (&TestModel{}).VerifyToken(p.Uid, p.Token); err != nil {
|
|
util.LogStructured("warn", "login verify failed", map[string]any{
|
|
"appId": p.AppId,
|
|
"areaCode": p.AreaCode,
|
|
"channel": "test",
|
|
"error": err.Error(),
|
|
"latencyMs": time.Since(startedAt).Milliseconds(),
|
|
"uid": p.Uid,
|
|
"version": p.Version,
|
|
})
|
|
c.JSON(401, gin.H{"error": "invalid token"})
|
|
return
|
|
}
|
|
util.LogStructured("info", "login verify succeeded", map[string]any{
|
|
"appId": p.AppId,
|
|
"areaCode": p.AreaCode,
|
|
"channel": "test",
|
|
"latencyMs": time.Since(startedAt).Milliseconds(),
|
|
"uid": p.Uid,
|
|
"version": p.Version,
|
|
})
|
|
util.LoginResponse(c, p.AppId, p.AreaCode, p.Version)
|
|
}
|
|
|
|
func (t *TestModel) VerifyToken(Uid string, Token string) error {
|
|
return nil
|
|
}
|