| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124 |
- <?php
- namespace app\user\controller;
- use think\Lang;
- use think\Cache;
- class Index extends UserControl
- {
- public function _initialize()
- {
- parent::_initialize();
- Lang::load(APP_PATH . 'admin/lang/' . config('default_lang') . '/index.lang.php');
- }
- public function index()
- {
- // $allpower = $this->qxhans();
- // $this->assign('allpower',$allpower);
- $this->assign('user_info', $this->getAdminInfo());
- return $this->fetch();
- }
- /**
- * 修改密码
- */
- public function modifypw()
- {
- if (request()->isPost()) {
- $new_pw = trim(input('post.new_pw'));
- $new_pw2 = trim(input('post.new_pw2'));
- $old_pw = trim(input('post.old_pw'));
- if ($new_pw !== $new_pw2) {
- $this->error(lang('index_modifypw_repeat_error'));
- }
- $admininfo = $this->getAdminInfo();
- //查询管理员信息
- $admin_model = model('admin');
- $admininfo = $admin_model->getOneAdmin(array('admin_id' => $admininfo['admin_id']));
- if (!is_array($admininfo) || count($admininfo) <= 0) {
- $this->error(lang('index_modifypw_admin_error'));
- }
- //旧密码是否正确
- if ($admininfo['admin_password'] != md5($old_pw)) {
- $this->error(lang('index_modifypw_oldpw_error'));
- }
- $new_pw = md5($new_pw);
- $result = $admin_model->editAdmin(array('admin_id' => $admininfo['admin_id']), array('admin_password' => $new_pw));
- if ($result) {
- session(null);
- dsLayerOpenSuccess(lang('index_modifypw_succ'));
- } else {
- $this->error(lang('index_modifypw_fail'));
- }
- } else {
- $this->setAdminCurItem('modifypw');
- return $this->fetch();
- }
- }
- private function _mysql_version()
- {
- $version = db()->query("select version() as ver");
- return $version[0]['ver'];
- }
- /**
- * 修改当前语言
- */
- public function setLanguageCookie()
- {
- $language = input('param.language');
- if ($language == config('default_lang')) {
- $this->error(\lang('ds_language_repetition'), url('Index/index'));
- exit();
- }
- setcookie("ds_admin_lang", $language, 0, '/');
- $this->success(\lang('ds_language_switching'), url('Index/index'));
- exit();
- }
- /**
- * 删除缓存
- */
- function clear()
- {
- $this->delCacheFile('temp');
- $this->delCacheFile('cache');
- Cache::clear();
- ds_json_encode(10000, lang('eliminate_succ'));
- exit();
- }
- /**
- * 删除缓存目录下的文件或子目录文件
- *
- * @param string $dir 目录名或文件名
- * @return boolean
- */
- function delCacheFile($dir)
- {
- //防止删除cache以外的文件
- if (strpos($dir, '..') !== false)
- return false;
- $path = RUNTIME_PATH . '/' . $dir;
- if (is_dir($path)) {
- $file_list = array();
- read_file_list($path, $file_list);
- if (!empty($file_list)) {
- foreach ($file_list as $v) {
- if (basename($v) != 'index.html')
- @unlink($v);
- }
- }
- } else {
- if (basename($path) != 'index.html')
- @unlink($path);
- }
- return true;
- }
- }
|