Index.php 3.6 KB

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