广告平台(站长使用)
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.

hdl_login.go 2.0 KiB

2 months ago
1 month ago
2 months ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
2 months ago
2 months ago
2 months ago
4 days ago
2 months ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. package hdl
  2. import (
  3. implement2 "applet/app/db/implement"
  4. "applet/app/e"
  5. "applet/app/lib/validate"
  6. "applet/app/md"
  7. "applet/app/svc"
  8. "applet/app/utils"
  9. db "code.fnuoos.com/zhimeng/model.git/src"
  10. "code.fnuoos.com/zhimeng/model.git/src/implement"
  11. "fmt"
  12. "github.com/gin-gonic/gin"
  13. )
  14. func LoginBase(c *gin.Context) {
  15. masterId := svc.GetMasterId(c)
  16. engine := db.DBs[masterId]
  17. sysCfgDb := implement2.NewSysCfgDb(engine, masterId)
  18. res := sysCfgDb.SysCfgFindWithDb("seo_platform_logo", "seo_platform_title")
  19. re := map[string]string{
  20. "seo_logo": res["seo_platform_logo"],
  21. "seo_title": res["seo_platform_title"],
  22. }
  23. e.OutSuc(c, re, nil)
  24. return
  25. }
  26. // Login 登陆
  27. // @Summary 登陆
  28. // @Tags 登录
  29. // @Description 登入
  30. // @Accept json
  31. // @Produce json
  32. // @Param req body md.LoginReq true "用户名密码"
  33. // @Success 200 {object} md.LoginResponse "token"
  34. // @Failure 400 {object} md.Response "具体错误"
  35. // @Router /api/login [post]
  36. func Login(c *gin.Context) {
  37. var req md.LoginReq
  38. err := c.ShouldBindJSON(&req)
  39. if err != nil {
  40. err = validate.HandleValidateErr(err)
  41. err1 := err.(e.E)
  42. e.OutErr(c, err1.Code, err1.Error())
  43. return
  44. }
  45. engine := db.DBs[svc.GetMasterId(c)]
  46. adminDb := implement.NewAdminDb(engine)
  47. admin, err := adminDb.GetAdminByUserName(req.UserName)
  48. if err != nil {
  49. e.OutErr(c, e.ERR_DB_ORM, err)
  50. return
  51. }
  52. if admin == nil {
  53. e.OutErr(c, e.ERR_NO_DATA, "账号不存在!")
  54. return
  55. }
  56. if utils.Md5(req.PassWord) != admin.Password {
  57. e.OutErr(c, 400, e.NewErr(400, "密码错误"))
  58. return
  59. }
  60. if admin.State == 2 {
  61. e.OutErr(c, 400, e.NewErr(400, "账号被禁用"))
  62. return
  63. }
  64. ip := utils.GetIP(c.Request)
  65. key := fmt.Sprintf(md.JwtTokenKey, ip, utils.AnyToString(admin.AdmId))
  66. token, err := svc.HandleLoginToken(key, admin)
  67. if err != nil {
  68. e.OutErr(c, e.ERR, err.Error())
  69. return
  70. }
  71. e.OutSuc(c, md.LoginResponse{
  72. Token: token,
  73. }, nil)
  74. return
  75. }