IndexLoginBusiness.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <?php
  2. namespace addons\csmadmin\library\business;
  3. use addons\csmadmin\library\CsmContants;
  4. use addons\csmadmin\library\service\AdminService;
  5. use think\Request;
  6. use think\Session;
  7. use addons\csmadmin\library\CsmTree;
  8. /**
  9. *
  10. * @author Chensm
  11. *
  12. */
  13. class IndexLoginBusiness extends ABusiness
  14. {
  15. public function moduleInit($request)
  16. {}
  17. /**
  18. * 根据根据用户id,和角色对应的组织&人员,重新计算authgroup
  19. */
  20. private function reCalcAdminAuthgroup($userid)
  21. {
  22. }
  23. public function viewFilter($request)
  24. {
  25. $sr = new Ibusinessmodel();
  26. $sr->trigger = true;
  27. $sr->triggername = "index_login";
  28. $config = get_addon_config(CsmContants::$ADDONS);
  29. $sr->jsondata = json_encode([
  30. 'canadminfindpassword' => $config['canadminfindpassword'],
  31. 'canadminregister' => $config['canadminregister']
  32. ]);
  33. return $sr;
  34. }
  35. public function actionBegin($request)
  36. {
  37. // 由于登录需要判断首次时间,而在afterlogin后首次登录状态被覆盖
  38. $config = get_addon_config(CsmContants::$ADDONS);
  39. $needupdatepsdwhenfirstlogin = $config["needupdatepsdwhenfirstlogin"];
  40. if ($needupdatepsdwhenfirstlogin == 'Y') {
  41. $username = $request->post('username');
  42. $service = new AdminService();
  43. $row = $service->getRowByUsername($username);
  44. if ($row != null) {
  45. Session::set("csmadmin_lastlogintime", $row->logintime);
  46. } else {
  47. Session::set("csmadmin_lastlogintime", time());
  48. }
  49. }
  50. }
  51. public function appEnd($response)
  52. {
  53. $request = Request::instance();
  54. if ($request->isAjax()) {
  55. $this->ajaxEnd($request);
  56. }
  57. }
  58. private function ajaxEnd($request)
  59. {
  60. $user = $this->getuserinfo();
  61. // 按部门管理,就需要根据角色重新授权
  62. $config = get_addon_config(CsmContants::$ADDONS);
  63. if ($config['canadmindepratmng'] == 'Y') {
  64. if ($user != null && $user['id']!=null){
  65. $this->reCalcAdminAuthgroup($user['id']);
  66. }
  67. }
  68. }
  69. }