Просмотр исходного кода

wesmiler ECY 画画交易平台

APPLE 3 лет назад
Родитель
Сommit
f4caaa491d
1 измененных файлов с 37 добавлено и 0 удалено
  1. 37 0
      application/cmgadm/controller/general/Googlecode.php

+ 37 - 0
application/cmgadm/controller/general/Googlecode.php

@@ -0,0 +1,37 @@
+<?php
+
+namespace app\cmgadm\controller\general;
+use app\cmgadm\model\Admin;
+use app\common\controller\Backend;
+use app\common\model\Config;
+
+/**
+ * 谷歌验证码
+ *
+ * @icon fa fa-user
+ */
+class Googlecode extends Backend
+{
+    /**
+     * @return string|\think\response\Json
+     * @throws \think\Exception
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\ModelNotFoundException
+     * @throws \think\exception\DbException
+     */
+    public function index(){
+        $google = new \PHPGangsta_GoogleAuthenticator();
+        $admin = Admin::where(['id'=> $this->auth->id])->field('id,username,nickname,google_key')->find();
+        $googleKey = isset($admin['google_key'])? $admin['google_key'] : '';
+        if(empty($googleKey)){
+            $secret = $google->createSecret();
+            Admin::where(['id'=> $this->auth->id])->update(['google_key'=> $secret]);
+        }
+        $config = Config::getConfigByGroup('basic');
+        $siteName = isset($config['name'])? $config['name']['value'] : '茶马古道';
+        $qrcode = $google->getQRCodeGoogleUrl($admin['username'],$googleKey,$siteName);
+        $this->view->assign('admin', $admin);
+        $this->view->assign('qrcode', $qrcode);
+        return $this->view->fetch();
+    }
+}