mobile_api_base_controller.go 1.7KB

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