mirror of
https://github.com/FlourishingWorld/hk4e.git
synced 2026-02-11 00:22:26 +08:00
init commit
This commit is contained in:
44
water/controller/memory_token_controller.go
Normal file
44
water/controller/memory_token_controller.go
Normal file
@@ -0,0 +1,44 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"flswld.com/logger"
|
||||
"github.com/gin-gonic/gin"
|
||||
"water/entity"
|
||||
)
|
||||
|
||||
// 获取token
|
||||
func (c *Controller) getMemoryToken(context *gin.Context) {
|
||||
login := new(entity.Login)
|
||||
err := context.ShouldBindJSON(login)
|
||||
if err != nil {
|
||||
logger.LOG.Error("[controller:getMemoryToken] context.ShouldBindJSON() fail: %v", err)
|
||||
return
|
||||
}
|
||||
auth, token := c.service.GetMemoryToken(login)
|
||||
if auth {
|
||||
context.JSON(200, gin.H{
|
||||
"code": 0,
|
||||
"token": token,
|
||||
})
|
||||
} else {
|
||||
context.JSON(200, gin.H{
|
||||
"code": 401,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// 验证token
|
||||
func (c *Controller) checkMemoryToken(context *gin.Context) {
|
||||
token := new(entity.MemoryToken)
|
||||
err := context.ShouldBindJSON(token)
|
||||
if err != nil {
|
||||
logger.LOG.Error("[controller:checkMemoryToken] context.ShouldBindJSON() fail: %v", err)
|
||||
return
|
||||
}
|
||||
valid, uid := c.service.CheckMemoryToken(token.Token)
|
||||
context.JSON(200, gin.H{
|
||||
"code": 0,
|
||||
"valid": valid,
|
||||
"uid": uid,
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user