| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106 |
- <?php
- /**
- * 这个方法不会检测登入和权限,如果需要登入后操作的请放到 CommonController
- */
- class SiteController extends Controller
- {
- /**
- * This is the action to handle external exceptions.
- */
- public function actionError()
- {
- Helper::error('系统错误', 500, Yii::app()->errorHandler->error);
- }
- /**
- * Displays the login page
- */
- public function actionLogin()
- {
- $model=new LoginForm;
- if (isset($_POST['username'])) {
- $model->attributes=$_POST;
- if($model->validate() && $model->login()){
- Helper::ok(['token' => \Yii::app()->session->getSessionID(), 'refreshToken' => '']);
- } else {
- Helper::error('登入失败');
- }
- }
- Helper::error('参数错误');
- }
- /**
- * 发送验证码
- */
- public function actionSendCode()
- {
- $phone = Helper::getPostString('phone', '');
- if (!Helper::isPhone($phone)) {
- Helper::error('手机号码格式错误');
- }
- // 验证码发送限制
- Helper::dealCommonResult(Helper::limitSmsSend(10, $phone, 5), false);
- if (!DB::getScalerWithCriteria('useradmin', DbCriteria::simpleCompare(['phone' => $phone])->setSelect('id'))) {
- Helper::error('该手机号用户不存在');
- }
- $code = (string)random_int(100000,999999);
- RedisInstance::getInstance()->set('user_code:'.$phone, $code, 600);
- // 发送短信
- Helper::dealCommonResult(SMS::getInstance()->send($phone, '2094847', [$code]));
- }
- /**
- * 找回密码
- */
- public function actionSetPassword()
- {
- $phone = Helper::getPostString('phone');
- $code = Helper::getPostString('code');
- $password = Helper::getPostString('password');
- if (!Helper::isPhone($phone)) {
- Helper::error('手机号码格式错误');
- }
- if (!$code || !$password) {
- Helper::error('参数错误');
- }
- if (RedisInstance::getInstance()->get('user_code:'.$phone) != $code) {
- Helper::error('验证码错误');
- }
- $id = DB::getScalerWithCriteria('useradmin', DbCriteria::simpleCompare(['phone' => $phone])->setSelect('id'));
- if (!$id) {
- Helper::error('该手机号用户不存在');
- }
- DB::updateById('useradmin', ['password' => md5($password)], $id);
- Helper::ok();
- }
- /******************************* 测试相关代码 ***************************************/
- public function actionPhp()
- {
- (new DBTable(Helper::getGetString('t1')))->echoEditPhp();
- }
- public function actionTs()
- {
- echo (new DBTable(Helper::getGetString('t1')))->getTsInterFace();
- }
- public function actionForm()
- {
- (new DBTable(Helper::getGetString('t1')))->editVue();
- }
- public function actionTable()
- {
- echo (new DBTable(Helper::getGetString('t1')))->getTableHtml();
- }
- public function actionInfo()
- {
- echo (new DBTable(Helper::getGetString('t1')))->getDetailHtml();
- }
- }
|