Csmadminlogin.php 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. <?php
  2. namespace app\admin\controller\csmadmin;
  3. use addons\csmadmin\library\CsmBackend;
  4. use addons\csmadmin\library\CsmContants;
  5. use addons\csmadmin\library\CsmadminUtils;
  6. use addons\csmadmin\library\WxUtils;
  7. use addons\csmadmin\library\service\AdminService;
  8. use think\Session;
  9. /**
  10. * http://127.0.0.1/fastadmin_plugin_csmmeet/public/q3HJDu2RgE.php/csmadmin/csmadminlogin/dobyemail
  11. */
  12. class Csmadminlogin extends CsmBackend
  13. {
  14. protected $noNeedLogin = [
  15. '*'
  16. ];
  17. protected $noNeedRight = [
  18. '*'
  19. ];
  20. protected $layout = '';
  21. protected $ulmenu;
  22. public function _initialize()
  23. {
  24. parent::_initialize();
  25. $url = $this->request->get('url');
  26. if ($this->auth->isLogin()) {
  27. $this->success(__("You've logged in, do not login again"), $url);
  28. }
  29. $getparam = ($url == null || $url == '') ? '?1=1' : '?url=' . urlencode($url);
  30. $this->ulmenu = [];
  31. $this->ulmenu[] = [
  32. 'name' => '邮件短信',
  33. 'code' => 'dobyemail',
  34. 'url' => $this->request->baseFile().'/csmadmin/csmadminlogin/dobyemail' . $getparam
  35. ];
  36. $config = get_addon_config(CsmContants::$ADDONS);
  37. //v2.1.3 适配fa.1.3.4增加手机号码调整
  38. $this->ulmenu[] = [
  39. 'name' => '手机短信',
  40. 'code' => 'dobymobile',
  41. 'url' => $this->request->baseFile().'/csmadmin/csmadminlogin/dobymobile' . $getparam
  42. ];
  43. if ($config['haswxfield'] == 'Y') {
  44. $this->ulmenu[] = [
  45. 'name' => '微信登录',
  46. 'code' => 'dobywx',
  47. 'url' => $this->request->baseFile().'/csmadmin/csmadminlogin/dobywx' . $getparam
  48. ];
  49. }
  50. //v1.2.1 增加钉钉登录
  51. $plugin = get_addon_info('csmding');
  52. if ($plugin && $plugin['state']) {
  53. $getparam .= '&urlmenu='.urlencode(json_encode($this->ulmenu));
  54. $this->ulmenu[] = [
  55. 'name' => '钉钉登录',
  56. 'code' => 'dobydd',
  57. 'url' => $this->request->baseFile().'/csmding/ddlogin/dobydd' . $getparam
  58. ];
  59. }
  60. $this->assign('ulmenu', $this->ulmenu);
  61. $this->assign('title', "用户登录");
  62. $this->view->engine->layout('csmadmin/layout/default');
  63. }
  64. public function dobyemail()
  65. {
  66. if ($this->request->isPost()) {
  67. $event = "通过邮箱登录验证码";
  68. $ccode = $this->csmreq("ccode", true);
  69. $email = $this->csmreq("email", true);
  70. // 校验验证码
  71. $sendccode = Session::get(CsmadminUtils::getSessionKey($email, $event));
  72. if ($sendccode != $ccode) {
  73. $this->error('验证码错误!');
  74. }
  75. $service = new AdminService();
  76. $row = $service->getRowByEmail($email);
  77. if ($row) {
  78. $service->directLogin($row);
  79. $this->success();
  80. } else {
  81. $this->error('帐号不存在,请重新登录!');
  82. }
  83. }
  84. return $this->view->fetch();
  85. }
  86. public function dobymobile()
  87. {
  88. if ($this->request->isPost()) {
  89. $event = "通过手机登录验证码";
  90. $ccode = $this->csmreq("ccode", true);
  91. $mobile = $this->csmreq("mobile", true);
  92. // 校验验证码
  93. $sendccode = Session::get(CsmadminUtils::getSessionKey($mobile, $event));
  94. if ($sendccode != $ccode) {
  95. $this->error('验证码错误!');
  96. }
  97. $service = new AdminService();
  98. $row = $service->getRowByMobile($mobile);
  99. if ($row) {
  100. $service->directLogin($row);
  101. $this->success();
  102. } else {
  103. $this->error('帐号不存在,请重新登录!');
  104. }
  105. }
  106. return $this->view->fetch();
  107. }
  108. public function dobywx()
  109. {
  110. if ($this->request->isPost()) {
  111. $sceneId = $this->csmreq("scene_id", true);
  112. $dao = new \app\admin\model\csmadmin\Wxscan();
  113. $row = $dao->where("scene_id", "=", $sceneId)->find();
  114. if ($row != null) {
  115. // 60秒验证码过期
  116. if ((int) $sceneId < (time() - 60)) {
  117. $this->error('验证码已经过期!');
  118. }
  119. $service = new AdminService();
  120. $row = $service->getRowByWx($row->openid);
  121. trace($row);
  122. if ($row) {
  123. $service->directLogin($row);
  124. $this->success();
  125. }
  126. }
  127. $this->error('');
  128. }
  129. // copy from Csmadminapp#sendWxCodeAjax
  130. $sceneId = time();
  131. $wxqdurl = WxUtils::qrcodeCreate($sceneId);
  132. $this->assign("wxqdurl", $wxqdurl);
  133. $this->assign("scene_id", $sceneId);
  134. return $this->view->fetch();
  135. }
  136. public function dobydd()
  137. {
  138. // copy from Csmadminapp#modifydddialog
  139. $config = get_addon_config(CsmContants::$ADDONS);
  140. $ddappid = $config['ddappid'];
  141. $this->assign("ddappid", $ddappid);
  142. $this->assign("hosturl", $_SERVER["REQUEST_SCHEME"] . "://" . $_SERVER["SERVER_NAME"]);
  143. return $this->view->fetch();
  144. }
  145. /**
  146. * 用户扫码后,钉钉重定向进入完成登录
  147. */
  148. public function dobyddtologin()
  149. {
  150. // 用户扫码后,钉钉重定向进入
  151. $loginTmpCode = $this->csmreq("code", false);
  152. if ($loginTmpCode != null && $loginTmpCode != '') {
  153. $row = [
  154. 'unionid' => $loginTmpCode
  155. ];
  156. // $row = DDUtils::getUserInfoByLoginTmpCode($loginTmpCode);
  157. if ($row != null) {
  158. $service = new AdminService();
  159. $row = $service->getRowByDduserid($row['unionid']);
  160. if($row){
  161. $service->directLogin($row);
  162. return $this->view->fetch();
  163. }
  164. }
  165. $this->error('帐号不存在,请重新登录!');
  166. }
  167. }
  168. }