123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165 |
- <?php
- namespace app\admin\controller;
- use think\facade\Cache;
- use think\facade\Env;
- use think\helper\Hash;
- use think\Db;
- use app\common\builder\ZBuilder;
- use app\user\model\User as UserModel;
- class Index extends Admin
- {
-
- public function index()
- {
- $admin_pass = Db::name('admin_user')->where('id', 1)->value('password');
- if (UID == 1 && $admin_pass && Hash::check('admin', $admin_pass)) {
- $this->assign('default_pass', 1);
- }
- return $this->fetch();
- }
-
- public function wipeCache()
- {
- $wipe_cache_type = config('wipe_cache_type');
- if (!empty($wipe_cache_type)) {
- foreach ($wipe_cache_type as $item) {
- switch ($item) {
- case 'TEMP_PATH':
- array_map('unlink', glob(Env::get('runtime_path'). 'temp/*.*'));
- break;
- case 'LOG_PATH':
- $dirs = (array) glob(Env::get('runtime_path') . 'log/*');
- foreach ($dirs as $dir) {
- array_map('unlink', glob($dir . '/*.log'));
- }
- array_map('rmdir', $dirs);
- break;
- case 'CACHE_PATH':
- array_map('unlink', glob(Env::get('runtime_path'). 'cache/*.*'));
- break;
- }
- }
- Cache::clear();
- $this->success('清空成功');
- } else {
- $this->error('请在系统设置中选择需要清除的缓存类型');
- }
- }
-
- public function profile()
- {
-
- if ($this->request->isPost()) {
- $data = $this->request->post();
- $data['nickname'] == '' && $this->error('昵称不能为空');
- $data['id'] = UID;
-
- if ($data['password'] == '') {
- unset($data['password']);
- }
- $UserModel = new UserModel();
- if ($user = $UserModel->allowField(['nickname', 'email', 'password', 'mobile', 'avatar'])->update($data)) {
-
- action_log('user_edit', 'admin_user', UID, UID, get_nickname(UID));
- $this->success('编辑成功');
- } else {
- $this->error('编辑失败');
- }
- }
-
- $info = UserModel::where('id', UID)->field('password', true)->find();
-
- return ZBuilder::make('form')
- ->addFormItems([
- ['static', 'username', '用户名', '不可更改'],
- ['text', 'nickname', '昵称', '可以是中文'],
- ['text', 'email', '邮箱', ''],
- ['password', 'password', '密码', '必填,6-20位'],
- ['text', 'mobile', '手机号'],
- ['image', 'avatar', '头像']
- ])
- ->setFormData($info)
- ->fetch();
- }
-
- public function checkUpdate()
- {
- $params = config('dolphin.');
- $params['domain'] = request()->domain();
- $params['website'] = config('web_site_title');
- $params['ip'] = $_SERVER['SERVER_ADDR'];
- $params['php_os'] = PHP_OS;
- $params['php_version'] = PHP_VERSION;
- $params['mysql_version'] = db()->query('select version() as version')[0]['version'];
- $params['server_software'] = $_SERVER['SERVER_SOFTWARE'];
- $params = http_build_query($params);
- $opts = [
- CURLOPT_TIMEOUT => 20,
- CURLOPT_RETURNTRANSFER => true,
- CURLOPT_URL => config('dolphin.product_update'),
- CURLOPT_USERAGENT => $_SERVER['HTTP_USER_AGENT'],
- CURLOPT_POST => 1,
- CURLOPT_POSTFIELDS => $params
- ];
-
- $ch = curl_init();
- curl_setopt_array($ch, $opts);
- $data = curl_exec($ch);
- curl_close($ch);
- $result = json_decode($data, true);
- if ($result['code'] == 1) {
- return json([
- 'update' => '<a class="badge badge-primary" href="http://www.dolphinphp.com/download" target="_blank">有新版本:'.$result["version"].'</a>',
- 'auth' => $result['auth']
- ]);
- } else {
- return json([
- 'update' => '',
- 'auth' => $result['auth']
- ]);
- }
- }
- }
|