You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
go-fly/controller/login.go

85 lines
2.0 KiB

package controller
import (
"github.com/gin-gonic/gin"
"github.com/taoshihan1991/imaptool/tools"
4 years ago
"log"
"time"
)
// @Summary 登陆验证接口
// @Produce json
// @Accept multipart/form-data
// @Param username formData string true "用户名"
// @Param password formData string true "密码"
// @Param type formData string true "类型"
// @Success 200 {object} controller.Response
// @Failure 200 {object} controller.Response
// @Router /check [post]
//验证接口
func LoginCheckPass(c *gin.Context) {
4 years ago
authType := c.PostForm("type")
password := c.PostForm("password")
username := c.PostForm("username")
switch authType {
case "local":
sessionId := CheckPass(username, password)
userinfo := make(map[string]interface{})
userinfo["name"] = username
userinfo["create_time"] = time.Now().Unix()
4 years ago
token, err := tools.MakeToken(userinfo)
userinfo["ref_token"]=true
refToken, _ := tools.MakeToken(userinfo)
4 years ago
log.Println(err)
if sessionId != "" {
c.JSON(200, gin.H{
"code": 200,
"msg": "验证成功,正在跳转",
"result": gin.H{
"token": token,
"ref_token":refToken,
"create_time":userinfo["create_time"],
4 years ago
},
})
return
}
case "kefu":
info,uRole,ok:=CheckKefuPass(username, password)
userinfo:= make(map[string]interface{})
if !ok{
c.JSON(200, gin.H{
"code": 400,
"msg": "验证失败",
})
return
}
userinfo["name"] = info.Name
userinfo["kefu_id"] = info.ID
userinfo["type"] = "kefu"
if uRole.RoleId!=0 {
userinfo["role_id"] =uRole.RoleId
}else{
userinfo["role_id"]=2
}
userinfo["create_time"] = time.Now().Unix()
token, _ := tools.MakeToken(userinfo)
userinfo["ref_token"]=true
refToken, _ := tools.MakeToken(userinfo)
4 years ago
c.JSON(200, gin.H{
"code": 200,
"msg": "验证成功,正在跳转",
"result": gin.H{
"token": token,
"ref_token":refToken,
"create_time":userinfo["create_time"],
},
4 years ago
})
return
4 years ago
}
c.JSON(200, gin.H{
"code": 400,
"msg": "验证失败",
})
}