mobile_api_base_controller.go 1.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. package mobile_api_controllers
  2. import (
  3. "XT_New/controllers"
  4. "XT_New/enums"
  5. "XT_New/models"
  6. "XT_New/service"
  7. )
  8. type MobileBaseAPIController struct {
  9. controllers.BaseAPIController
  10. }
  11. func (this *MobileBaseAPIController) Prepare() {
  12. this.BaseAPIController.Prepare()
  13. // beego.Trace("============================================================")
  14. // beego.Trace("session ID: %v", this.Ctx.Input.Cookie("beegosessionID"))
  15. // beego.Trace("session : %v", this.GetSession("info"))
  16. // this.SetSession("info", time.Now().Format("2006/01/02 15:04:05"))
  17. // beego.Trace("============================================================")
  18. }
  19. func (this *MobileBaseAPIController) GetMobileAdminUserInfo() *MobileAdminUserInfo {
  20. userInfo := this.GetSession("mobile_admin_user_info")
  21. if userInfo == nil {
  22. return nil
  23. } else {
  24. return userInfo.(*MobileAdminUserInfo)
  25. }
  26. }
  27. type MobileAdminUserInfo struct {
  28. AdminUser *models.AdminUser
  29. Org *models.Org
  30. App *models.OrgApp
  31. AppRole *models.App_Role
  32. Subscibe *models.ServeSubscibe
  33. TemplateInfo *models.GobalTemplate
  34. }
  35. type MobileBaseAPIAuthController struct {
  36. MobileBaseAPIController
  37. }
  38. func (this *MobileBaseAPIAuthController) Prepare() {
  39. this.MobileBaseAPIController.Prepare()
  40. adminUserInfo := this.GetMobileAdminUserInfo()
  41. if adminUserInfo == nil {
  42. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNotLogin)
  43. this.StopRun()
  44. }
  45. if this.Ctx.Request.Method != "GET" {
  46. err := service.GetOrgSubscibeState(adminUserInfo.Subscibe)
  47. if err != nil || adminUserInfo.Subscibe.State == 3 {
  48. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNotSubscibe)
  49. this.StopRun()
  50. }
  51. }
  52. }