diff --git a/README.md b/README.md index a3018d2d..b7eddbb5 100644 --- a/README.md +++ b/README.md @@ -23,10 +23,10 @@ FastAdmin是一款基于ThinkPHP5+Bootstrap的极速后台开发框架。 * 共用同一账号体系的Web端会员中心权限验证和API接口会员权限验证 * 二级域名部署支持,同时域名支持绑定到插件 * 多语言支持,服务端及客户端支持 -* 强大的第三方模块支持([CMS](https://www.fastadmin.net/store/cms.html)、[博客](https://www.fastadmin.net/store/blog.html)、[文档生成](https://www.fastadmin.net/store/docs.html)) +* 强大的第三方模块支持([CMS](https://www.fastadmin.net/store/cms.html)、[博客](https://www.fastadmin.net/store/blog.html)、[知识付费问答](https://www.fastadmin.net/store/ask.html)) * 整合第三方短信接口(阿里云、腾讯云短信) * 无缝整合第三方云存储(七牛、阿里云OSS、又拍云)功能 -* 第三方富文本编辑器支持(Summernote、Tinymce、百度编辑器) +* 第三方富文本编辑器支持(Summernote、Kindeditor、百度编辑器) * 第三方登录(QQ、微信、微博)整合 * Ucenter整合第三方应用 @@ -86,6 +86,6 @@ FastAdmin遵循Apache2开源协议发布,并提供免费使用。 本项目包含的第三方源码和二进制文件之版权信息另行标注。 -版权所有Copyright © 2017-2018 by FastAdmin (https://www.fastadmin.net) +版权所有Copyright © 2017-2019 by FastAdmin (https://www.fastadmin.net) All rights reserved。 \ No newline at end of file diff --git a/application/admin/lang/zh-cn/addon.php b/application/admin/lang/zh-cn/addon.php index bb05cf98..c5088a49 100755 --- a/application/admin/lang/zh-cn/addon.php +++ b/application/admin/lang/zh-cn/addon.php @@ -29,6 +29,9 @@ return [ 'Not installed tips' => '请安装后再访问插件前台页面!', 'Not enabled tips' => '插件已经禁用,请启用后再访问插件前台页面!', 'New version tips' => '发现新版本:%s 点击查看更新日志', + 'Store now available tips' => 'FastAdmin插件市场暂不可用,是否切换到本地插件?', + 'Switch to the local' => '切换到本地插件', + 'try to reload' => '重新尝试加载', 'Please disable addon first' => '请先禁用插件再进行升级', 'Login now' => '立即登录', 'Continue install' => '不登录,继续安装', diff --git a/application/admin/library/Auth.php b/application/admin/library/Auth.php index fe4c905e..8c569360 100644 --- a/application/admin/library/Auth.php +++ b/application/admin/library/Auth.php @@ -12,7 +12,6 @@ use think\Session; class Auth extends \fast\Auth { - protected $_error = ''; protected $requestUri = ''; protected $breadcrumb = []; @@ -33,7 +32,7 @@ class Auth extends \fast\Auth * * @param string $username 用户名 * @param string $password 密码 - * @param int $keeptime 有效时长 + * @param int $keeptime 有效时长 * @return boolean */ public function login($username, $password, $keeptime = 0) @@ -146,17 +145,17 @@ class Auth extends \fast\Auth $request = Request::instance(); $arr = is_array($arr) ? $arr : explode(',', $arr); if (!$arr) { - return FALSE; + return false; } $arr = array_map('strtolower', $arr); // 是否存在 if (in_array(strtolower($request->action()), $arr) || in_array('*', $arr)) { - return TRUE; + return true; } // 没找到匹配 - return FALSE; + return false; } /** @@ -229,7 +228,7 @@ class Auth extends \fast\Auth public function isSuperAdmin() { - return in_array('*', $this->getRuleIds()) ? TRUE : FALSE; + return in_array('*', $this->getRuleIds()) ? true : false; } /** @@ -322,8 +321,9 @@ class Auth extends \fast\Auth */ public function getBreadCrumb($path = '') { - if ($this->breadcrumb || !$path) + if ($this->breadcrumb || !$path) { return $this->breadcrumb; + } $path_rule_id = 0; foreach ($this->rules as $rule) { $path_rule_id = $rule['name'] == $path ? $rule['id'] : $path_rule_id; @@ -341,7 +341,7 @@ class Auth extends \fast\Auth /** * 获取左侧和顶部菜单栏 * - * @param array $params URL对应的badge数据 + * @param array $params URL对应的badge数据 * @param string $fixedPage 默认页 * @return array */ @@ -455,5 +455,4 @@ class Auth extends \fast\Auth { return $this->_error ? __($this->_error) : ''; } - } diff --git a/application/admin/library/traits/Backend.php b/application/admin/library/traits/Backend.php index d231811c..c543c689 100755 --- a/application/admin/library/traits/Backend.php +++ b/application/admin/library/traits/Backend.php @@ -7,7 +7,10 @@ use PhpOffice\PhpSpreadsheet\Cell\Coordinate; use PhpOffice\PhpSpreadsheet\Reader\Xlsx; use PhpOffice\PhpSpreadsheet\Reader\Xls; use PhpOffice\PhpSpreadsheet\Reader\Csv; +use think\Db; use think\Exception; +use think\exception\PDOException; +use think\exception\ValidateException; trait Backend { @@ -108,6 +111,8 @@ trait Backend if ($this->dataLimit && $this->dataLimitFieldAutoFill) { $params[$this->dataLimitField] = $this->auth->id; } + $result = false; + Db::startTrans(); try { //是否采用模型验证 if ($this->modelValidate) { @@ -116,15 +121,21 @@ trait Backend $this->model->validate($validate); } $result = $this->model->allowField(true)->save($params); - if ($result !== false) { - $this->success(); - } else { - $this->error($this->model->getError()); - } - } catch (\think\exception\PDOException $e) { + Db::commit(); + } catch (ValidateException $e) { + Db::rollback(); $this->error($e->getMessage()); - } catch (\think\Exception $e) { + } catch (PDOException $e) { + Db::rollback(); $this->error($e->getMessage()); + } catch (Exception $e) { + Db::rollback(); + $this->error($e->getMessage()); + } + if ($result) { + $this->success(); + } else { + $this->error(); } } $this->error(__('Parameter %s can not be empty', '')); @@ -151,7 +162,8 @@ trait Backend $params = $this->request->post("row/a"); if ($params) { $params = $this->preExcludeFields($params); - + $result = false; + Db::startTrans(); try { //是否采用模型验证 if ($this->modelValidate) { @@ -160,15 +172,21 @@ trait Backend $row->validate($validate); } $result = $row->allowField(true)->save($params); - if ($result !== false) { - $this->success(); - } else { - $this->error($row->getError()); - } - } catch (\think\exception\PDOException $e) { + Db::commit(); + } catch (ValidateException $e) { + Db::rollback(); $this->error($e->getMessage()); - } catch (\think\Exception $e) { + } catch (PDOException $e) { + Db::rollback(); $this->error($e->getMessage()); + } catch (Exception $e) { + Db::rollback(); + $this->error($e->getMessage()); + } + if ($result) { + $this->success(); + } else { + $this->error(); } } $this->error(__('Parameter %s can not be empty', '')); @@ -186,12 +204,23 @@ trait Backend $pk = $this->model->getPk(); $adminIds = $this->getDataLimitAdminIds(); if (is_array($adminIds)) { - $count = $this->model->where($this->dataLimitField, 'in', $adminIds); + $this->model->where($this->dataLimitField, 'in', $adminIds); } $list = $this->model->where($pk, 'in', $ids)->select(); + $count = 0; - foreach ($list as $k => $v) { - $count += $v->delete(); + Db::startTrans(); + try { + foreach ($list as $k => $v) { + $count += $v->delete(); + } + Db::commit(); + } catch (PDOException $e) { + Db::rollback(); + $this->error($e->getMessage()); + } catch (Exception $e) { + Db::rollback(); + $this->error($e->getMessage()); } if ($count) { $this->success(); @@ -210,15 +239,25 @@ trait Backend $pk = $this->model->getPk(); $adminIds = $this->getDataLimitAdminIds(); if (is_array($adminIds)) { - $count = $this->model->where($this->dataLimitField, 'in', $adminIds); + $this->model->where($this->dataLimitField, 'in', $adminIds); } if ($ids) { $this->model->where($pk, 'in', $ids); } $count = 0; - $list = $this->model->onlyTrashed()->select(); - foreach ($list as $k => $v) { - $count += $v->delete(true); + Db::startTrans(); + try { + $list = $this->model->onlyTrashed()->select(); + foreach ($list as $k => $v) { + $count += $v->delete(true); + } + Db::commit(); + } catch (PDOException $e) { + Db::rollback(); + $this->error($e->getMessage()); + } catch (Exception $e) { + Db::rollback(); + $this->error($e->getMessage()); } if ($count) { $this->success(); @@ -242,9 +281,19 @@ trait Backend $this->model->where($pk, 'in', $ids); } $count = 0; - $list = $this->model->onlyTrashed()->select(); - foreach ($list as $index => $item) { - $count += $item->restore(); + Db::startTrans(); + try { + $list = $this->model->onlyTrashed()->select(); + foreach ($list as $index => $item) { + $count += $item->restore(); + } + Db::commit(); + } catch (PDOException $e) { + Db::rollback(); + $this->error($e->getMessage()); + } catch (Exception $e) { + Db::rollback(); + $this->error($e->getMessage()); } if ($count) { $this->success(); @@ -268,9 +317,19 @@ trait Backend $this->model->where($this->dataLimitField, 'in', $adminIds); } $count = 0; - $list = $this->model->where($this->model->getPk(), 'in', $ids)->select(); - foreach ($list as $index => $item) { - $count += $item->allowField(true)->isUpdate(true)->save($values); + Db::startTrans(); + try { + $list = $this->model->where($this->model->getPk(), 'in', $ids)->select(); + foreach ($list as $index => $item) { + $count += $item->allowField(true)->isUpdate(true)->save($values); + } + Db::commit(); + } catch (PDOException $e) { + Db::rollback(); + $this->error($e->getMessage()); + } catch (Exception $e) { + Db::rollback(); + $this->error($e->getMessage()); } if ($count) { $this->success(); @@ -405,7 +464,7 @@ trait Backend } } $this->model->saveAll($insert); - } catch (\think\exception\PDOException $exception) { + } catch (PDOException $exception) { $msg = $exception->getMessage(); if (preg_match("/.+Integrity constraint violation: 1062 Duplicate entry '(.+)' for key '(.+)'/is", $msg, $matches)) { $msg = "导入失败,包含【{$matches[1]}】的记录已存在"; diff --git a/application/api/controller/Common.php b/application/api/controller/Common.php index 615e8376..d8624cfb 100644 --- a/application/api/controller/Common.php +++ b/application/api/controller/Common.php @@ -13,21 +13,15 @@ use think\Config; */ class Common extends Api { - protected $noNeedLogin = ['init']; protected $noNeedRight = '*'; - public function _initialize() - { - parent::_initialize(); - } - /** * 加载初始化 * * @param string $version 版本号 - * @param string $lng 经度 - * @param string $lat 纬度 + * @param string $lng 经度 + * @param string $lat 纬度 */ public function init() { @@ -137,5 +131,4 @@ class Common extends Api $this->error($file->getError()); } } - } diff --git a/application/api/controller/Ems.php b/application/api/controller/Ems.php index b9c772ba..0046cdbc 100644 --- a/application/api/controller/Ems.php +++ b/application/api/controller/Ems.php @@ -1,123 +1,102 @@ -to($params->email) - ->subject('验证码') - ->message("你的验证码是:" . $params->code) - ->send(); - return $result; - }); - } - - /** - * 发送验证码 - * - * @param string $email 邮箱 - * @param string $event 事件名称 - */ - public function send() - { - $email = $this->request->request("email"); - $event = $this->request->request("event"); - $event = $event ? $event : 'register'; - - $last = Emslib::get($email, $event); - if ($last && time() - $last['createtime'] < 60) - { - $this->error(__('发送频繁')); - } - if ($event) - { - $userinfo = User::getByEmail($email); - if ($event == 'register' && $userinfo) - { - //已被注册 - $this->error(__('已被注册')); - } - else if (in_array($event, ['changeemail']) && $userinfo) - { - //被占用 - $this->error(__('已被占用')); - } - else if (in_array($event, ['changepwd', 'resetpwd']) && !$userinfo) - { - //未注册 - $this->error(__('未注册')); - } - } - $ret = Emslib::send($email, NULL, $event); - if ($ret) - { - $this->success(__('发送成功')); - } - else - { - $this->error(__('发送失败')); - } - } - - /** - * 检测验证码 - * - * @param string $email 邮箱 - * @param string $event 事件名称 - * @param string $captcha 验证码 - */ - public function check() - { - $email = $this->request->request("email"); - $event = $this->request->request("event"); - $event = $event ? $event : 'register'; - $captcha = $this->request->request("captcha"); - - if ($event) - { - $userinfo = User::getByEmail($email); - if ($event == 'register' && $userinfo) - { - //已被注册 - $this->error(__('已被注册')); - } - else if (in_array($event, ['changeemail']) && $userinfo) - { - //被占用 - $this->error(__('已被占用')); - } - else if (in_array($event, ['changepwd', 'resetpwd']) && !$userinfo) - { - //未注册 - $this->error(__('未注册')); - } - } - $ret = Emslib::check($email, $captcha, $event); - if ($ret) - { - $this->success(__('成功')); - } - else - { - $this->error(__('验证码不正确')); - } - } - -} +to($params->email) + ->subject('验证码') + ->message("你的验证码是:" . $params->code) + ->send(); + return $result; + }); + } + + /** + * 发送验证码 + * + * @param string $email 邮箱 + * @param string $event 事件名称 + */ + public function send() + { + $email = $this->request->request("email"); + $event = $this->request->request("event"); + $event = $event ? $event : 'register'; + + $last = Emslib::get($email, $event); + if ($last && time() - $last['createtime'] < 60) { + $this->error(__('发送频繁')); + } + if ($event) { + $userinfo = User::getByEmail($email); + if ($event == 'register' && $userinfo) { + //已被注册 + $this->error(__('已被注册')); + } elseif (in_array($event, ['changeemail']) && $userinfo) { + //被占用 + $this->error(__('已被占用')); + } elseif (in_array($event, ['changepwd', 'resetpwd']) && !$userinfo) { + //未注册 + $this->error(__('未注册')); + } + } + $ret = Emslib::send($email, null, $event); + if ($ret) { + $this->success(__('发送成功')); + } else { + $this->error(__('发送失败')); + } + } + + /** + * 检测验证码 + * + * @param string $email 邮箱 + * @param string $event 事件名称 + * @param string $captcha 验证码 + */ + public function check() + { + $email = $this->request->request("email"); + $event = $this->request->request("event"); + $event = $event ? $event : 'register'; + $captcha = $this->request->request("captcha"); + + if ($event) { + $userinfo = User::getByEmail($email); + if ($event == 'register' && $userinfo) { + //已被注册 + $this->error(__('已被注册')); + } elseif (in_array($event, ['changeemail']) && $userinfo) { + //被占用 + $this->error(__('已被占用')); + } elseif (in_array($event, ['changepwd', 'resetpwd']) && !$userinfo) { + //未注册 + $this->error(__('未注册')); + } + } + $ret = Emslib::check($email, $captcha, $event); + if ($ret) { + $this->success(__('成功')); + } else { + $this->error(__('验证码不正确')); + } + } +} diff --git a/application/api/controller/Index.php b/application/api/controller/Index.php index 0bc9d9af..24c615e8 100644 --- a/application/api/controller/Index.php +++ b/application/api/controller/Index.php @@ -9,17 +9,15 @@ use app\common\controller\Api; */ class Index extends Api { - protected $noNeedLogin = ['*']; protected $noNeedRight = ['*']; /** * 首页 - * + * */ public function index() { $this->success('请求成功'); } - } diff --git a/application/api/controller/Sms.php b/application/api/controller/Sms.php index f8ac47bb..fc3a1318 100644 --- a/application/api/controller/Sms.php +++ b/application/api/controller/Sms.php @@ -1,105 +1,98 @@ -request->request("mobile"); - $event = $this->request->request("event"); - $event = $event ? $event : 'register'; - - if (!$mobile || !\think\Validate::regex($mobile, "^1\d{10}$")) { - $this->error(__('手机号不正确')); - } - $last = Smslib::get($mobile, $event); - if ($last && time() - $last['createtime'] < 60) { - $this->error(__('发送频繁')); - } - $ipSendTotal = \app\common\model\Sms::where(['ip' => $this->request->ip()])->whereTime('createtime', '-1 hours')->count(); - if ($ipSendTotal >= 5) { - $this->error(__('发送频繁')); - } - if ($event) { - $userinfo = User::getByMobile($mobile); - if ($event == 'register' && $userinfo) { - //已被注册 - $this->error(__('已被注册')); - } else if (in_array($event, ['changemobile']) && $userinfo) { - //被占用 - $this->error(__('已被占用')); - } else if (in_array($event, ['changepwd', 'resetpwd']) && !$userinfo) { - //未注册 - $this->error(__('未注册')); - } - } - $ret = Smslib::send($mobile, NULL, $event); - if ($ret) { - $this->success(__('发送成功')); - } else { - $this->error(__('发送失败')); - } - } - - /** - * 检测验证码 - * - * @param string $mobile 手机号 - * @param string $event 事件名称 - * @param string $captcha 验证码 - */ - public function check() - { - $mobile = $this->request->request("mobile"); - $event = $this->request->request("event"); - $event = $event ? $event : 'register'; - $captcha = $this->request->request("captcha"); - - if (!$mobile || !\think\Validate::regex($mobile, "^1\d{10}$")) { - $this->error(__('手机号不正确')); - } - if ($event) { - $userinfo = User::getByMobile($mobile); - if ($event == 'register' && $userinfo) { - //已被注册 - $this->error(__('已被注册')); - } else if (in_array($event, ['changemobile']) && $userinfo) { - //被占用 - $this->error(__('已被占用')); - } else if (in_array($event, ['changepwd', 'resetpwd']) && !$userinfo) { - //未注册 - $this->error(__('未注册')); - } - } - $ret = Smslib::check($mobile, $captcha, $event); - if ($ret) { - $this->success(__('成功')); - } else { - $this->error(__('验证码不正确')); - } - } - -} +request->request("mobile"); + $event = $this->request->request("event"); + $event = $event ? $event : 'register'; + + if (!$mobile || !\think\Validate::regex($mobile, "^1\d{10}$")) { + $this->error(__('手机号不正确')); + } + $last = Smslib::get($mobile, $event); + if ($last && time() - $last['createtime'] < 60) { + $this->error(__('发送频繁')); + } + $ipSendTotal = \app\common\model\Sms::where(['ip' => $this->request->ip()])->whereTime('createtime', '-1 hours')->count(); + if ($ipSendTotal >= 5) { + $this->error(__('发送频繁')); + } + if ($event) { + $userinfo = User::getByMobile($mobile); + if ($event == 'register' && $userinfo) { + //已被注册 + $this->error(__('已被注册')); + } elseif (in_array($event, ['changemobile']) && $userinfo) { + //被占用 + $this->error(__('已被占用')); + } elseif (in_array($event, ['changepwd', 'resetpwd']) && !$userinfo) { + //未注册 + $this->error(__('未注册')); + } + } + $ret = Smslib::send($mobile, null, $event); + if ($ret) { + $this->success(__('发送成功')); + } else { + $this->error(__('发送失败')); + } + } + + /** + * 检测验证码 + * + * @param string $mobile 手机号 + * @param string $event 事件名称 + * @param string $captcha 验证码 + */ + public function check() + { + $mobile = $this->request->request("mobile"); + $event = $this->request->request("event"); + $event = $event ? $event : 'register'; + $captcha = $this->request->request("captcha"); + + if (!$mobile || !\think\Validate::regex($mobile, "^1\d{10}$")) { + $this->error(__('手机号不正确')); + } + if ($event) { + $userinfo = User::getByMobile($mobile); + if ($event == 'register' && $userinfo) { + //已被注册 + $this->error(__('已被注册')); + } elseif (in_array($event, ['changemobile']) && $userinfo) { + //被占用 + $this->error(__('已被占用')); + } elseif (in_array($event, ['changepwd', 'resetpwd']) && !$userinfo) { + //未注册 + $this->error(__('未注册')); + } + } + $ret = Smslib::check($mobile, $captcha, $event); + if ($ret) { + $this->success(__('成功')); + } else { + $this->error(__('验证码不正确')); + } + } +} diff --git a/application/api/controller/Token.php b/application/api/controller/Token.php index f8a64ebb..75b280a1 100644 --- a/application/api/controller/Token.php +++ b/application/api/controller/Token.php @@ -1,49 +1,42 @@ -auth->getToken(); - $tokenInfo = \app\common\library\Token::get($token); - $this->success('', ['token' => $tokenInfo['token'], 'expires_in' => $tokenInfo['expires_in']]); - } - - /** - * 刷新Token - * - */ - public function refresh() - { - //删除源Token - $token = $this->auth->getToken(); - \app\common\library\Token::delete($token); - //创建新Token - $token = Random::uuid(); - \app\common\library\Token::set($token, $this->auth->id, 2592000); - $tokenInfo = \app\common\library\Token::get($token); - $this->success('', ['token' => $tokenInfo['token'], 'expires_in' => $tokenInfo['expires_in']]); - } - -} +auth->getToken(); + $tokenInfo = \app\common\library\Token::get($token); + $this->success('', ['token' => $tokenInfo['token'], 'expires_in' => $tokenInfo['expires_in']]); + } + + /** + * 刷新Token + * + */ + public function refresh() + { + //删除源Token + $token = $this->auth->getToken(); + \app\common\library\Token::delete($token); + //创建新Token + $token = Random::uuid(); + \app\common\library\Token::set($token, $this->auth->id, 2592000); + $tokenInfo = \app\common\library\Token::get($token); + $this->success('', ['token' => $tokenInfo['token'], 'expires_in' => $tokenInfo['expires_in']]); + } +} diff --git a/application/api/controller/User.php b/application/api/controller/User.php index fc990043..0387d195 100644 --- a/application/api/controller/User.php +++ b/application/api/controller/User.php @@ -13,7 +13,6 @@ use think\Validate; */ class User extends Api { - protected $noNeedLogin = ['login', 'mobilelogin', 'register', 'resetpwd', 'changeemail', 'changemobile', 'third']; protected $noNeedRight = '*'; @@ -33,7 +32,7 @@ class User extends Api /** * 会员登录 * - * @param string $account 账号 + * @param string $account 账号 * @param string $password 密码 */ public function login() @@ -55,7 +54,7 @@ class User extends Api /** * 手机验证码登录 * - * @param string $mobile 手机号 + * @param string $mobile 手机号 * @param string $captcha 验证码 */ public function mobilelogin() @@ -92,8 +91,8 @@ class User extends Api * * @param string $username 用户名 * @param string $password 密码 - * @param string $email 邮箱 - * @param string $mobile 手机号 + * @param string $email 邮箱 + * @param string $mobile 手机号 */ public function register() { @@ -131,10 +130,10 @@ class User extends Api /** * 修改会员个人信息 * - * @param string $avatar 头像地址 + * @param string $avatar 头像地址 * @param string $username 用户名 * @param string $nickname 昵称 - * @param string $bio 个人简介 + * @param string $bio 个人简介 */ public function profile() { @@ -142,7 +141,7 @@ class User extends Api $username = $this->request->request('username'); $nickname = $this->request->request('nickname'); $bio = $this->request->request('bio'); - $avatar = $this->request->request('avatar'); + $avatar = $this->request->request('avatar', '', 'trim,strip_tags,htmlspecialchars'); if ($username) { $exists = \app\common\model\User::where('username', $username)->where('id', '<>', $this->auth->id)->find(); if ($exists) { @@ -160,7 +159,7 @@ class User extends Api /** * 修改邮箱 * - * @param string $email 邮箱 + * @param string $email 邮箱 * @param string $captcha 验证码 */ public function changeemail() @@ -194,7 +193,7 @@ class User extends Api /** * 修改手机号 * - * @param string $email 手机号 + * @param string $email 手机号 * @param string $captcha 验证码 */ public function changemobile() @@ -229,7 +228,7 @@ class User extends Api * 第三方登录 * * @param string $platform 平台名称 - * @param string $code Code码 + * @param string $code Code码 */ public function third() { @@ -259,9 +258,9 @@ class User extends Api /** * 重置密码 * - * @param string $mobile 手机号 + * @param string $mobile 手机号 * @param string $newpassword 新密码 - * @param string $captcha 验证码 + * @param string $captcha 验证码 */ public function resetpwd() { @@ -309,5 +308,4 @@ class User extends Api $this->error($this->auth->getError()); } } - } diff --git a/application/api/controller/Validate.php b/application/api/controller/Validate.php index c950eda4..87d153b8 100644 --- a/application/api/controller/Validate.php +++ b/application/api/controller/Validate.php @@ -1,147 +1,138 @@ -request->request('email'); - $id = (int) $this->request->request('id'); - $count = User::where('email', '=', $email)->where('id', '<>', $id)->count(); - if ($count > 0) - { - $this->error(__('邮箱已经被占用')); - } - $this->success(); - } - - /** - * 检测用户名 - * - * @param string $username 用户名 - * @param string $id 排除会员ID - */ - public function check_username_available() - { - $email = $this->request->request('username'); - $id = (int) $this->request->request('id'); - $count = User::where('username', '=', $email)->where('id', '<>', $id)->count(); - if ($count > 0) - { - $this->error(__('用户名已经被占用')); - } - $this->success(); - } - - /** - * 检测手机 - * - * @param string $mobile 手机号 - * @param string $id 排除会员ID - */ - public function check_mobile_available() - { - $mobile = $this->request->request('mobile'); - $id = (int) $this->request->request('id'); - $count = User::where('mobile', '=', $mobile)->where('id', '<>', $id)->count(); - if ($count > 0) - { - $this->error(__('该手机号已经占用')); - } - $this->success(); - } - - /** - * 检测手机 - * - * @param string $mobile 手机号 - */ - public function check_mobile_exist() - { - $mobile = $this->request->request('mobile'); - $count = User::where('mobile', '=', $mobile)->count(); - if (!$count) - { - $this->error(__('手机号不存在')); - } - $this->success(); - } - - /** - * 检测邮箱 - * - * @param string $mobile 邮箱 - */ - public function check_email_exist() - { - $email = $this->request->request('email'); - $count = User::where('email', '=', $email)->count(); - if (!$count) - { - $this->error(__('邮箱不存在')); - } - $this->success(); - } - - /** - * 检测手机验证码 - * - * @param string $mobile 手机号 - * @param string $captcha 验证码 - * @param string $event 事件 - */ - public function check_sms_correct() - { - $mobile = $this->request->request('mobile'); - $captcha = $this->request->request('captcha'); - $event = $this->request->request('event'); - if (!\app\common\library\Sms::check($mobile, $captcha, $event)) - { - $this->error(__('验证码不正确')); - } - $this->success(); - } - - /** - * 检测邮箱验证码 - * - * @param string $email 邮箱 - * @param string $captcha 验证码 - * @param string $event 事件 - */ - public function check_ems_correct() - { - $email = $this->request->request('email'); - $captcha = $this->request->request('captcha'); - $event = $this->request->request('event'); - if (!\app\common\library\Ems::check($email, $captcha, $event)) - { - $this->error(__('验证码不正确')); - } - $this->success(); - } - -} +request->request('email'); + $id = (int)$this->request->request('id'); + $count = User::where('email', '=', $email)->where('id', '<>', $id)->count(); + if ($count > 0) { + $this->error(__('邮箱已经被占用')); + } + $this->success(); + } + + /** + * 检测用户名 + * + * @param string $username 用户名 + * @param string $id 排除会员ID + */ + public function check_username_available() + { + $email = $this->request->request('username'); + $id = (int)$this->request->request('id'); + $count = User::where('username', '=', $email)->where('id', '<>', $id)->count(); + if ($count > 0) { + $this->error(__('用户名已经被占用')); + } + $this->success(); + } + + /** + * 检测手机 + * + * @param string $mobile 手机号 + * @param string $id 排除会员ID + */ + public function check_mobile_available() + { + $mobile = $this->request->request('mobile'); + $id = (int)$this->request->request('id'); + $count = User::where('mobile', '=', $mobile)->where('id', '<>', $id)->count(); + if ($count > 0) { + $this->error(__('该手机号已经占用')); + } + $this->success(); + } + + /** + * 检测手机 + * + * @param string $mobile 手机号 + */ + public function check_mobile_exist() + { + $mobile = $this->request->request('mobile'); + $count = User::where('mobile', '=', $mobile)->count(); + if (!$count) { + $this->error(__('手机号不存在')); + } + $this->success(); + } + + /** + * 检测邮箱 + * + * @param string $mobile 邮箱 + */ + public function check_email_exist() + { + $email = $this->request->request('email'); + $count = User::where('email', '=', $email)->count(); + if (!$count) { + $this->error(__('邮箱不存在')); + } + $this->success(); + } + + /** + * 检测手机验证码 + * + * @param string $mobile 手机号 + * @param string $captcha 验证码 + * @param string $event 事件 + */ + public function check_sms_correct() + { + $mobile = $this->request->request('mobile'); + $captcha = $this->request->request('captcha'); + $event = $this->request->request('event'); + if (!\app\common\library\Sms::check($mobile, $captcha, $event)) { + $this->error(__('验证码不正确')); + } + $this->success(); + } + + /** + * 检测邮箱验证码 + * + * @param string $email 邮箱 + * @param string $captcha 验证码 + * @param string $event 事件 + */ + public function check_ems_correct() + { + $email = $this->request->request('email'); + $captcha = $this->request->request('captcha'); + $event = $this->request->request('event'); + if (!\app\common\library\Ems::check($email, $captcha, $event)) { + $this->error(__('验证码不正确')); + } + $this->success(); + } +} diff --git a/application/api/lang/zh-cn.php b/application/api/lang/zh-cn.php index 53cd5437..35dafd70 100644 --- a/application/api/lang/zh-cn.php +++ b/application/api/lang/zh-cn.php @@ -2,16 +2,13 @@ return [ 'Keep login' => '保持会话', - 'Sign in' => '登入', 'Username' => '用户名', 'User id' => '会员ID', - 'Username' => '用户名', 'Nickname' => '昵称', 'Password' => '密码', 'Sign up' => '注 册', 'Sign in' => '登 录', 'Sign out' => '注 销', - 'Keep login' => '保持会话', 'Guest' => '游客', 'Welcome' => '%s,你好!', 'Add' => '添加', @@ -56,13 +53,9 @@ return [ 'Line' => '行号', 'File' => '文件', 'Menu' => '菜单', - 'Name' => '名称', - 'Weigh' => '权重', 'Type' => '类型', 'Title' => '标题', 'Content' => '内容', - 'Status' => '状态', - 'Operate' => '操作', 'Append' => '追加', 'Memo' => '备注', 'Parent' => '父级', diff --git a/application/api/lang/zh-cn/user.php b/application/api/lang/zh-cn/user.php index db7fd11b..111ccf54 100644 --- a/application/api/lang/zh-cn/user.php +++ b/application/api/lang/zh-cn/user.php @@ -9,7 +9,6 @@ return [ 'Username must be 6 to 30 characters' => '用户名必须6-30个字符', 'Password can not be empty' => '密码不能为空', 'Password must be 6 to 30 characters' => '密码必须6-30个字符', - 'Email is incorrect' => '邮箱格式不正确', 'Mobile is incorrect' => '手机格式不正确', 'Username already exist' => '用户名已经存在', 'Email already exist' => '邮箱已经存在', @@ -27,9 +26,7 @@ return [ 'Profile' => '个人资料', 'Verify email' => '邮箱验证', 'Change password' => '修改密码', - 'Change password successful' => '修改密码成功', 'Captcha is incorrect' => '验证码不正确', - 'Sign up successful' => '注册成功', 'Logged in successful' => '登录成功', 'Logout successful' => '注销成功', 'Operation failed' => '操作失败', diff --git a/application/api/library/ExceptionHandle.php b/application/api/library/ExceptionHandle.php index e3d095cd..852f7efe 100644 --- a/application/api/library/ExceptionHandle.php +++ b/application/api/library/ExceptionHandle.php @@ -14,20 +14,17 @@ class ExceptionHandle extends Handle public function render(Exception $e) { // 在生产环境下返回code信息 - if (!\think\Config::get('app_debug')) - { + if (!\think\Config::get('app_debug')) { $statuscode = $code = 500; $msg = 'An error occurred'; // 验证异常 - if ($e instanceof \think\exception\ValidateException) - { + if ($e instanceof \think\exception\ValidateException) { $code = 0; $statuscode = 200; $msg = $e->getError(); } // Http异常 - if ($e instanceof \think\exception\HttpException) - { + if ($e instanceof \think\exception\HttpException) { $statuscode = $code = $e->getStatusCode(); } return json(['code' => $code, 'msg' => $msg, 'time' => time(), 'data' => null], $statuscode); diff --git a/application/common/behavior/Common.php b/application/common/behavior/Common.php index 7e436948..ee3a1b31 100644 --- a/application/common/behavior/Common.php +++ b/application/common/behavior/Common.php @@ -8,7 +8,6 @@ use think\Loader; class Common { - public function moduleInit(&$request) { // 设置mbstring字符编码 @@ -17,45 +16,37 @@ class Common // 如果修改了index.php入口地址,则需要手动修改cdnurl的值 $url = preg_replace("/\/(\w+)\.php$/i", '', $request->root()); // 如果未设置__CDN__则自动匹配得出 - if (!Config::get('view_replace_str.__CDN__')) - { + if (!Config::get('view_replace_str.__CDN__')) { Config::set('view_replace_str.__CDN__', $url); } // 如果未设置__PUBLIC__则自动匹配得出 - if (!Config::get('view_replace_str.__PUBLIC__')) - { + if (!Config::get('view_replace_str.__PUBLIC__')) { Config::set('view_replace_str.__PUBLIC__', $url . '/'); } // 如果未设置__ROOT__则自动匹配得出 - if (!Config::get('view_replace_str.__ROOT__')) - { + if (!Config::get('view_replace_str.__ROOT__')) { Config::set('view_replace_str.__ROOT__', preg_replace("/\/public\/$/", '', $url . '/')); } // 如果未设置cdnurl则自动匹配得出 - if (!Config::get('site.cdnurl')) - { + if (!Config::get('site.cdnurl')) { Config::set('site.cdnurl', $url); } // 如果未设置cdnurl则自动匹配得出 - if (!Config::get('upload.cdnurl')) - { + if (!Config::get('upload.cdnurl')) { Config::set('upload.cdnurl', $url); } - if (Config::get('app_debug')) - { + if (Config::get('app_debug')) { // 如果是调试模式将version置为当前的时间戳可避免缓存 Config::set('site.version', time()); // 如果是开发模式那么将异常模板修改成官方的 Config::set('exception_tmpl', THINK_PATH . 'tpl' . DS . 'think_exception.tpl'); } // 如果是trace模式且Ajax的情况下关闭trace - if (Config::get('app_trace') && $request->isAjax()) - { + if (Config::get('app_trace') && $request->isAjax()) { Config::set('app_trace', false); } // 切换多语言 - if (Config::get('lang_switch_on') && $request->get('lang')) - { + if (Config::get('lang_switch_on') && $request->get('lang')) { \think\Cookie::set('think_var', $request->get('lang')); } // Form别名 @@ -72,5 +63,4 @@ class Common ]); $this->moduleInit($request); } - } diff --git a/application/common/controller/Api.php b/application/common/controller/Api.php index acd65ec1..0fd34431 100644 --- a/application/common/controller/Api.php +++ b/application/common/controller/Api.php @@ -52,13 +52,13 @@ class Api /** * 权限Auth - * @var Auth + * @var Auth */ protected $auth = null; /** * 默认响应输出类型,支持json/xml - * @var string + * @var string */ protected $responseType = 'json'; @@ -75,13 +75,11 @@ class Api $this->_initialize(); // 前置操作方法 - if ($this->beforeActionList) - { - foreach ($this->beforeActionList as $method => $options) - { + if ($this->beforeActionList) { + foreach ($this->beforeActionList as $method => $options) { is_numeric($method) ? - $this->beforeAction($options) : - $this->beforeAction($method, $options); + $this->beforeAction($options) : + $this->beforeAction($method, $options); } } } @@ -108,30 +106,23 @@ class Api // 设置当前请求的URI $this->auth->setRequestUri($path); // 检测是否需要验证登录 - if (!$this->auth->match($this->noNeedLogin)) - { + if (!$this->auth->match($this->noNeedLogin)) { //初始化 $this->auth->init($token); //检测是否登录 - if (!$this->auth->isLogin()) - { + if (!$this->auth->isLogin()) { $this->error(__('Please login first'), null, 401); } // 判断是否需要验证权限 - if (!$this->auth->match($this->noNeedRight)) - { + if (!$this->auth->match($this->noNeedRight)) { // 判断控制器和方法判断是否有对应权限 - if (!$this->auth->check($path)) - { + if (!$this->auth->check($path)) { $this->error(__('You have no permission'), null, 403); } } - } - else - { + } else { // 如果有传递token才验证是否登录状态 - if ($token) - { + if ($token) { $this->auth->init($token); } } @@ -158,11 +149,11 @@ class Api /** * 操作成功返回的数据 - * @param string $msg 提示信息 - * @param mixed $data 要返回的数据 - * @param int $code 错误码,默认为1 - * @param string $type 输出类型 - * @param array $header 发送的 Header 信息 + * @param string $msg 提示信息 + * @param mixed $data 要返回的数据 + * @param int $code 错误码,默认为1 + * @param string $type 输出类型 + * @param array $header 发送的 Header 信息 */ protected function success($msg = '', $data = null, $code = 1, $type = null, array $header = []) { @@ -171,11 +162,11 @@ class Api /** * 操作失败返回的数据 - * @param string $msg 提示信息 - * @param mixed $data 要返回的数据 - * @param int $code 错误码,默认为0 - * @param string $type 输出类型 - * @param array $header 发送的 Header 信息 + * @param string $msg 提示信息 + * @param mixed $data 要返回的数据 + * @param int $code 错误码,默认为0 + * @param string $type 输出类型 + * @param array $header 发送的 Header 信息 */ protected function error($msg = '', $data = null, $code = 0, $type = null, array $header = []) { @@ -204,13 +195,10 @@ class Api // 如果未设置类型则自动判断 $type = $type ? $type : ($this->request->param(config('var_jsonp_handler')) ? 'jsonp' : $this->responseType); - if (isset($header['statuscode'])) - { + if (isset($header['statuscode'])) { $code = $header['statuscode']; unset($header['statuscode']); - } - else - { + } else { //未设置状态码,根据code值判断 $code = $code >= 1000 || $code < 200 ? 200 : $code; } @@ -227,27 +215,20 @@ class Api */ protected function beforeAction($method, $options = []) { - if (isset($options['only'])) - { - if (is_string($options['only'])) - { + if (isset($options['only'])) { + if (is_string($options['only'])) { $options['only'] = explode(',', $options['only']); } - if (!in_array($this->request->action(), $options['only'])) - { + if (!in_array($this->request->action(), $options['only'])) { return; } - } - elseif (isset($options['except'])) - { - if (is_string($options['except'])) - { + } elseif (isset($options['except'])) { + if (is_string($options['except'])) { $options['except'] = explode(',', $options['except']); } - if (in_array($this->request->action(), $options['except'])) - { + if (in_array($this->request->action(), $options['except'])) { return; } } @@ -281,16 +262,12 @@ class Api */ protected function validate($data, $validate, $message = [], $batch = false, $callback = null) { - if (is_array($validate)) - { + if (is_array($validate)) { $v = Loader::validate(); $v->rule($validate); - } - else - { + } else { // 支持场景 - if (strpos($validate, '.')) - { + if (strpos($validate, '.')) { list($validate, $scene) = explode('.', $validate); } @@ -300,21 +277,20 @@ class Api } // 批量验证 - if ($batch || $this->batchValidate) + if ($batch || $this->batchValidate) { $v->batch(true); + } // 设置错误信息 - if (is_array($message)) + if (is_array($message)) { $v->message($message); + } // 使用回调验证 - if ($callback && is_callable($callback)) - { + if ($callback && is_callable($callback)) { call_user_func_array($callback, [$v, &$data]); } - if (!$v->check($data)) - { - if ($this->failException) - { + if (!$v->check($data)) { + if ($this->failException) { throw new ValidateException($v->getError()); } @@ -323,5 +299,4 @@ class Api return true; } - } diff --git a/application/common/controller/Backend.php b/application/common/controller/Backend.php index 59b37c06..100222f4 100644 --- a/application/common/controller/Backend.php +++ b/application/common/controller/Backend.php @@ -121,10 +121,10 @@ class Backend extends Controller $path = str_replace('.', '/', $controllername) . '/' . $actionname; // 定义是否Addtabs请求 - !defined('IS_ADDTABS') && define('IS_ADDTABS', input("addtabs") ? TRUE : FALSE); + !defined('IS_ADDTABS') && define('IS_ADDTABS', input("addtabs") ? true : false); // 定义是否Dialog请求 - !defined('IS_DIALOG') && define('IS_DIALOG', input("dialog") ? TRUE : FALSE); + !defined('IS_DIALOG') && define('IS_DIALOG', input("dialog") ? true : false); // 定义是否AJAX请求 !defined('IS_AJAX') && define('IS_AJAX', $this->request->isAjax()); @@ -233,7 +233,7 @@ class Backend extends Controller /** * 渲染配置信息 - * @param mixed $name 键名或数组 + * @param mixed $name 键名或数组 * @param mixed $value 值 */ protected function assignconfig($name, $value = '') @@ -243,7 +243,7 @@ class Backend extends Controller /** * 生成查询所需要的条件,排序方式 - * @param mixed $searchfields 快速查询的字段 + * @param mixed $searchfields 快速查询的字段 * @param boolean $relationSearch 是否关联查询 * @return array */ @@ -258,8 +258,8 @@ class Backend extends Controller $order = $this->request->get("order", "DESC"); $offset = $this->request->get("offset", 0); $limit = $this->request->get("limit", 0); - $filter = (array)json_decode($filter, TRUE); - $op = (array)json_decode($op, TRUE); + $filter = (array)json_decode($filter, true); + $op = (array)json_decode($op, true); $filter = $filter ? $filter : []; $where = []; $tableName = ''; @@ -325,13 +325,14 @@ class Backend extends Controller case 'BETWEEN': case 'NOT BETWEEN': $arr = array_slice(explode(',', $v), 0, 2); - if (stripos($v, ',') === false || !array_filter($arr)) + if (stripos($v, ',') === false || !array_filter($arr)) { continue 2; + } //当出现一边为空时改变操作符 if ($arr[0] === '') { $sym = $sym == 'BETWEEN' ? '<=' : '>'; $arr = $arr[1]; - } else if ($arr[1] === '') { + } elseif ($arr[1] === '') { $sym = $sym == 'BETWEEN' ? '>=' : '<'; $arr = $arr[0]; } @@ -341,13 +342,14 @@ class Backend extends Controller case 'NOT RANGE': $v = str_replace(' - ', ',', $v); $arr = array_slice(explode(',', $v), 0, 2); - if (stripos($v, ',') === false || !array_filter($arr)) + if (stripos($v, ',') === false || !array_filter($arr)) { continue 2; + } //当出现一边为空时改变操作符 if ($arr[0] === '') { $sym = $sym == 'RANGE' ? '<=' : '>'; $arr = $arr[1]; - } else if ($arr[1] === '') { + } elseif ($arr[1] === '') { $sym = $sym == 'RANGE' ? '>=' : '<'; $arr = $arr[0]; } @@ -488,11 +490,11 @@ class Backend extends Controller 'pid' => isset($item['pid']) ? $item['pid'] : 0 ]; } - if($istree) { + if ($istree) { $tree = Tree::instance(); $tree->init(collection($list)->toArray(), 'pid'); $list = $tree->getTreeList($tree->getTreeArray(0), $field); - if(!$ishtml){ + if (!$ishtml) { foreach ($list as &$item) { $item = str_replace(' ', ' ', $item); } @@ -503,5 +505,4 @@ class Backend extends Controller //这里一定要返回有list这个字段,total是可选的,如果total<=list的数量,则会隐藏分页按钮 return json(['list' => $list, 'total' => $total]); } - } diff --git a/application/common/controller/Frontend.php b/application/common/controller/Frontend.php index a661b3ef..09dd34cb 100644 --- a/application/common/controller/Frontend.php +++ b/application/common/controller/Frontend.php @@ -127,12 +127,11 @@ class Frontend extends Controller /** * 渲染配置信息 - * @param mixed $name 键名或数组 + * @param mixed $name 键名或数组 * @param mixed $value 值 */ protected function assignconfig($name, $value = '') { $this->view->config = array_merge($this->view->config ? $this->view->config : [], is_array($name) ? $name : [$name => $value]); } - } diff --git a/application/common/library/Auth.php b/application/common/library/Auth.php index cabbc3bf..102199dc 100644 --- a/application/common/library/Auth.php +++ b/application/common/library/Auth.php @@ -7,17 +7,17 @@ use app\common\model\UserRule; use fast\Random; use think\Config; use think\Db; +use think\Exception; use think\Hook; use think\Request; use think\Validate; class Auth { - protected static $instance = null; protected $_error = ''; - protected $_logined = FALSE; - protected $_user = NULL; + protected $_logined = false; + protected $_user = null; protected $_token = ''; //Token默认有效时长 protected $keeptime = 2592000; @@ -30,22 +30,20 @@ class Auth public function __construct($options = []) { - if ($config = Config::get('user')) - { + if ($config = Config::get('user')) { $this->config = array_merge($this->config, $config); } $this->options = array_merge($this->config, $options); } /** - * + * * @param array $options 参数 * @return Auth */ public static function instance($options = []) { - if (is_null(self::$instance)) - { + if (is_null(self::$instance)) { self::$instance = new static($options); } @@ -63,91 +61,82 @@ class Auth /** * 兼容调用user模型的属性 - * + * * @param string $name * @return mixed */ public function __get($name) { - return $this->_user ? $this->_user->$name : NULL; + return $this->_user ? $this->_user->$name : null; } /** * 根据Token初始化 * - * @param string $token Token + * @param string $token Token * @return boolean */ public function init($token) { - if ($this->_logined) - { - return TRUE; + if ($this->_logined) { + return true; + } + if ($this->_error) { + return false; } - if ($this->_error) - return FALSE; $data = Token::get($token); - if (!$data) - { - return FALSE; + if (!$data) { + return false; } $user_id = intval($data['user_id']); - if ($user_id > 0) - { + if ($user_id > 0) { $user = User::get($user_id); - if (!$user) - { + if (!$user) { $this->setError('Account not exist'); - return FALSE; + return false; } - if ($user['status'] != 'normal') - { + if ($user['status'] != 'normal') { $this->setError('Account is locked'); - return FALSE; + return false; } $this->_user = $user; - $this->_logined = TRUE; + $this->_logined = true; $this->_token = $token; //初始化成功的事件 Hook::listen("user_init_successed", $this->_user); - return TRUE; - } - else - { + return true; + } else { $this->setError('You are not logged in'); - return FALSE; + return false; } } /** * 注册用户 * - * @param string $username 用户名 - * @param string $password 密码 - * @param string $email 邮箱 - * @param string $mobile 手机号 - * @param array $extend 扩展参数 + * @param string $username 用户名 + * @param string $password 密码 + * @param string $email 邮箱 + * @param string $mobile 手机号 + * @param array $extend 扩展参数 * @return boolean */ public function register($username, $password, $email = '', $mobile = '', $extend = []) { // 检测用户名或邮箱、手机号是否存在 - if (User::getByUsername($username)) - { + if (User::getByUsername($username)) { $this->setError('Username already exist'); - return FALSE; + return false; } - if ($email && User::getByEmail($email)) - { + if ($email && User::getByEmail($email)) { $this->setError('Email already exist'); - return FALSE; + return false; } - if ($mobile && User::getByMobile($mobile)) - { + if ($mobile && User::getByMobile($mobile)) { $this->setError('Mobile already exist'); - return FALSE; + return false; } $ip = request()->ip(); @@ -175,31 +164,11 @@ class Auth $params['password'] = $this->getEncryptPassword($password, $params['salt']); $params = array_merge($params, $extend); - ////////////////同步到Ucenter//////////////// - if (defined('UC_STATUS') && UC_STATUS) - { - $uc = new \addons\ucenter\library\client\Client(); - $user_id = $uc->uc_user_register($username, $password, $email); - // 如果小于0则说明发生错误 - if ($user_id <= 0) - { - $this->setError($user_id > -4 ? 'Username is incorrect' : 'Email is incorrect'); - return FALSE; - } - else - { - $params['id'] = $user_id; - } - } - //账号注册时需要开启事务,避免出现垃圾数据 Db::startTrans(); - try - { - $user = User::create($params); - Db::commit(); + try { + $user = User::create($params, true); - // 此时的Model中只包含部分数据 $this->_user = User::get($user->id); //设置Token @@ -207,101 +176,99 @@ class Auth Token::set($this->_token, $user->id, $this->keeptime); //注册成功的事件 - Hook::listen("user_register_successed", $this->_user); - - return TRUE; - } - catch (Exception $e) - { + Hook::listen("user_register_successed", $this->_user, $data); + Db::commit(); + } catch (Exception $e) { $this->setError($e->getMessage()); Db::rollback(); - return FALSE; + return false; } + return true; } /** * 用户登录 * - * @param string $account 账号,用户名、邮箱、手机号 - * @param string $password 密码 + * @param string $account 账号,用户名、邮箱、手机号 + * @param string $password 密码 * @return boolean */ public function login($account, $password) { $field = Validate::is($account, 'email') ? 'email' : (Validate::regex($account, '/^1\d{10}$/') ? 'mobile' : 'username'); $user = User::get([$field => $account]); - if (!$user) - { + if (!$user) { $this->setError('Account is incorrect'); - return FALSE; + return false; } - if ($user->status != 'normal') - { + if ($user->status != 'normal') { $this->setError('Account is locked'); - return FALSE; + return false; } - if ($user->password != $this->getEncryptPassword($password, $user->salt)) - { + if ($user->password != $this->getEncryptPassword($password, $user->salt)) { $this->setError('Password is incorrect'); - return FALSE; + return false; } //直接登录会员 $this->direct($user->id); - return TRUE; + return true; } /** * 注销 - * + * * @return boolean */ public function logout() { - if (!$this->_logined) - { + if (!$this->_logined) { $this->setError('You are not logged in'); return false; } //设置登录标识 - $this->_logined = FALSE; + $this->_logined = false; //删除Token Token::delete($this->_token); //注销成功的事件 Hook::listen("user_logout_successed", $this->_user); - return TRUE; + return true; } /** * 修改密码 - * @param string $newpassword 新密码 - * @param string $oldpassword 旧密码 - * @param bool $ignoreoldpassword 忽略旧密码 + * @param string $newpassword 新密码 + * @param string $oldpassword 旧密码 + * @param bool $ignoreoldpassword 忽略旧密码 * @return boolean */ public function changepwd($newpassword, $oldpassword = '', $ignoreoldpassword = false) { - if (!$this->_logined) - { + if (!$this->_logined) { $this->setError('You are not logged in'); return false; } //判断旧密码是否正确 - if ($this->_user->password == $this->getEncryptPassword($oldpassword, $this->_user->salt) || $ignoreoldpassword) - { - $salt = Random::alnum(); - $newpassword = $this->getEncryptPassword($newpassword, $salt); - $this->_user->save(['password' => $newpassword, 'salt' => $salt]); + if ($this->_user->password == $this->getEncryptPassword($oldpassword, $this->_user->salt) || $ignoreoldpassword) { + Db::startTrans(); + try { + $salt = Random::alnum(); + $newpassword = $this->getEncryptPassword($newpassword, $salt); + $this->_user->save(['password' => $newpassword, 'salt' => $salt]); - Token::delete($this->_token); - //修改密码成功的事件 - Hook::listen("user_changepwd_successed", $this->_user); + Token::delete($this->_token); + //修改密码成功的事件 + Hook::listen("user_changepwd_successed", $this->_user); + Db::commit(); + } catch (Exception $e) { + Db::rollback(); + $this->setError($e->getMessage()); + return false; + } return true; - } - else - { + } else { $this->setError('Password is incorrect'); return false; } @@ -315,75 +282,66 @@ class Auth public function direct($user_id) { $user = User::get($user_id); - if ($user) - { - ////////////////同步到Ucenter//////////////// - if (defined('UC_STATUS') && UC_STATUS) - { - $uc = new \addons\ucenter\library\client\Client(); - $re = $uc->uc_user_login($this->user->id, $this->user->password . '#split#' . $this->user->salt, 3); - // 如果小于0则说明发生错误 - if ($re <= 0) - { - $this->setError('Username or password is incorrect'); - return FALSE; + if ($user) { + Db::startTrans(); + try { + $ip = request()->ip(); + $time = time(); + + //判断连续登录和最大连续登录 + if ($user->logintime < \fast\Date::unixtime('day')) { + $user->successions = $user->logintime < \fast\Date::unixtime('day', -1) ? 1 : $user->successions + 1; + $user->maxsuccessions = max($user->successions, $user->maxsuccessions); } + + $user->prevtime = $user->logintime; + //记录本次登录的IP和时间 + $user->loginip = $ip; + $user->logintime = $time; + + $user->save(); + + $this->_user = $user; + + $this->_token = Random::uuid(); + Token::set($this->_token, $user->id, $this->keeptime); + + $this->_logined = true; + + //登录成功的事件 + Hook::listen("user_login_successed", $this->_user); + Db::commit(); + } catch (Exception $e) { + Db::rollback(); + $this->setError($e->getMessage()); + return false; } - - $ip = request()->ip(); - $time = time(); - - //判断连续登录和最大连续登录 - if ($user->logintime < \fast\Date::unixtime('day')) - { - $user->successions = $user->logintime < \fast\Date::unixtime('day', -1) ? 1 : $user->successions + 1; - $user->maxsuccessions = max($user->successions, $user->maxsuccessions); - } - - $user->prevtime = $user->logintime; - //记录本次登录的IP和时间 - $user->loginip = $ip; - $user->logintime = $time; - - $user->save(); - - $this->_user = $user; - - $this->_token = Random::uuid(); - Token::set($this->_token, $user->id, $this->keeptime); - - $this->_logined = TRUE; - - //登录成功的事件 - Hook::listen("user_login_successed", $this->_user); - return TRUE; - } - else - { - return FALSE; + return true; + } else { + return false; } } /** * 检测是否是否有对应权限 - * @param string $path 控制器/方法 - * @param string $module 模块 默认为当前模块 + * @param string $path 控制器/方法 + * @param string $module 模块 默认为当前模块 * @return boolean */ - public function check($path = NULL, $module = NULL) + public function check($path = null, $module = null) { - if (!$this->_logined) + if (!$this->_logined) { return false; + } $ruleList = $this->getRuleList(); $rules = []; - foreach ($ruleList as $k => $v) - { + foreach ($ruleList as $k => $v) { $rules[] = $v['name']; } $url = ($module ? $module : request()->module()) . '/' . (is_null($path) ? $this->getRequestUri() : $path); $url = strtolower(str_replace('.', '/', $url)); - return in_array($url, $rules) ? TRUE : FALSE; + return in_array($url, $rules) ? true : false; } /** @@ -392,8 +350,7 @@ class Auth */ public function isLogin() { - if ($this->_logined) - { + if ($this->_logined) { return true; } return false; @@ -426,11 +383,11 @@ class Auth */ public function getRuleList() { - if ($this->rules) + if ($this->rules) { return $this->rules; + } $group = $this->_user->group; - if (!$group) - { + if (!$group) { return []; } $rules = explode(',', $group->rules); @@ -482,43 +439,30 @@ class Auth public function delete($user_id) { $user = User::get($user_id); - if (!$user) - { - return FALSE; + if (!$user) { + return false; } + Db::startTrans(); + try { + // 删除会员 + User::destroy($user_id); + // 删除会员指定的所有Token + Token::clear($user_id); - ////////////////同步到Ucenter//////////////// - if (defined('UC_STATUS') && UC_STATUS) - { - $uc = new \addons\ucenter\library\client\Client(); - $re = $uc->uc_user_delete($user['id']); - // 如果小于0则说明发生错误 - if ($re <= 0) - { - $this->setError('Account is locked'); - return FALSE; - } - } - - // 调用事务删除账号 - $result = Db::transaction(function($db) use($user_id) { - // 删除会员 - User::destroy($user_id); - // 删除会员指定的所有Token - Token::clear($user_id); - return TRUE; - }); - if ($result) - { Hook::listen("user_delete_successed", $user); + Db::commit(); + } catch (Exception $e) { + Db::rollback(); + $this->setError($e->getMessage()); + return false; } - return $result ? TRUE : FALSE; + return true; } /** * 获取密码加密后的字符串 - * @param string $password 密码 - * @param string $salt 密码盐 + * @param string $password 密码 + * @param string $salt 密码盐 * @return string */ public function getEncryptPassword($password, $salt = '') @@ -536,19 +480,17 @@ class Auth { $request = Request::instance(); $arr = is_array($arr) ? $arr : explode(',', $arr); - if (!$arr) - { - return FALSE; + if (!$arr) { + return false; } $arr = array_map('strtolower', $arr); // 是否存在 - if (in_array(strtolower($request->action()), $arr) || in_array('*', $arr)) - { - return TRUE; + if (in_array(strtolower($request->action()), $arr) || in_array('*', $arr)) { + return true; } // 没找到匹配 - return FALSE; + return false; } /** @@ -562,39 +504,35 @@ class Auth /** * 渲染用户数据 - * @param array $datalist 二维数组 - * @param mixed $fields 加载的字段列表 - * @param string $fieldkey 渲染的字段 - * @param string $renderkey 结果字段 + * @param array $datalist 二维数组 + * @param mixed $fields 加载的字段列表 + * @param string $fieldkey 渲染的字段 + * @param string $renderkey 结果字段 * @return array */ public function render(&$datalist, $fields = [], $fieldkey = 'user_id', $renderkey = 'userinfo') { $fields = !$fields ? ['id', 'nickname', 'level', 'avatar'] : (is_array($fields) ? $fields : explode(',', $fields)); $ids = []; - foreach ($datalist as $k => $v) - { - if (!isset($v[$fieldkey])) + foreach ($datalist as $k => $v) { + if (!isset($v[$fieldkey])) { continue; + } $ids[] = $v[$fieldkey]; } $list = []; - if ($ids) - { - if (!in_array('id', $fields)) - { + if ($ids) { + if (!in_array('id', $fields)) { $fields[] = 'id'; } $ids = array_unique($ids); $selectlist = User::where('id', 'in', $ids)->column($fields); - foreach ($selectlist as $k => $v) - { + foreach ($selectlist as $k => $v) { $list[$v['id']] = $v; } } - foreach ($datalist as $k => &$v) - { - $v[$renderkey] = isset($list[$v[$fieldkey]]) ? $list[$v[$fieldkey]] : NULL; + foreach ($datalist as $k => &$v) { + $v[$renderkey] = isset($list[$v[$fieldkey]]) ? $list[$v[$fieldkey]] : null; } unset($v); return $datalist; @@ -620,5 +558,4 @@ class Auth { return $this->_error ? __($this->_error) : ''; } - } diff --git a/application/common/library/Email.php b/application/common/library/Email.php index 0881e26e..acd24984 100644 --- a/application/common/library/Email.php +++ b/application/common/library/Email.php @@ -38,8 +38,7 @@ class Email */ public static function instance($options = []) { - if (is_null(self::$instance)) - { + if (is_null(self::$instance)) { self::$instance = new static($options); } @@ -52,8 +51,7 @@ class Email */ public function __construct($options = []) { - if ($config = Config::get('site')) - { + if ($config = Config::get('site')) { $this->options = array_merge($this->options, $config); } $this->options = array_merge($this->options, $options); @@ -114,7 +112,7 @@ class Email /** * 设置邮件正文 - * @param string $body + * @param string $body * @param boolean $ishtml * @return $this */ @@ -150,27 +148,20 @@ class Email public function send() { $result = false; - switch ($this->options['mail_type']) - { + switch ($this->options['mail_type']) { case 1: //使用phpmailer发送 $this->mail->setFrom($this->options['from'], $this->options['from_name']); $this->mail->addAddress($this->options['to'], $this->options['to_name']); $this->mail->Subject = $this->options['subject']; - if ($this->options['ishtml']) - { + if ($this->options['ishtml']) { $this->mail->msgHTML($this->options['body']); - } - else - { + } else { $this->mail->Body = $this->options['body']; } - try - { + try { $result = $this->mail->send(); - } - catch (\phpmailerException $e) - { + } catch (\phpmailerException $e) { $this->setError($e->getMessage()); } diff --git a/application/common/library/Ems.php b/application/common/library/Ems.php index a0ed193e..368278b5 100644 --- a/application/common/library/Ems.php +++ b/application/common/library/Ems.php @@ -1,144 +1,133 @@ - $email, 'event' => $event]) - ->order('id', 'DESC') - ->find(); - Hook::listen('ems_get', $ems, null, true); - return $ems ? $ems : NULL; - } - - /** - * 发送验证码 - * - * @param int $email 邮箱 - * @param int $code 验证码,为空时将自动生成4位数字 - * @param string $event 事件 - * @return boolean - */ - public static function send($email, $code = NULL, $event = 'default') - { - $code = is_null($code) ? mt_rand(1000, 9999) : $code; - $time = time(); - $ip = request()->ip(); - $ems = \app\common\model\Ems::create(['event' => $event, 'email' => $email, 'code' => $code, 'ip' => $ip, 'createtime' => $time]); - $result = Hook::listen('ems_send', $ems, null, true); - if (!$result) - { - $ems->delete(); - return FALSE; - } - return TRUE; - } - - /** - * 发送通知 - * - * @param mixed $email 邮箱,多个以,分隔 - * @param string $msg 消息内容 - * @param string $template 消息模板 - * @return boolean - */ - public static function notice($email, $msg = '', $template = NULL) - { - $params = [ - 'email' => $email, - 'msg' => $msg, - 'template' => $template - ]; - $result = Hook::listen('ems_notice', $params, null, true); - return $result ? TRUE : FALSE; - } - - /** - * 校验验证码 - * - * @param int $email 邮箱 - * @param int $code 验证码 - * @param string $event 事件 - * @return boolean - */ - public static function check($email, $code, $event = 'default') - { - $time = time() - self::$expire; - $ems = \app\common\model\Ems::where(['email' => $email, 'event' => $event]) - ->order('id', 'DESC') - ->find(); - if ($ems) - { - if ($ems['createtime'] > $time && $ems['times'] <= self::$maxCheckNums) - { - $correct = $code == $ems['code']; - if (!$correct) - { - $ems->times = $ems->times + 1; - $ems->save(); - return FALSE; - } - else - { - $result = Hook::listen('ems_check', $ems, null, true); - return TRUE; - } - } - else - { - // 过期则清空该邮箱验证码 - self::flush($email, $event); - return FALSE; - } - } - else - { - return FALSE; - } - } - - /** - * 清空指定邮箱验证码 - * - * @param int $email 邮箱 - * @param string $event 事件 - * @return boolean - */ - public static function flush($email, $event = 'default') - { - \app\common\model\Ems:: - where(['email' => $email, 'event' => $event]) - ->delete(); - Hook::listen('ems_flush'); - return TRUE; - } - -} + $email, 'event' => $event]) + ->order('id', 'DESC') + ->find(); + Hook::listen('ems_get', $ems, null, true); + return $ems ? $ems : null; + } + + /** + * 发送验证码 + * + * @param int $email 邮箱 + * @param int $code 验证码,为空时将自动生成4位数字 + * @param string $event 事件 + * @return boolean + */ + public static function send($email, $code = null, $event = 'default') + { + $code = is_null($code) ? mt_rand(1000, 9999) : $code; + $time = time(); + $ip = request()->ip(); + $ems = \app\common\model\Ems::create(['event' => $event, 'email' => $email, 'code' => $code, 'ip' => $ip, 'createtime' => $time]); + $result = Hook::listen('ems_send', $ems, null, true); + if (!$result) { + $ems->delete(); + return false; + } + return true; + } + + /** + * 发送通知 + * + * @param mixed $email 邮箱,多个以,分隔 + * @param string $msg 消息内容 + * @param string $template 消息模板 + * @return boolean + */ + public static function notice($email, $msg = '', $template = null) + { + $params = [ + 'email' => $email, + 'msg' => $msg, + 'template' => $template + ]; + $result = Hook::listen('ems_notice', $params, null, true); + return $result ? true : false; + } + + /** + * 校验验证码 + * + * @param int $email 邮箱 + * @param int $code 验证码 + * @param string $event 事件 + * @return boolean + */ + public static function check($email, $code, $event = 'default') + { + $time = time() - self::$expire; + $ems = \app\common\model\Ems::where(['email' => $email, 'event' => $event]) + ->order('id', 'DESC') + ->find(); + if ($ems) { + if ($ems['createtime'] > $time && $ems['times'] <= self::$maxCheckNums) { + $correct = $code == $ems['code']; + if (!$correct) { + $ems->times = $ems->times + 1; + $ems->save(); + return false; + } else { + $result = Hook::listen('ems_check', $ems, null, true); + return true; + } + } else { + // 过期则清空该邮箱验证码 + self::flush($email, $event); + return false; + } + } else { + return false; + } + } + + /** + * 清空指定邮箱验证码 + * + * @param int $email 邮箱 + * @param string $event 事件 + * @return boolean + */ + public static function flush($email, $event = 'default') + { + \app\common\model\Ems:: + where(['email' => $email, 'event' => $event]) + ->delete(); + Hook::listen('ems_flush'); + return true; + } +} diff --git a/application/common/library/Menu.php b/application/common/library/Menu.php index 4c20818a..b82ed191 100644 --- a/application/common/library/Menu.php +++ b/application/common/library/Menu.php @@ -17,18 +17,14 @@ class Menu */ public static function create($menu, $parent = 0) { - if (!is_numeric($parent)) - { + if (!is_numeric($parent)) { $parentRule = AuthRule::getByName($parent); $pid = $parentRule ? $parentRule['id'] : 0; - } - else - { + } else { $pid = $parent; } $allow = array_flip(['file', 'name', 'title', 'icon', 'condition', 'remark', 'ismenu']); - foreach ($menu as $k => $v) - { + foreach ($menu as $k => $v) { $hasChild = isset($v['sublist']) && $v['sublist'] ? true : false; $data = array_intersect_key($v, $allow); @@ -37,16 +33,12 @@ class Menu $data['icon'] = isset($data['icon']) ? $data['icon'] : ($hasChild ? 'fa fa-list' : 'fa fa-circle-o'); $data['pid'] = $pid; $data['status'] = 'normal'; - try - { + try { $menu = AuthRule::create($data); - if ($hasChild) - { + if ($hasChild) { self::create($v['sublist'], $menu->id); } - } - catch (PDOException $e) - { + } catch (PDOException $e) { throw new Exception($e->getMessage()); } } @@ -54,14 +46,13 @@ class Menu /** * 删除菜单 - * @param string $name 规则name + * @param string $name 规则name * @return boolean */ public static function delete($name) { $ids = self::getAuthRuleIdsByName($name); - if (!$ids) - { + if (!$ids) { return false; } AuthRule::destroy($ids); @@ -76,8 +67,7 @@ class Menu public static function enable($name) { $ids = self::getAuthRuleIdsByName($name); - if (!$ids) - { + if (!$ids) { return false; } AuthRule::where('id', 'in', $ids)->update(['status' => 'normal']); @@ -92,8 +82,7 @@ class Menu public static function disable($name) { $ids = self::getAuthRuleIdsByName($name); - if (!$ids) - { + if (!$ids) { return false; } AuthRule::where('id', 'in', $ids)->update(['status' => 'hidden']); @@ -108,14 +97,12 @@ class Menu public static function export($name) { $ids = self::getAuthRuleIdsByName($name); - if (!$ids) - { + if (!$ids) { return []; } $menuList = []; $menu = AuthRule::getByName($name); - if ($menu) - { + if ($menu) { $ruleList = collection(AuthRule::where('id', 'in', $ids)->select())->toArray(); $menuList = Tree::instance()->init($ruleList)->getTreeArray($menu['id']); } @@ -131,8 +118,7 @@ class Menu { $ids = []; $menu = AuthRule::getByName($name); - if ($menu) - { + if ($menu) { // 必须将结果集转换为数组 $ruleList = collection(AuthRule::order('weigh', 'desc')->field('id,pid,name')->select())->toArray(); // 构造菜单数据 diff --git a/application/common/library/Sms.php b/application/common/library/Sms.php index 7204530a..56ec56d8 100644 --- a/application/common/library/Sms.php +++ b/application/common/library/Sms.php @@ -1,144 +1,133 @@ - $mobile, 'event' => $event]) - ->order('id', 'DESC') - ->find(); - Hook::listen('sms_get', $sms, null, true); - return $sms ? $sms : NULL; - } - - /** - * 发送验证码 - * - * @param int $mobile 手机号 - * @param int $code 验证码,为空时将自动生成4位数字 - * @param string $event 事件 - * @return boolean - */ - public static function send($mobile, $code = NULL, $event = 'default') - { - $code = is_null($code) ? mt_rand(1000, 9999) : $code; - $time = time(); - $ip = request()->ip(); - $sms = \app\common\model\Sms::create(['event' => $event, 'mobile' => $mobile, 'code' => $code, 'ip' => $ip, 'createtime' => $time]); - $result = Hook::listen('sms_send', $sms, null, true); - if (!$result) - { - $sms->delete(); - return FALSE; - } - return TRUE; - } - - /** - * 发送通知 - * - * @param mixed $mobile 手机号,多个以,分隔 - * @param string $msg 消息内容 - * @param string $template 消息模板 - * @return boolean - */ - public static function notice($mobile, $msg = '', $template = NULL) - { - $params = [ - 'mobile' => $mobile, - 'msg' => $msg, - 'template' => $template - ]; - $result = Hook::listen('sms_notice', $params, null, true); - return $result ? TRUE : FALSE; - } - - /** - * 校验验证码 - * - * @param int $mobile 手机号 - * @param int $code 验证码 - * @param string $event 事件 - * @return boolean - */ - public static function check($mobile, $code, $event = 'default') - { - $time = time() - self::$expire; - $sms = \app\common\model\Sms::where(['mobile' => $mobile, 'event' => $event]) - ->order('id', 'DESC') - ->find(); - if ($sms) - { - if ($sms['createtime'] > $time && $sms['times'] <= self::$maxCheckNums) - { - $correct = $code == $sms['code']; - if (!$correct) - { - $sms->times = $sms->times + 1; - $sms->save(); - return FALSE; - } - else - { - $result = Hook::listen('sms_check', $sms, null, true); - return $result; - } - } - else - { - // 过期则清空该手机验证码 - self::flush($mobile, $event); - return FALSE; - } - } - else - { - return FALSE; - } - } - - /** - * 清空指定手机号验证码 - * - * @param int $mobile 手机号 - * @param string $event 事件 - * @return boolean - */ - public static function flush($mobile, $event = 'default') - { - \app\common\model\Sms:: - where(['mobile' => $mobile, 'event' => $event]) - ->delete(); - Hook::listen('sms_flush'); - return TRUE; - } - -} + $mobile, 'event' => $event]) + ->order('id', 'DESC') + ->find(); + Hook::listen('sms_get', $sms, null, true); + return $sms ? $sms : null; + } + + /** + * 发送验证码 + * + * @param int $mobile 手机号 + * @param int $code 验证码,为空时将自动生成4位数字 + * @param string $event 事件 + * @return boolean + */ + public static function send($mobile, $code = null, $event = 'default') + { + $code = is_null($code) ? mt_rand(1000, 9999) : $code; + $time = time(); + $ip = request()->ip(); + $sms = \app\common\model\Sms::create(['event' => $event, 'mobile' => $mobile, 'code' => $code, 'ip' => $ip, 'createtime' => $time]); + $result = Hook::listen('sms_send', $sms, null, true); + if (!$result) { + $sms->delete(); + return false; + } + return true; + } + + /** + * 发送通知 + * + * @param mixed $mobile 手机号,多个以,分隔 + * @param string $msg 消息内容 + * @param string $template 消息模板 + * @return boolean + */ + public static function notice($mobile, $msg = '', $template = null) + { + $params = [ + 'mobile' => $mobile, + 'msg' => $msg, + 'template' => $template + ]; + $result = Hook::listen('sms_notice', $params, null, true); + return $result ? true : false; + } + + /** + * 校验验证码 + * + * @param int $mobile 手机号 + * @param int $code 验证码 + * @param string $event 事件 + * @return boolean + */ + public static function check($mobile, $code, $event = 'default') + { + $time = time() - self::$expire; + $sms = \app\common\model\Sms::where(['mobile' => $mobile, 'event' => $event]) + ->order('id', 'DESC') + ->find(); + if ($sms) { + if ($sms['createtime'] > $time && $sms['times'] <= self::$maxCheckNums) { + $correct = $code == $sms['code']; + if (!$correct) { + $sms->times = $sms->times + 1; + $sms->save(); + return false; + } else { + $result = Hook::listen('sms_check', $sms, null, true); + return $result; + } + } else { + // 过期则清空该手机验证码 + self::flush($mobile, $event); + return false; + } + } else { + return false; + } + } + + /** + * 清空指定手机号验证码 + * + * @param int $mobile 手机号 + * @param string $event 事件 + * @return boolean + */ + public static function flush($mobile, $event = 'default') + { + \app\common\model\Sms:: + where(['mobile' => $mobile, 'event' => $event]) + ->delete(); + Hook::listen('sms_flush'); + return true; + } +} diff --git a/application/common/library/Token.php b/application/common/library/Token.php index 2751f644..e9cd5e35 100644 --- a/application/common/library/Token.php +++ b/application/common/library/Token.php @@ -25,8 +25,8 @@ class Token /** * 连接Token驱动 * @access public - * @param array $options 配置数组 - * @param bool|string $name Token连接标识 true 强制重新连接 + * @param array $options 配置数组 + * @param bool|string $name Token连接标识 true 强制重新连接 * @return Driver */ public static function connect(array $options = [], $name = false) @@ -102,8 +102,8 @@ class Token /** * 读取Token * @access public - * @param string $token Token标识 - * @param mixed $default 默认值 + * @param string $token Token标识 + * @param mixed $default 默认值 * @return mixed */ public static function get($token, $default = false) @@ -114,9 +114,9 @@ class Token /** * 写入Token * @access public - * @param string $token Token标识 - * @param mixed $user_id 存储数据 - * @param int|null $expire 有效时间 0为永久 + * @param string $token Token标识 + * @param mixed $user_id 存储数据 + * @param int|null $expire 有效时间 0为永久 * @return boolean */ public static function set($token, $user_id, $expire = null) diff --git a/application/common/library/token/Driver.php b/application/common/library/token/Driver.php index 7e2dfa77..03463024 100644 --- a/application/common/library/token/Driver.php +++ b/application/common/library/token/Driver.php @@ -21,9 +21,9 @@ abstract class Driver /** * 存储Token - * @param string $token Token - * @param int $user_id 会员ID - * @param int $expire 过期时长,0表示无限,单位秒 + * @param string $token Token + * @param int $user_id 会员ID + * @param int $expire 过期时长,0表示无限,单位秒 * @return bool */ abstract function set($token, $user_id, $expire = 0); @@ -37,8 +37,8 @@ abstract class Driver /** * 判断Token是否可用 - * @param string $token Token - * @param int $user_id 会员ID + * @param string $token Token + * @param int $user_id 会员ID * @return boolean */ abstract function check($token, $user_id); diff --git a/application/common/library/token/driver/Mysql.php b/application/common/library/token/driver/Mysql.php index 5884d836..3859e260 100644 --- a/application/common/library/token/driver/Mysql.php +++ b/application/common/library/token/driver/Mysql.php @@ -40,9 +40,9 @@ class Mysql extends Driver /** * 存储Token - * @param string $token Token - * @param int $user_id 会员ID - * @param int $expire 过期时长,0表示无限,单位秒 + * @param string $token Token + * @param int $user_id 会员ID + * @param int $expire 过期时长,0表示无限,单位秒 * @return bool */ public function set($token, $user_id, $expire = null) @@ -77,8 +77,8 @@ class Mysql extends Driver /** * 判断Token是否可用 - * @param string $token Token - * @param int $user_id 会员ID + * @param string $token Token + * @param int $user_id 会员ID * @return boolean */ public function check($token, $user_id) diff --git a/application/common/library/token/driver/Redis.php b/application/common/library/token/driver/Redis.php index 0f187eb4..0aa0caaa 100644 --- a/application/common/library/token/driver/Redis.php +++ b/application/common/library/token/driver/Redis.php @@ -75,9 +75,9 @@ class Redis extends Driver /** * 存储Token - * @param string $token Token - * @param int $user_id 会员ID - * @param int $expire 过期时长,0表示无限,单位秒 + * @param string $token Token + * @param int $user_id 会员ID + * @param int $expire 过期时长,0表示无限,单位秒 * @return bool */ public function set($token, $user_id, $expire = 0) @@ -123,8 +123,8 @@ class Redis extends Driver /** * 判断Token是否可用 - * @param string $token Token - * @param int $user_id 会员ID + * @param string $token Token + * @param int $user_id 会员ID * @return boolean */ public function check($token, $user_id) diff --git a/application/common/model/Category.php b/application/common/model/Category.php index 40e5701a..4adfd5d4 100644 --- a/application/common/model/Category.php +++ b/application/common/model/Category.php @@ -7,7 +7,7 @@ use think\Model; /** * 分类模型 */ -class Category Extends Model +class Category extends Model { // 开启自动写入时间戳字段 @@ -40,8 +40,7 @@ class Category Extends Model public static function getTypeList() { $typeList = config('site.categorytype'); - foreach ($typeList as $k => &$v) - { + foreach ($typeList as $k => &$v) { $v = __($v); } return $typeList; @@ -69,23 +68,20 @@ class Category Extends Model /** * 读取分类列表 - * @param string $type 指定类型 - * @param string $status 指定状态 + * @param string $type 指定类型 + * @param string $status 指定状态 * @return array */ - public static function getCategoryArray($type = NULL, $status = NULL) + public static function getCategoryArray($type = null, $status = null) { - $list = collection(self::where(function($query) use($type, $status) { - if (!is_null($type)) - { - $query->where('type', '=', $type); - } - if (!is_null($status)) - { - $query->where('status', '=', $status); - } - })->order('weigh', 'desc')->select())->toArray(); + $list = collection(self::where(function ($query) use ($type, $status) { + if (!is_null($type)) { + $query->where('type', '=', $type); + } + if (!is_null($status)) { + $query->where('status', '=', $status); + } + })->order('weigh', 'desc')->select())->toArray(); return $list; } - } diff --git a/application/common/model/Version.php b/application/common/model/Version.php index 2c72485d..56bcbca4 100644 --- a/application/common/model/Version.php +++ b/application/common/model/Version.php @@ -1,54 +1,50 @@ -cache('__version__')->order('weigh desc,id desc')->select(); - foreach ($versionlist as $k => $v) - { - // 版本正常且新版本号不等于验证的版本号且找到匹配的旧版本 - if ($v['status'] == 'normal' && $v['newversion'] !== $version && \fast\Version::check($version, $v['oldversion'])) - { - $updateversion = $v; - break; - } - } - if (isset($updateversion)) - { - $search = ['{version}', '{newversion}', '{downloadurl}', '{url}', '{packagesize}']; - $replace = [$version, $updateversion['newversion'], $updateversion['downloadurl'], $updateversion['downloadurl'], $updateversion['packagesize']]; - $upgradetext = str_replace($search, $replace, $updateversion['content']); - return [ - "enforce" => $updateversion['enforce'], - "version" => $version, - "newversion" => $updateversion['newversion'], - "downloadurl" => $updateversion['downloadurl'], - "packagesize" => $updateversion['packagesize'], - "upgradetext" => $upgradetext - ]; - } - return NULL; - } - -} +cache('__version__')->order('weigh desc,id desc')->select(); + foreach ($versionlist as $k => $v) { + // 版本正常且新版本号不等于验证的版本号且找到匹配的旧版本 + if ($v['status'] == 'normal' && $v['newversion'] !== $version && \fast\Version::check($version, $v['oldversion'])) { + $updateversion = $v; + break; + } + } + if (isset($updateversion)) { + $search = ['{version}', '{newversion}', '{downloadurl}', '{url}', '{packagesize}']; + $replace = [$version, $updateversion['newversion'], $updateversion['downloadurl'], $updateversion['downloadurl'], $updateversion['packagesize']]; + $upgradetext = str_replace($search, $replace, $updateversion['content']); + return [ + "enforce" => $updateversion['enforce'], + "version" => $version, + "newversion" => $updateversion['newversion'], + "downloadurl" => $updateversion['downloadurl'], + "packagesize" => $updateversion['packagesize'], + "upgradetext" => $upgradetext + ]; + } + return null; + } +} diff --git a/application/config.php b/application/config.php index 03cfc423..25a7901d 100755 --- a/application/config.php +++ b/application/config.php @@ -272,7 +272,7 @@ return [ //自动检测更新 'checkupdate' => false, //版本号 - 'version' => '1.0.0.20190318_beta', + 'version' => '1.0.0.20190407_beta', //API接口地址 'api_url' => 'https://api.fastadmin.net', ], diff --git a/application/index/controller/Index.php b/application/index/controller/Index.php index ba5aaf4d..e72ff83a 100755 --- a/application/index/controller/Index.php +++ b/application/index/controller/Index.php @@ -12,11 +12,6 @@ class Index extends Frontend protected $noNeedRight = '*'; protected $layout = ''; - public function _initialize() - { - parent::_initialize(); - } - public function index() { return $this->view->fetch(); diff --git a/application/index/view/layout/default.html b/application/index/view/layout/default.html index 762a83d2..462ff090 100644 --- a/application/index/view/layout/default.html +++ b/application/index/view/layout/default.html @@ -61,7 +61,7 @@ {include file="common/script" /} diff --git a/application/index/view/user/login.html b/application/index/view/user/login.html index f2a2c281..6184b730 100755 --- a/application/index/view/user/login.html +++ b/application/index/view/user/login.html @@ -36,7 +36,7 @@