login_api_controller.go 875B

123456789101112131415161718192021222324252627282930313233343536373839
  1. package admin_api_controllers
  2. import (
  3. "XT_Admin_Api/enums"
  4. "XT_Admin_Api/service"
  5. "fmt"
  6. )
  7. type LoginAPIController struct {
  8. AdminBaseAPIController
  9. }
  10. // /admin/api/login/pwd [post] LoginByPwd
  11. // @param account:string
  12. // @param password:string
  13. func (this *LoginAPIController) LoginByPwd() {
  14. account := this.GetString("account")
  15. password := this.GetString("password")
  16. admin, getAdminErr := service.GetAdminAccount(account, password)
  17. if getAdminErr != nil {
  18. this.ErrorLog("获取管理员信息失败:%v", getAdminErr)
  19. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  20. return
  21. } else if admin == nil {
  22. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAccountOrPasswordWrong)
  23. return
  24. }
  25. fmt.Println(admin)
  26. this.SetSession("admin_info", &AdminInfo{
  27. Admin: admin,
  28. })
  29. this.ServeSuccessJSON(map[string]interface{}{
  30. "admin": admin,
  31. })
  32. }