SiteController.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <?php
  2. /**
  3. * 这个方法不会检测登入和权限,如果需要登入后操作的请放到 CommonController
  4. */
  5. class SiteController extends Controller
  6. {
  7. /**
  8. * This is the action to handle external exceptions.
  9. */
  10. public function actionError()
  11. {
  12. Helper::error('系统错误', 500, Yii::app()->errorHandler->error);
  13. }
  14. /**
  15. * Displays the login page
  16. */
  17. public function actionLogin()
  18. {
  19. $model=new LoginForm;
  20. if (isset($_POST['username'])) {
  21. $model->attributes=$_POST;
  22. if($model->validate() && $model->login()){
  23. Helper::ok(['token' => \Yii::app()->session->getSessionID(), 'refreshToken' => '']);
  24. } else {
  25. Helper::error('登入失败');
  26. }
  27. }
  28. Helper::error('参数错误');
  29. }
  30. /**
  31. * 发送验证码
  32. */
  33. public function actionSendCode()
  34. {
  35. $phone = Helper::getPostString('phone', '');
  36. if (!Helper::isPhone($phone)) {
  37. Helper::error('手机号码格式错误');
  38. }
  39. // 验证码发送限制
  40. Helper::dealCommonResult(Helper::limitSmsSend(10, $phone, 5), false);
  41. if (!DB::getScalerWithCriteria('useradmin', DbCriteria::simpleCompare(['phone' => $phone])->setSelect('id'))) {
  42. Helper::error('该手机号用户不存在');
  43. }
  44. $code = (string)random_int(100000,999999);
  45. RedisInstance::getInstance()->set('user_code:'.$phone, $code, 600);
  46. // 发送短信
  47. Helper::dealCommonResult(SMS::getInstance()->send($phone, '2094847', [$code]));
  48. }
  49. /**
  50. * 找回密码
  51. */
  52. public function actionSetPassword()
  53. {
  54. $phone = Helper::getPostString('phone');
  55. $code = Helper::getPostString('code');
  56. $password = Helper::getPostString('password');
  57. if (!Helper::isPhone($phone)) {
  58. Helper::error('手机号码格式错误');
  59. }
  60. if (!$code || !$password) {
  61. Helper::error('参数错误');
  62. }
  63. if (RedisInstance::getInstance()->get('user_code:'.$phone) != $code) {
  64. Helper::error('验证码错误');
  65. }
  66. $id = DB::getScalerWithCriteria('useradmin', DbCriteria::simpleCompare(['phone' => $phone])->setSelect('id'));
  67. if (!$id) {
  68. Helper::error('该手机号用户不存在');
  69. }
  70. DB::updateById('useradmin', ['password' => md5($password)], $id);
  71. Helper::ok();
  72. }
  73. /******************************* 测试相关代码 ***************************************/
  74. public function actionPhp()
  75. {
  76. (new DBTable(Helper::getGetString('t1')))->echoEditPhp();
  77. }
  78. public function actionTs()
  79. {
  80. echo (new DBTable(Helper::getGetString('t1')))->getTsInterFace();
  81. }
  82. public function actionForm()
  83. {
  84. (new DBTable(Helper::getGetString('t1')))->editVue();
  85. }
  86. public function actionTable()
  87. {
  88. echo (new DBTable(Helper::getGetString('t1')))->getTableHtml();
  89. }
  90. public function actionInfo()
  91. {
  92. echo (new DBTable(Helper::getGetString('t1')))->getDetailHtml();
  93. }
  94. }