BackupController.class.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <?php
  2. /**
  3. * @name eolinker ams open source,eolinker开源版本
  4. * @link https://www.eolinker.com/
  5. * @package eolinker
  6. * @author www.eolinker.com 广州银云信息科技有限公司 ©2015-2018
  7. * eoLinker是目前全球领先、国内最大的在线API接口管理平台,提供自动生成API文档、API自动化测试、Mock测试、团队协作等功能,旨在解决由于前后端分离导致的开发效率低下问题。
  8. * 如在使用的过程中有任何问题,欢迎加入用户讨论群进行反馈,我们将会以最快的速度,最好的服务态度为您解决问题。
  9. *
  10. * eoLinker AMS开源版的开源协议遵循Apache License 2.0,如需获取最新的eolinker开源版以及相关资讯,请访问:https://www.eolinker.com/#/os/download
  11. *
  12. * 官方网站:https://www.eolinker.com/
  13. * 官方博客以及社区:http://blog.eolinker.com/
  14. * 使用教程以及帮助:http://help.eolinker.com/
  15. * 商务合作邮箱:market@eolinker.com
  16. * 用户讨论QQ群:284421832
  17. */
  18. class BackupController
  19. {
  20. // 返回json类型
  21. private $returnJson = array('type' => 'backup');
  22. /**
  23. * 检查登录状态
  24. */
  25. public function __construct()
  26. {
  27. // 身份验证
  28. $server = new GuestModule;
  29. if (!$server->checkLogin()) {
  30. $this->returnJson['statusCode'] = '120005';
  31. exitOutput($this->returnJson);
  32. }
  33. }
  34. /**
  35. * 备份项目
  36. */
  37. public function backupProject()
  38. {
  39. $user_call = securelyInput('userCall');
  40. $user_password = securelyInput('userPassword');
  41. $project_id = securelyInput('projectID');
  42. $verify_code = securelyInput('verifyCode');
  43. if (empty($user_call)) {
  44. $this->returnJson['statusCode'] = '310001';
  45. } elseif (!preg_match('/^[0-9a-zA-Z]{32}$/', $user_password)) {
  46. $this->returnJson['statusCode'] = '310002';
  47. } elseif (!preg_match('/^[0-9]{1,11}$/', $project_id)) {
  48. $this->returnJson['statusCode'] = '310003';
  49. } elseif (!preg_match('/^[0-9a-zA-Z]{32}$/', $verify_code)) {
  50. $this->returnJson['statusCode'] = '310004';
  51. } else {
  52. $project_module = new ProjectModule();
  53. $user_type = $project_module->getUserType($project_id);
  54. if ($user_type < 0 || $user_type > 1) {
  55. $this->returnJson['statusCode'] = '120007';
  56. } else {
  57. $module = new BackupModule();
  58. $result = $module->backupProject($user_call, $user_password, $project_id, $verify_code);
  59. if ($result === TRUE) {
  60. $this->returnJson['statusCode'] = '000000';
  61. } else {
  62. switch ($result) {
  63. case -1:
  64. $this->returnJson['msg'] = '用户没有写权限';
  65. $this->returnJson['statusCode'] = '310005';
  66. break;
  67. case -2:
  68. $this->returnJson['msg'] = '发送登录请求失败';
  69. $this->returnJson['statusCode'] = '310006';
  70. break;
  71. case -3:
  72. $this->returnJson['msg'] = '登录账号非法';
  73. $this->returnJson['statusCode'] = '310007';
  74. break;
  75. case -4:
  76. $this->returnJson['msg'] = '账号不存在或密码错误';
  77. $this->returnJson['statusCode'] = '310008';
  78. break;
  79. case -5:
  80. $this->returnJson['msg'] = '未知登录错误';
  81. $this->returnJson['statusCode'] = '310009';
  82. break;
  83. case -6:
  84. $this->returnJson['msg'] = '备份项目失败';
  85. $this->returnJson['statusCode'] = '310010';
  86. break;
  87. default:
  88. $this->returnJson['statusCode'] = '310000';
  89. $this->returnJson['statusCode'] = '备份项目失败';
  90. }
  91. }
  92. }
  93. }
  94. exitOutput($this->returnJson);
  95. }
  96. }