DatabasePartnerController.class.php 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  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 DatabasePartnerController
  19. {
  20. // return json object
  21. // 返回json类型
  22. private $returnJson = array('type' => 'partner');
  23. /**
  24. * checkout login status
  25. * 检查登录状态
  26. */
  27. public function __construct()
  28. {
  29. // identity authentication
  30. // 身份验证
  31. $server = new GuestModule;
  32. if (!$server->checkLogin()) {
  33. $this->returnJson['statusCode'] = '120005';
  34. exitOutput($this->returnJson);
  35. }
  36. }
  37. /**
  38. * get partner's personal information by userName
  39. * 获取人员信息
  40. */
  41. public function getPartnerInfo()
  42. {
  43. $userName = securelyInput('userName');
  44. $dbID = securelyInput('dbID');
  45. if (!preg_match('/^([a-zA-Z][0-9a-zA-Z_]{3,59})$/', $userName)) {
  46. // illegal userName length
  47. //userName格式非法
  48. $this->returnJson['statusCode'] = '250001';
  49. } else {
  50. $userServer = new UserModule;
  51. $userInfo = $userServer->checkUserExist($userName);
  52. if ($userInfo) {
  53. $partnerServer = new DatabasePartnerModule;
  54. if ($partnerServer->checkIsInvited($dbID, $userName)) {
  55. $this->returnJson['statusCode'] = '250007';
  56. $this->returnJson['userInfo']['userName'] = $userName;
  57. $this->returnJson['userInfo']['userNickName'] = $userInfo['userNickName'];
  58. $this->returnJson['userInfo']['isInvited'] = 1;
  59. } else {
  60. $this->returnJson['statusCode'] = '000000';
  61. $this->returnJson['userInfo']['userName'] = $userName;
  62. $this->returnJson['userInfo']['userNickName'] = $userInfo['userNickName'];
  63. $this->returnJson['userInfo']['isInvited'] = 0;
  64. }
  65. } else {
  66. //the user doesn't exist
  67. //用户不存在
  68. $this->returnJson['statusCode'] = '250002';
  69. }
  70. }
  71. exitOutput($this->returnJson);
  72. }
  73. /**
  74. * invite a user to join the database
  75. * 邀请协作人员
  76. */
  77. public function invitePartner()
  78. {
  79. $userName = securelyInput('userName');
  80. $dbID = securelyInput('dbID');
  81. $module = new DatabaseModule();
  82. $userType = $module->getUserType($dbID);
  83. if ($userType < 0 || $userType > 1) {
  84. $this->returnJson['statusCode'] = '120007';
  85. exitOutput($this->returnJson);
  86. }
  87. if (!preg_match('/^([a-zA-Z][0-9a-zA-Z_]{3,59})$/', $userName)) {
  88. // illegal userName
  89. //userName格式非法
  90. $this->returnJson['statusCode'] = '250001';
  91. } else {
  92. $userServer = new UserModule;
  93. $userInfo = $userServer->checkUserExist($userName);
  94. if ($userInfo) {
  95. $partnerServer = new DatabasePartnerModule;
  96. //check if the user have been invited
  97. //检查是否已经被邀请过
  98. if ($partnerServer->checkIsInvited($dbID, $userName)) {
  99. // Has been invited
  100. //已被邀请
  101. $this->returnJson['statusCode'] = '250007';
  102. } else {
  103. if ($connID = $partnerServer->invitePartner($dbID, $userInfo['userID'])) {
  104. $this->returnJson['statusCode'] = '000000';
  105. $this->returnJson['connID'] = $connID;
  106. } else {
  107. //invite fail, the user has been invited
  108. //添加协作成员失败,成员已经添加
  109. $this->returnJson['statusCode'] = '250003';
  110. }
  111. }
  112. } else {
  113. // userName doesn't exist
  114. //用户不存在
  115. $this->returnJson['statusCode'] = '250002';
  116. }
  117. }
  118. exitOutput($this->returnJson);
  119. }
  120. /**
  121. * remove user from database
  122. * 移除协作人员
  123. */
  124. public function removePartner()
  125. {
  126. $dbID = securelyInput('dbID');
  127. $module = new DatabaseModule();
  128. $userType = $module->getUserType($dbID);
  129. if ($userType < 0 || $userType > 1) {
  130. $this->returnJson['statusCode'] = '120007';
  131. exitOutput($this->returnJson);
  132. }
  133. $connID = securelyInput('connID');
  134. $server = new DatabasePartnerModule;
  135. if ($server->removePartner($dbID, $connID)) {
  136. $this->returnJson['statusCode'] = '000000';
  137. } else {
  138. // remove user fail, the user has been removed
  139. //移除成员失败,成员已经被移出
  140. $this->returnJson['statusCode'] = '250004';
  141. }
  142. exitOutput($this->returnJson);
  143. }
  144. /**
  145. * get database partner list
  146. * 获取协作人员列表
  147. */
  148. public function getPartnerList()
  149. {
  150. $dbID = securelyInput('dbID');
  151. $server = new DatabasePartnerModule;
  152. $result = $server->getPartnerList($dbID);
  153. if ($result) {
  154. $this->returnJson['statusCode'] = '000000';
  155. $this->returnJson['partnerList'] = $result;
  156. } else {
  157. //the partner list is empty
  158. //协作人员列表为空
  159. $this->returnJson['statusCode'] = '250005';
  160. }
  161. exitOutput($this->returnJson);
  162. }
  163. /**
  164. * quit the database
  165. * 退出协作数据字典
  166. */
  167. public function quitPartner()
  168. {
  169. $dbID = securelyInput('dbID');
  170. $server = new DatabasePartnerModule;
  171. $result = $server->quitPartner($dbID);
  172. if ($result) {
  173. $this->returnJson['statusCode'] = '000000';
  174. } else {
  175. //quit fail, the user has quited
  176. //退出协作项目失败,已退出协作项目
  177. $this->returnJson['statusCode'] = '250006';
  178. }
  179. exitOutput($this->returnJson);
  180. }
  181. /**
  182. * edit partner's nickName
  183. * 修改协作成员的昵称
  184. */
  185. public function editPartnerNickName()
  186. {
  187. $dbID = securelyInput('dbID');
  188. $conn_id = securelyInput('connID');
  189. $nick_name = securelyInput('nickName');
  190. $name_length = mb_strlen(quickInput('nickName'), 'utf8');
  191. //verify connID
  192. //判断关联ID是否合法
  193. if (!preg_match('/^[0-9]{1,11}$/', $conn_id)) {
  194. //illegal connID
  195. //关联ID格式非法
  196. $this->returnJson['statusCode'] = '250003';
  197. } elseif ($name_length < 1 || $name_length > 32) {
  198. //illegal nickName
  199. //昵称格式非法
  200. $this->returnJson['statusCode'] = '250004';
  201. } else {
  202. $module = new DatabasePartnerModule();
  203. $result = $module->editPartnerNickName($dbID, $conn_id, $nick_name);
  204. if ($result) {
  205. //edit success
  206. //成功
  207. $this->returnJson['statusCode'] = '000000';
  208. } else {
  209. //edit fail
  210. //失败
  211. $this->returnJson['statusCode'] = '250000';
  212. }
  213. }
  214. exitOutput($this->returnJson);
  215. }
  216. /**
  217. * 修改协作成员的类型
  218. */
  219. public function editPartnerType()
  220. {
  221. $dbID = securelyInput('dbID');
  222. $module = new DatabaseModule();
  223. $userType = $module->getUserType($dbID);
  224. if ($userType < 0 || $userType > 1) {
  225. $this->returnJson['statusCode'] = '120007';
  226. exitOutput($this->returnJson);
  227. }
  228. $conn_id = securelyInput('connID');
  229. $user_type = securelyInput('userType');
  230. if (!preg_match('/^[0-9]{1,11}$/', $conn_id)) {
  231. //illegal connID
  232. //关联ID格式非法
  233. $this->returnJson['statusCode'] = '250003';
  234. } elseif (!preg_match('/^[1-3]{1}$/', $user_type)) {
  235. //illegal userType
  236. //用户类型格式非法
  237. $this->returnJson['statusCode'] = '250005';
  238. } else {
  239. $module = new DatabasePartnerModule();
  240. $result = $module->editPartnerType($dbID, $conn_id, $user_type);
  241. if ($result) {
  242. //edit success
  243. //成功
  244. $this->returnJson['statusCode'] = '000000';
  245. } else {
  246. //edit fail
  247. //失败
  248. $this->returnJson['statusCode'] = '250000';
  249. }
  250. }
  251. exitOutput($this->returnJson);
  252. }
  253. }
  254. ?>