Index.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. <?php
  2. namespace app\user\controller;
  3. use think\Lang;
  4. use think\Cache;
  5. class Index extends UserControl
  6. {
  7. public function _initialize()
  8. {
  9. parent::_initialize();
  10. Lang::load(APP_PATH . 'admin/lang/' . config('default_lang') . '/index.lang.php');
  11. }
  12. public function index()
  13. {
  14. $allpower = $this->qxhans();
  15. $this->assign('allpower',$allpower);
  16. $this->assign('admin_info', $this->getAdminInfo());
  17. return $this->fetch();
  18. }
  19. /**
  20. * 修改密码
  21. */
  22. public function modifypw()
  23. {
  24. if (request()->isPost()) {
  25. $new_pw = trim(input('post.new_pw'));
  26. $new_pw2 = trim(input('post.new_pw2'));
  27. $old_pw = trim(input('post.old_pw'));
  28. if ($new_pw !== $new_pw2) {
  29. $this->error(lang('index_modifypw_repeat_error'));
  30. }
  31. $admininfo = $this->getAdminInfo();
  32. //查询管理员信息
  33. $admin_model = model('admin');
  34. $admininfo = $admin_model->getOneAdmin(array('admin_id' => $admininfo['admin_id']));
  35. if (!is_array($admininfo) || count($admininfo) <= 0) {
  36. $this->error(lang('index_modifypw_admin_error'));
  37. }
  38. //旧密码是否正确
  39. if ($admininfo['admin_password'] != md5($old_pw)) {
  40. $this->error(lang('index_modifypw_oldpw_error'));
  41. }
  42. $new_pw = md5($new_pw);
  43. $result = $admin_model->editAdmin(array('admin_id' => $admininfo['admin_id']), array('admin_password' => $new_pw));
  44. if ($result) {
  45. session(null);
  46. dsLayerOpenSuccess(lang('index_modifypw_succ'));
  47. } else {
  48. $this->error(lang('index_modifypw_fail'));
  49. }
  50. } else {
  51. $this->setAdminCurItem('modifypw');
  52. return $this->fetch();
  53. }
  54. }
  55. private function _mysql_version()
  56. {
  57. $version = db()->query("select version() as ver");
  58. return $version[0]['ver'];
  59. }
  60. /**
  61. * 修改当前语言
  62. */
  63. public function setLanguageCookie()
  64. {
  65. $language = input('param.language');
  66. if ($language == config('default_lang')) {
  67. $this->error(\lang('ds_language_repetition'), url('Index/index'));
  68. exit();
  69. }
  70. setcookie("ds_admin_lang", $language, 0, '/');
  71. $this->success(\lang('ds_language_switching'), url('Index/index'));
  72. exit();
  73. }
  74. /**
  75. * 删除缓存
  76. */
  77. function clear()
  78. {
  79. $this->delCacheFile('temp');
  80. $this->delCacheFile('cache');
  81. Cache::clear();
  82. ds_json_encode(10000, lang('eliminate_succ'));
  83. exit();
  84. }
  85. /**
  86. * 删除缓存目录下的文件或子目录文件
  87. *
  88. * @param string $dir 目录名或文件名
  89. * @return boolean
  90. */
  91. function delCacheFile($dir)
  92. {
  93. //防止删除cache以外的文件
  94. if (strpos($dir, '..') !== false)
  95. return false;
  96. $path = RUNTIME_PATH . '/' . $dir;
  97. if (is_dir($path)) {
  98. $file_list = array();
  99. read_file_list($path, $file_list);
  100. if (!empty($file_list)) {
  101. foreach ($file_list as $v) {
  102. if (basename($v) != 'index.html')
  103. @unlink($v);
  104. }
  105. }
  106. } else {
  107. if (basename($path) != 'index.html')
  108. @unlink($path);
  109. }
  110. return true;
  111. }
  112. }