init commit
This commit is contained in:
1 parent
eda2b643b9
commit
3efed3defe
5834 files changed
+636508
No files matched your search
@@ -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