115 lines
3.1 KiB
Go
115 lines
3.1 KiB
Go
package web_acc
|
|
|
|
import (
|
|
"videoweb/pub/common"
|
|
"videoweb/pub/common/srvdef"
|
|
"videoweb/pub/models/mwacc"
|
|
"videoweb/web/service/srv_mwacc"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
// @Tags 登录
|
|
// @Summary 登录-登录
|
|
// @Description 登录-登录
|
|
// @Accept json
|
|
// @Produce json
|
|
// @Param param body MainWebLoginReq true "参数列表"
|
|
// @Success 200 {object} MainWebLoginResp "成功"
|
|
// @Failure 400 {string} string "获取失败的返回结果"
|
|
// @Router /api/web/login/acc [POST]
|
|
func AccLogin(c *gin.Context) {
|
|
var req MainWebLoginReq
|
|
|
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|
common.ServerJSON(c, srvdef.ErrParamError, err.Error())
|
|
return
|
|
}
|
|
|
|
accInfo, err := srv_mwacc.AccLogin(c, req.Acc, req.Pwd, req.Code)
|
|
if err != nil || accInfo == nil {
|
|
common.ServerJSON(c, err.Code, err.Msg)
|
|
return
|
|
}
|
|
|
|
resp := MainWebLoginResp{}
|
|
|
|
if len(accInfo.Qurl) != 0 {
|
|
resp.Qurl = accInfo.Qurl
|
|
} else {
|
|
// 成功保存token
|
|
if ok, _ := mwacc.SaveToken(c, accInfo.Id, accInfo.Token); ok != true {
|
|
common.ServerJSON(c, srvdef.GenerateTokenFailed, srvdef.GenerateTokenFailed.Msg())
|
|
}
|
|
|
|
resp.AccId = accInfo.Id
|
|
resp.Acc = accInfo.Acc
|
|
resp.RoleId = accInfo.RoleId
|
|
resp.Token = accInfo.Token
|
|
}
|
|
common.ServerJSON(c, srvdef.Success, resp)
|
|
return
|
|
}
|
|
|
|
// SLogin doc
|
|
// @Summary 管理员sso登陆
|
|
// @Description 管理员sso登陆
|
|
// @Tags web-单点登陆
|
|
// @Accept mpfd,json
|
|
// @Produce json,html
|
|
// @Param name formData string true "账号"
|
|
// @Param password formData string true "密码"
|
|
// @Success 200 {string} json "{"msg": "管理员信息""}"
|
|
// @Failure 400 {string} json "{"msg": "操作失败"}"
|
|
// @Router /api/web/login/slogin [post]
|
|
func SLogin(c *gin.Context) {
|
|
var req MainWebLoginReq
|
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|
common.ServerJSON(c, srvdef.ErrParamError, err.Error())
|
|
return
|
|
}
|
|
accInfo, err := srv_mwacc.AccSLogin(c, req.Acc, req.Pwd)
|
|
if err != nil || accInfo == nil {
|
|
common.ServerJSON(c, err.Code, err.Msg)
|
|
return
|
|
}
|
|
resp := MainWebLoginResp{}
|
|
// 成功保存token
|
|
if ok, _ := mwacc.SaveToken(c, accInfo.Id, accInfo.Token); ok != true {
|
|
common.ServerJSON(c, srvdef.GenerateTokenFailed, srvdef.GenerateTokenFailed.Msg())
|
|
}
|
|
resp.AccId = accInfo.Id
|
|
resp.Acc = accInfo.Acc
|
|
resp.RoleId = accInfo.RoleId
|
|
resp.Token = accInfo.Token
|
|
|
|
common.ServerJSON(c, srvdef.Success, resp)
|
|
return
|
|
}
|
|
|
|
// @Tags 登录
|
|
// @Summary 登录-绑定二维码
|
|
// @Description 登录-绑定二维码
|
|
// @Accept json
|
|
// @Produce json
|
|
// @Param param body BindQurlReq true "参数列表"
|
|
// @Success 200 {object} BindQurlResp "成功"
|
|
// @Failure 400 {string} string "获取失败的返回结果"
|
|
// @Router /api/web/login/bind [POST]
|
|
func BindQurl(c *gin.Context) {
|
|
var req BindQurlReq
|
|
|
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|
common.ServerJSON(c, srvdef.ErrParamError, "tone AccLogin arg error "+err.Error())
|
|
return
|
|
}
|
|
|
|
ok, _ := mwacc.BindAccQurl(c, req.Acc)
|
|
if !ok {
|
|
common.ServerJSON(c, srvdef.Failure, BindQurlResp{Result: false})
|
|
return
|
|
}
|
|
common.ServerJSON(c, srvdef.Success, BindQurlResp{Result: true})
|
|
return
|
|
}
|