|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
- package hdl
-
- import (
- implement2 "applet/app/db/implement"
- "applet/app/e"
- "applet/app/lib/validate"
- "applet/app/md"
- "applet/app/svc"
- "applet/app/utils"
- db "code.fnuoos.com/zhimeng/model.git/src"
- "code.fnuoos.com/zhimeng/model.git/src/implement"
- "fmt"
- "github.com/gin-gonic/gin"
- )
-
- func LoginBase(c *gin.Context) {
- masterId := svc.GetMasterId(c)
- engine := db.DBs[masterId]
- sysCfgDb := implement2.NewSysCfgDb(engine, masterId)
- res := sysCfgDb.SysCfgFindWithDb("seo_platform_logo", "seo_platform_title")
- re := map[string]string{
- "seo_logo": res["seo_platform_logo"],
- "seo_title": res["seo_platform_title"],
- }
- e.OutSuc(c, re, nil)
- return
- }
-
- // Login 登陆
- // @Summary 登陆
- // @Tags 登录
- // @Description 登入
- // @Accept json
- // @Produce json
- // @Param req body md.LoginReq true "用户名密码"
- // @Success 200 {object} md.LoginResponse "token"
- // @Failure 400 {object} md.Response "具体错误"
- // @Router /api/login [post]
- func Login(c *gin.Context) {
- var req md.LoginReq
- err := c.ShouldBindJSON(&req)
- if err != nil {
- err = validate.HandleValidateErr(err)
- err1 := err.(e.E)
- e.OutErr(c, err1.Code, err1.Error())
- return
- }
- engine := db.DBs[svc.GetMasterId(c)]
- adminDb := implement.NewAdminDb(engine)
- admin, err := adminDb.GetAdminByUserName(req.UserName)
- if err != nil {
- e.OutErr(c, e.ERR_DB_ORM, err)
- return
- }
- if admin == nil {
- e.OutErr(c, e.ERR_NO_DATA, "账号不存在!")
- return
- }
- if utils.Md5(req.PassWord) != admin.Password {
- e.OutErr(c, 400, e.NewErr(400, "密码错误"))
- return
- }
- if admin.State == 2 {
- e.OutErr(c, 400, e.NewErr(400, "账号被禁用"))
- return
- }
- ip := utils.GetIP(c.Request)
- key := fmt.Sprintf(md.JwtTokenKey, ip, utils.AnyToString(admin.AdmId))
- token, err := svc.HandleLoginToken(key, admin)
- if err != nil {
- e.OutErr(c, e.ERR, err.Error())
- return
- }
- e.OutSuc(c, md.LoginResponse{
- Token: token,
- }, nil)
- return
- }
|