123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186 |
- <?php
- namespace app\admin\controller\csmadmin;
- use addons\csmadmin\library\CsmBackend;
- use addons\csmadmin\library\CsmContants;
- use addons\csmadmin\library\CsmadminUtils;
- use addons\csmadmin\library\WxUtils;
- use addons\csmadmin\library\service\AdminService;
- use think\Session;
- /**
- * http://127.0.0.1/fastadmin_plugin_csmmeet/public/q3HJDu2RgE.php/csmadmin/csmadminlogin/dobyemail
- */
- class Csmadminlogin extends CsmBackend
- {
- protected $noNeedLogin = [
- '*'
- ];
- protected $noNeedRight = [
- '*'
- ];
- protected $layout = '';
- protected $ulmenu;
- public function _initialize()
- {
- parent::_initialize();
- $url = $this->request->get('url');
- if ($this->auth->isLogin()) {
- $this->success(__("You've logged in, do not login again"), $url);
- }
- $getparam = ($url == null || $url == '') ? '?1=1' : '?url=' . urlencode($url);
- $this->ulmenu = [];
- $this->ulmenu[] = [
- 'name' => '邮件短信',
- 'code' => 'dobyemail',
- 'url' => $this->request->baseFile().'/csmadmin/csmadminlogin/dobyemail' . $getparam
- ];
- $config = get_addon_config(CsmContants::$ADDONS);
- //v2.1.3 适配fa.1.3.4增加手机号码调整
- $this->ulmenu[] = [
- 'name' => '手机短信',
- 'code' => 'dobymobile',
- 'url' => $this->request->baseFile().'/csmadmin/csmadminlogin/dobymobile' . $getparam
- ];
- if ($config['haswxfield'] == 'Y') {
- $this->ulmenu[] = [
- 'name' => '微信登录',
- 'code' => 'dobywx',
- 'url' => $this->request->baseFile().'/csmadmin/csmadminlogin/dobywx' . $getparam
- ];
- }
- //v1.2.1 增加钉钉登录
- $plugin = get_addon_info('csmding');
- if ($plugin && $plugin['state']) {
- $getparam .= '&urlmenu='.urlencode(json_encode($this->ulmenu));
- $this->ulmenu[] = [
- 'name' => '钉钉登录',
- 'code' => 'dobydd',
- 'url' => $this->request->baseFile().'/csmding/ddlogin/dobydd' . $getparam
- ];
- }
-
- $this->assign('ulmenu', $this->ulmenu);
- $this->assign('title', "用户登录");
- $this->view->engine->layout('csmadmin/layout/default');
- }
- public function dobyemail()
- {
- if ($this->request->isPost()) {
- $event = "通过邮箱登录验证码";
- $ccode = $this->csmreq("ccode", true);
- $email = $this->csmreq("email", true);
- // 校验验证码
- $sendccode = Session::get(CsmadminUtils::getSessionKey($email, $event));
- if ($sendccode != $ccode) {
- $this->error('验证码错误!');
- }
- $service = new AdminService();
- $row = $service->getRowByEmail($email);
- if ($row) {
- $service->directLogin($row);
- $this->success();
- } else {
- $this->error('帐号不存在,请重新登录!');
- }
- }
- return $this->view->fetch();
- }
- public function dobymobile()
- {
- if ($this->request->isPost()) {
- $event = "通过手机登录验证码";
- $ccode = $this->csmreq("ccode", true);
- $mobile = $this->csmreq("mobile", true);
- // 校验验证码
- $sendccode = Session::get(CsmadminUtils::getSessionKey($mobile, $event));
- if ($sendccode != $ccode) {
- $this->error('验证码错误!');
- }
- $service = new AdminService();
- $row = $service->getRowByMobile($mobile);
- if ($row) {
- $service->directLogin($row);
- $this->success();
- } else {
- $this->error('帐号不存在,请重新登录!');
- }
- }
- return $this->view->fetch();
- }
- public function dobywx()
- {
- if ($this->request->isPost()) {
- $sceneId = $this->csmreq("scene_id", true);
- $dao = new \app\admin\model\csmadmin\Wxscan();
- $row = $dao->where("scene_id", "=", $sceneId)->find();
- if ($row != null) {
- // 60秒验证码过期
- if ((int) $sceneId < (time() - 60)) {
- $this->error('验证码已经过期!');
- }
- $service = new AdminService();
- $row = $service->getRowByWx($row->openid);
- trace($row);
- if ($row) {
- $service->directLogin($row);
- $this->success();
- }
- }
- $this->error('');
- }
- // copy from Csmadminapp#sendWxCodeAjax
- $sceneId = time();
- $wxqdurl = WxUtils::qrcodeCreate($sceneId);
- $this->assign("wxqdurl", $wxqdurl);
- $this->assign("scene_id", $sceneId);
- return $this->view->fetch();
- }
- public function dobydd()
- {
- // copy from Csmadminapp#modifydddialog
- $config = get_addon_config(CsmContants::$ADDONS);
- $ddappid = $config['ddappid'];
- $this->assign("ddappid", $ddappid);
- $this->assign("hosturl", $_SERVER["REQUEST_SCHEME"] . "://" . $_SERVER["SERVER_NAME"]);
- return $this->view->fetch();
- }
- /**
- * 用户扫码后,钉钉重定向进入完成登录
- */
- public function dobyddtologin()
- {
- // 用户扫码后,钉钉重定向进入
- $loginTmpCode = $this->csmreq("code", false);
- if ($loginTmpCode != null && $loginTmpCode != '') {
- $row = [
- 'unionid' => $loginTmpCode
- ];
- // $row = DDUtils::getUserInfoByLoginTmpCode($loginTmpCode);
- if ($row != null) {
- $service = new AdminService();
- $row = $service->getRowByDduserid($row['unionid']);
- if($row){
- $service->directLogin($row);
- return $this->view->fetch();
- }
- }
- $this->error('帐号不存在,请重新登录!');
- }
- }
- }
|