admin_api_base_controller.go 1.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. package admin_api_controllers
  2. import (
  3. "XT_New/controllers"
  4. "XT_New/enums"
  5. "XT_New/models/admin_models"
  6. )
  7. type AdminBaseAPIController struct {
  8. controllers.BaseAPIController
  9. }
  10. func (this *AdminBaseAPIController) ErrorLog(format string, a ...interface{}) {
  11. //beego.Error(fmt.Sprintf("[管理员后台] %v", fmt.Sprintf(format, a...)))
  12. }
  13. func (this *AdminBaseAPIController) WarnLog(format string, a ...interface{}) {
  14. //beego.Warn(fmt.Sprintf("[管理员后台] %v", fmt.Sprintf(format, a...)))
  15. }
  16. func (this *AdminBaseAPIController) InfoLog(format string, a ...interface{}) {
  17. //beego.Info(fmt.Sprintf("[管理员后台] %v", fmt.Sprintf(format, a...)))
  18. }
  19. func (this *AdminBaseAPIController) DebugLog(format string, a ...interface{}) {
  20. //beego.Debug(fmt.Sprintf("[管理员后台] %v", fmt.Sprintf(format, a...)))
  21. }
  22. func (this *AdminBaseAPIController) TraceLog(format string, a ...interface{}) {
  23. //beego.Trace(fmt.Sprintf("[管理员后台] %v", fmt.Sprintf(format, a...)))
  24. }
  25. func (this *AdminBaseAPIController) GetAdminInfo() *AdminInfo {
  26. userInfo := this.GetSession("admin_info")
  27. if userInfo == nil {
  28. return nil
  29. } else {
  30. return userInfo.(*AdminInfo)
  31. }
  32. }
  33. type AdminInfo struct {
  34. Admin *admin_models.AdminAccount
  35. }
  36. type AdminBaseAPIAuthController struct {
  37. AdminBaseAPIController
  38. }
  39. func (this *AdminBaseAPIAuthController) Prepare() {
  40. this.AdminBaseAPIController.Prepare()
  41. adminInfo := this.GetAdminInfo()
  42. if adminInfo == nil {
  43. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNotLogin)
  44. this.StopRun()
  45. }
  46. }