GuestController.class.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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 GuestController
  19. {
  20. //返回json类型
  21. private $returnJson = array('type' => 'guest');
  22. /**
  23. * 登录
  24. */
  25. public function login()
  26. {
  27. $loginName = securelyInput('loginName');
  28. $loginPassword = securelyInput('loginPassword');
  29. $server = new GuestModule;
  30. if (preg_match('/^[0-9a-zA-Z]{32}$/', $loginPassword)) {
  31. if (preg_match('/^[0-9a-zA-Z][0-9a-zA-Z_]{3,63}$/', $loginName)) {
  32. $result = $server->login($loginName, $loginPassword);
  33. if ($result) {
  34. $this->returnJson['statusCode'] = '000000';
  35. $this->returnJson['userID'] = $_SESSION['userID'];
  36. } else
  37. $this->returnJson['statusCode'] = '120004';
  38. } else {
  39. $this->returnJson['statusCode'] = '120001';
  40. exitOutput(json_encode($this->returnJson));
  41. }
  42. } else {
  43. //密码非法
  44. $this->returnJson['statusCode'] = '120002';
  45. }
  46. exitOutput($this->returnJson);
  47. }
  48. /**
  49. * 用户名注册
  50. */
  51. public function register()
  52. {
  53. if (!ALLOW_REGISTER) {
  54. //不允许新用户注册
  55. $this->returnJson['statusCode'] = '130005';
  56. } else {
  57. $userName = securelyInput('userName');
  58. $loginPassword = securelyInput('userPassword');
  59. $nickNameLen = mb_strlen(quickInput('userNickName'), 'utf8');
  60. $userNickName = securelyInput('userNickName');
  61. //验证用户名,4~16位非纯数字,英文数字下划线组合,只能以英文开头
  62. if (!preg_match('/^[0-9a-zA-Z][0-9a-zA-Z_]{3,63}$/', $userName)) {
  63. //用户名非法
  64. $this->returnJson['statusCode'] = '130001';
  65. } elseif (!preg_match('/^[0-9a-zA-Z]{32}$/', $loginPassword)) {
  66. //密码非法
  67. $this->returnJson['statusCode'] = '130002';
  68. } elseif (!($nickNameLen == 0 || $nickNameLen <= 16)) {
  69. //用户名非法
  70. $this->returnJson['statusCode'] = '130014';
  71. } else {
  72. $server = new GuestModule;
  73. $result = $server->register($userName, $loginPassword, $userNickName);
  74. if ($result)
  75. //注册成功
  76. $this->returnJson['statusCode'] = '000000';
  77. else
  78. //注册失败
  79. $this->returnJson['statusCode'] = '130005';
  80. }
  81. }
  82. exitOutput($this->returnJson);
  83. }
  84. /**
  85. * 用户查重
  86. */
  87. public function checkUserNameExist()
  88. {
  89. $userName = securelyInput('userName');
  90. $server = new GuestModule;
  91. if (preg_match('/^[0-9a-zA-Z][0-9a-zA-Z_]{3,63}$/', $userName)) {
  92. $result = $server->checkUserNameExist($userName);
  93. if ($result)
  94. //用户名可注册
  95. $this->returnJson['statusCode'] = '000000';
  96. else
  97. //用户名重复
  98. $this->returnJson['statusCode'] = '130005';
  99. } else
  100. //userName格式非法
  101. $this->returnJson['statusCode'] = '130001';
  102. exitOutput($this->returnJson);
  103. }
  104. /**
  105. * 检查登录状态
  106. */
  107. public function checkLogin()
  108. {
  109. $server = new GuestModule;
  110. $result = $server->checkLogin();
  111. if ($result) {
  112. //已登录
  113. $this->returnJson['statusCode'] = '000000';
  114. } else {
  115. //未登录
  116. $this->returnJson['statusCode'] = '120005';
  117. }
  118. exitOutput($this->returnJson);
  119. }
  120. }
  121. ?>