Index.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. <?php
  2. /**
  3. * ----------------------------------------------------------------------------
  4. * 行到水穷处,坐看云起时
  5. * 开发软件,找贵阳云起信息科技,官网地址:https://www.56q7.com/
  6. * ----------------------------------------------------------------------------
  7. * Author: 老成
  8. * email:85556713@qq.com
  9. */
  10. declare (strict_types = 1);
  11. namespace app\admin\controller;
  12. use app\common\controller\Backend;
  13. use app\common\model\Admin;
  14. use app\common\model\Qrcode;
  15. use think\annotation\route\Route;
  16. use think\captcha\facade\Captcha;
  17. use think\facade\Session;
  18. class Index extends Backend
  19. {
  20. protected $noNeedLogin = ['login','captcha','qrcodeLogin'];
  21. protected $noNeedRight = ['index','logout','platform','changeTheme'];
  22. #[Route('GET','index')]
  23. public function index()
  24. {
  25. $referer=Session::pull('referer');
  26. if($referer){
  27. Session::save();
  28. }
  29. list($platform,$menulist, $selected, $referer) = $this->auth->getSidebar($referer);
  30. $this->assign('site',site_config('basic'));
  31. $this->assign('platform',$platform);
  32. $this->assign('menulist',$menulist);
  33. $this->assign('selected',$selected);
  34. $this->assign('referer',$referer);
  35. return $this->fetch('',[],false);
  36. }
  37. #[Route('POST','change-theme')]
  38. public function changeTheme()
  39. {
  40. $key=$this->request->post('key');
  41. $value=$this->request->post('value');
  42. if($value==='true'){
  43. $value=true;
  44. }
  45. if($value==='false'){
  46. $value=false;
  47. }
  48. $element_ui=Admin::where('id',$this->auth->id)->value('element_ui');
  49. if($element_ui){
  50. $element_ui=json_decode($element_ui,true);
  51. }else{
  52. $element_ui=[];
  53. }
  54. $element_ui[$key]=$value;
  55. $element_ui=json_encode($element_ui);
  56. Admin::update(['element_ui'=>$element_ui],['id'=>$this->auth->id]);
  57. Session::set('admin.element_ui',$element_ui);
  58. Session::save();
  59. $this->success();
  60. }
  61. #[Route('GET','captcha')]
  62. public function captcha()
  63. {
  64. return Captcha::create();
  65. }
  66. #[Route('GET','platform')]
  67. public function platform()
  68. {
  69. $id=$this->request->get('id');
  70. Session::set('admin.platform_id',$id);
  71. Session::save();
  72. $this->success();
  73. }
  74. #[Route('GET','qrcodeLogin')]
  75. public function qrcodeLogin()
  76. {
  77. $token=$this->request->get('token');
  78. $admin_id=$this->request->get('admin_id');
  79. $adminlist=[];
  80. if($this->auth->loginByThird($token,$admin_id,$adminlist)){
  81. $this->success(__('登陆成功'));
  82. }
  83. $this->error('',$adminlist);
  84. }
  85. #[Route('POST,GET','login')]
  86. public function login()
  87. {
  88. if(!$this->request->isPost()){
  89. if($this->auth->isLogin()){
  90. $alis=get_module_alis();
  91. return redirect(request()->domain().'/'.$alis.'/index');
  92. }
  93. $thirdLogin=addons_installed('uniapp') && site_config("uniapp.scan_login");
  94. if($thirdLogin){
  95. $config=[
  96. 'appid'=>site_config("uniapp.mpapp_id"),
  97. 'appsecret'=>site_config("uniapp.mpapp_secret"),
  98. ];
  99. $qrcode=Qrcode::createQrcode(Qrcode::TYPE('管理员扫码登录'),token(),5*60);
  100. $wechat=new \WeChat\Qrcode($config);
  101. $ticket = $wechat->create($qrcode->id)['ticket'];
  102. $url=$wechat->url($ticket);
  103. $this->assign('qrcode',$url);
  104. }
  105. $this->assign('thirdLogin',$thirdLogin);
  106. $this->assign('logo',site_config("basic.logo"));
  107. $this->assign('sitename',site_config("basic.sitename"));
  108. $this->assign('login_captcha',config('yunqi.login_captcha'));
  109. return $this->fetch();
  110. }
  111. $username = $this->request->post('username');
  112. $password = $this->request->post('password');
  113. $captcha = $this->request->post('captcha');
  114. if(config('yunqi.login_captcha') && !captcha_check($captcha)){
  115. $this->error(__('验证码错误'),0);
  116. }
  117. try{
  118. $this->auth->login($username,$password);
  119. Session::delete('captcha');
  120. Session::save();
  121. }catch (\Exception $e){
  122. $this->error($e->getMessage(),1);
  123. }
  124. $this->success(__('登陆成功'));
  125. }
  126. #[Route('GET','logout')]
  127. public function logout()
  128. {
  129. $alis=get_module_alis();
  130. $this->auth->logout();
  131. $url=request()->domain().'/'.$alis.'/login';
  132. return redirect($url);
  133. }
  134. }