login_api_controller.go 847B

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