Index.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. <?php
  2. namespace app\admin\controller;
  3. use think\facade\View;
  4. use think\facade\Lang;
  5. use think\facade\Cache;
  6. /**
  7. * 控制器
  8. */
  9. class Index extends AdminControl
  10. {
  11. public function initialize()
  12. {
  13. parent::initialize();
  14. Lang::load(base_path() . 'admin/lang/' . config('lang.default_lang') . '/index.lang.php');
  15. }
  16. public function index()
  17. {
  18. View::assign('admin_info', $this->getAdminInfo());
  19. return View::fetch();
  20. }
  21. /**
  22. * 修改密码
  23. */
  24. public function modifypw()
  25. {
  26. if (request()->isPost()) {
  27. $new_pw = trim(input('post.new_pw'));
  28. $new_pw2 = trim(input('post.new_pw2'));
  29. $old_pw = trim(input('post.old_pw'));
  30. if ($new_pw !== $new_pw2) {
  31. $this->error(lang('index_modifypw_repeat_error'));
  32. }
  33. $admininfo = $this->getAdminInfo();
  34. //查询管理员信息
  35. $admin_model = model('admin');
  36. $admininfo = $admin_model->getOneAdmin(array('admin_id' => $admininfo['admin_id']));
  37. if (!is_array($admininfo) || count($admininfo) <= 0) {
  38. $this->error(lang('index_modifypw_admin_error'));
  39. }
  40. //旧密码是否正确
  41. if ($admininfo['admin_password'] != md5($old_pw)) {
  42. $this->error(lang('index_modifypw_oldpw_error'));
  43. }
  44. $new_pw = md5($new_pw);
  45. $result = $admin_model->editAdmin(array('admin_password' => $new_pw), $admininfo['admin_id']);
  46. if ($result && checkInputPassword($admininfo)) {
  47. session(null);
  48. echo "<script>parent.location.href='" . (string)url('Login/index') . "'</script>";
  49. } else {
  50. $this->error(lang('index_modifypw_fail'));
  51. }
  52. } else {
  53. return View::fetch();
  54. }
  55. }
  56. /**
  57. * 删除缓存
  58. */
  59. function clear()
  60. {
  61. $this->delCacheFile('admin/temp');
  62. $this->delCacheFile('admin/cache');
  63. $this->delCacheFile('home/temp');
  64. $this->delCacheFile('home/cache');
  65. $this->delCacheFile('api/temp');
  66. $this->delCacheFile('api/cache');
  67. Cache::clear();
  68. ds_json_encode(10000, lang('ds_common_op_succ'));
  69. exit();
  70. }
  71. /**
  72. * 删除缓存目录下的文件或子目录文件
  73. *
  74. * @param string $dir 目录名或文件名
  75. * @return boolean
  76. */
  77. function delCacheFile($dir)
  78. {
  79. //防止删除cache以外的文件
  80. if (strpos($dir, '..') !== false)
  81. return false;
  82. $path = root_path() . 'runtime/' . $dir;
  83. if (is_dir($path)) {
  84. $file_list = array();
  85. read_file_list($path, $file_list);
  86. if (!empty($file_list)) {
  87. foreach ($file_list as $v) {
  88. if (basename($v) != 'index.html')
  89. @unlink($v);
  90. }
  91. }
  92. } else {
  93. if (basename($path) != 'index.html')
  94. @unlink($path);
  95. }
  96. return true;
  97. }
  98. }