GoogleCode.php 1.0 KB

123456789101112131415161718192021222324252627282930
  1. <?php
  2. namespace app\cmgadm\controller\general;
  3. use app\cmgadm\model\Admin;
  4. use app\common\controller\Backend;
  5. use app\common\model\Config;
  6. /**
  7. * 谷歌验证码
  8. *
  9. * @icon fa fa-user
  10. */
  11. class GoogleCode extends Backend
  12. {
  13. public function index(){
  14. $google = new \PHPGangsta_GoogleAuthenticator();
  15. $admin = Admin::where(['id'=> $this->auth->id])->field('id,username,nickname,google_key')->find();
  16. $googleKey = isset($admin['google_key'])? $admin['google_key'] : '';
  17. if(empty($googleKey)){
  18. $secret = $google->createSecret();
  19. Admin::where(['id'=> $this->auth->id])->update(['google_key'=> $secret]);
  20. }
  21. $config = Config::getConfigByGroup('basic');
  22. $siteName = isset($config['name'])? $config['name'] : '茶马古道';
  23. $qrcode = $google->getQRCodeGoogleUrl($admin['username'],$googleKey,$siteName);
  24. $this->view->assign('admin', $admin);
  25. $this->view->assign('qrcode', $qrcode);
  26. return $this->view->fetch();
  27. }
  28. }