LoginSetController.php 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: CGOD
  5. * Date: 2020/1/7
  6. * Time: 9:30
  7. */
  8. namespace app\platform\modules\system\controllers;
  9. use app\platform\controllers\BaseController;
  10. use app\platform\modules\system\models\SystemSetting;
  11. use app\platform\modules\system\models\WhiteList;
  12. use app\platform\modules\user\models\AdminUser;
  13. class LoginSetController extends BaseController
  14. {
  15. public function index()
  16. {
  17. $set_data = request()->setdata;
  18. $loginset = SystemSetting::settingLoad('loginset', 'system_loginset');
  19. if ($set_data) {
  20. $pwd_mark = false;//为了刷新修改密码时间
  21. $loginset = unserialize(app('SystemSetting')->get('loginset')['value']);//拒绝缓存
  22. if($loginset['force_change_pwd'] != 1)
  23. {
  24. $pwd_mark = true;
  25. }
  26. $site = SystemSetting::settingSave($set_data, 'loginset', 'system_loginset');
  27. if ($site) {
  28. if($set_data['force_change_pwd'] == 1 && $pwd_mark)
  29. {
  30. AdminUser::where('uid','!=',1)->where('deleted_at',null)->update(['change_password_at' => time()]);
  31. }
  32. return $this->successJson('成功', '');
  33. } else {
  34. return $this->errorJson('失败', '');
  35. }
  36. }
  37. if ($loginset) {
  38. $loginset['white_list_verify'] = $loginset['white_list_verify'] ? : "0";
  39. }
  40. return $this->successJson('成功', $loginset?:[]);
  41. }
  42. public function whiteList()
  43. {
  44. $data = WhiteList::getWhite(request()->search)->paginate(20);
  45. return $this->successJson('成功', $data);
  46. }
  47. public function addWhiteList()
  48. {
  49. try {
  50. $res = WhiteList::addIP(request()->white_list);
  51. if (!$res) {
  52. throw new \Exception('添加失败');
  53. }
  54. return $this->successJson('成功');
  55. } catch (\Exception $e) {
  56. return $this->errorJson($e->getMessage());
  57. }
  58. }
  59. public function editWhiteList()
  60. {
  61. try {
  62. $res = WhiteList::editIP(request()->id,request()->edit);
  63. if (!$res) {
  64. throw new \Exception('编辑失败');
  65. }
  66. return $this->successJson('成功');
  67. } catch (\Exception $e) {
  68. return $this->errorJson($e->getMessage());
  69. }
  70. }
  71. public function delWhiteList()
  72. {
  73. try {
  74. $res = WhiteList::delIP(request()->id);
  75. if (!$res) {
  76. throw new \Exception('删除失败或已删除');
  77. }
  78. return $this->successJson('成功');
  79. } catch (\Exception $e) {
  80. return $this->errorJson($e->getMessage());
  81. }
  82. }
  83. }