UserController.class.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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 UserController
  19. {
  20. // 返回json类型
  21. private $returnJson = array('type' => 'user');
  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 logout()
  38. {
  39. @session_start();
  40. @session_destroy();
  41. $this->returnJson['statusCode'] = '000000';
  42. exitOutput(json_encode($this->returnJson));
  43. }
  44. /**
  45. * 修改密码
  46. */
  47. public function changePassword()
  48. {
  49. $oldPassword = securelyInput('oldPassword');
  50. $newPassword = securelyInput('newPassword');
  51. if (!preg_match('/^[0-9a-zA-Z]{32}$/', $newPassword) || !preg_match('/^[0-9a-zA-Z]{32}$/', $oldPassword)) {
  52. //密码非法
  53. $this->returnJson['statusCode'] = '130002';
  54. } elseif ($oldPassword == $newPassword) {
  55. //密码相同
  56. $this->returnJson['statusCode'] = '000000';
  57. } else {
  58. $server = new UserModule;
  59. $result = $server->changePassword($oldPassword, $newPassword);
  60. if ($result) {
  61. $this->returnJson['statusCode'] = '000000';
  62. } else {
  63. $this->returnJson['statusCode'] = '130006';
  64. }
  65. }
  66. exitOutput($this->returnJson);
  67. }
  68. /**
  69. * 修改昵称
  70. */
  71. public function changeNickName()
  72. {
  73. $nickNameLength = mb_strlen(quickInput('nickName'), 'utf8');
  74. $nickName = securelyInput('nickName');
  75. if ($nickNameLength > 20) {
  76. //昵称格式非法
  77. $this->returnJson['statusCode'] = '130008';
  78. } else {
  79. $server = new UserModule;
  80. $result = $server->changeNickName($nickName);
  81. if ($result) {
  82. $this->returnJson['statusCode'] = '000000';
  83. } else {
  84. $this->returnJson['statusCode'] = '130009';
  85. }
  86. }
  87. exitOutput($this->returnJson);
  88. }
  89. /**
  90. * 确认用户名
  91. */
  92. public function confirmUserName()
  93. {
  94. $userName = securelyInput('userName');
  95. //验证用户名,4~16位非纯数字,英文数字下划线组合,只能以英文开头
  96. if (!preg_match('/^[a-zA-Z][0-9a-zA-Z_]{3,59}$/', $userName)) {
  97. //用户名非法
  98. $this->returnJson['statusCode'] = '130001';
  99. } else {
  100. $server = new UserModule;
  101. $result = $server->confirmUserName($userName);
  102. if ($result) {
  103. $this->returnJson['statusCode'] = '000000';
  104. } else {
  105. $this->returnJson['statusCode'] = '130010';
  106. }
  107. }
  108. exitOutput($this->returnJson);
  109. }
  110. /**
  111. * 获取用户信息
  112. */
  113. public function getUserInfo()
  114. {
  115. $server = new UserModule;
  116. $result = $server->getUserInfo();
  117. if ($result) {
  118. $this->returnJson['statusCode'] = '000000';
  119. $this->returnJson['userInfo'] = $result;
  120. } else {
  121. $this->returnJson['statusCode'] = '130013';
  122. }
  123. exitOutput($this->returnJson);
  124. }
  125. }
  126. ?>