errorHandler->error); } public function beforeAction($action): bool { $this->checkRequest(); return true; } /** * Displays the login page */ public function actionLogin() { $userName = Helper::getPostString('username', ''); $password = Helper::getPostString('password', ''); if (!($userName && $password)) { Helper::error('参数错误'); } $user = DB::getInfoWithCriteria('useradmin', DbCriteria::simpleCompare(['username' => $userName, 'status' => 1])->setSelect('id, password')); if (!$user || $user['password'] != md5($password)) { Helper::error('登入失败'); } $token = Helper::getRandomString(32); RedisInstance::getInstance()->set('user_token:'.$token, ['id' => $user['id']], 86400); $this->clearAuth($user['id']); Helper::ok(['token' => $token, 'refreshToken' => '']); } /** * 发送验证码 */ 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(); } public function actionJson() { $newData = []; $data = file_get_contents(PROJECT_PATH . '/protected/runtime/city.json'); foreach (json_decode($data, true) as $province) { foreach ($province['citys'] as $city) { $newData[] = $city['city']; } } echo json_encode($newData, JSON_UNESCAPED_UNICODE); \CVarDumper::dump(count($newData), 6, 1);die; } public function actionDefault() { $data = 'id: number name: string // 名称 distinct: string[] // 地区, canteens: number[] // 地区, province: string // 省 city: string // 市 area: string // 区 address: string // 详细地址 bind_user_id?: number // 负责人 memo: string // 备注'; $data = explode("\n", $data); $data = array_map(function ($item) { $item = trim($item); $item = explode(':', $item); $name = trim($item[0], '? '); $type = trim(explode('//', $item[1])[0]); $value = "''"; switch ($type) { case '0|1': case 'number': $value = 0; break; case 'string[]': case 'number[]': $value = '[]'; break; } echo "{$name}: {$value},
"; }, $data); }*/ }