|
|
@@ -2,6 +2,7 @@
|
|
|
|
|
|
namespace app\cmgadm\controller;
|
|
|
|
|
|
+use app\cmgadm\model\Admin;
|
|
|
use app\cmgadm\model\AdminLog;
|
|
|
use app\common\controller\Backend;
|
|
|
use think\Config;
|
|
|
@@ -61,6 +62,8 @@ class Index extends Backend
|
|
|
if ($this->auth->isLogin()) {
|
|
|
$this->success(__("You've logged in, do not login again"), $url);
|
|
|
}
|
|
|
+ $config = \app\common\model\Config::getConfigByGroup('basic');
|
|
|
+ $googleVerify = isset($config['google_verify'])? $config['google_verify']['value'] : 0;
|
|
|
if ($this->request->isPost()) {
|
|
|
$username = $this->request->post('username');
|
|
|
$password = $this->request->post('password');
|
|
|
@@ -80,11 +83,28 @@ class Index extends Backend
|
|
|
$rule['captcha'] = 'require|captcha';
|
|
|
$data['captcha'] = $this->request->post('captcha');
|
|
|
}
|
|
|
- $validate = new Validate($rule, [], ['username' => __('Username'), 'password' => __('Password'), 'captcha' => __('Captcha')]);
|
|
|
+
|
|
|
+ $admin = Admin::get(['username' => $username]);
|
|
|
+ $googleKey = isset($admin['google_key'])? $admin['google_key'] : '';
|
|
|
+ $googleBind = isset($admin['google_bind'])? $admin['google_bind'] : 0;
|
|
|
+ if ($googleVerify && $googleBind==1) {
|
|
|
+ $rule['google_code'] = 'require';
|
|
|
+ }
|
|
|
+ $validate = new Validate($rule, [], ['username' => __('Username'), 'password' => __('Password'), 'captcha' => __('Captcha'),'google_code'=>'谷歌验证码']);
|
|
|
$result = $validate->check($data);
|
|
|
if (!$result) {
|
|
|
$this->error($validate->getError(), $url, ['token' => $this->request->token()]);
|
|
|
}
|
|
|
+
|
|
|
+ // 谷歌验证码验证
|
|
|
+ $googleCode = $this->request->post('google_code');
|
|
|
+ if($googleVerify && $googleBind==1){
|
|
|
+ $google = new \PHPGangsta_GoogleAuthenticator();
|
|
|
+ if(!$google->verifyCode($googleKey, $googleCode)){
|
|
|
+ $this->error('谷歌验证码错误', $url, ['token' => $this->request->token()]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
AdminLog::setTitle(__('Login'));
|
|
|
$result = $this->auth->login($username, $password, $keeplogin ? 86400 : 0);
|
|
|
if ($result === true) {
|
|
|
@@ -104,8 +124,6 @@ class Index extends Backend
|
|
|
|
|
|
$background = Config::get('fastadmin.login_background');
|
|
|
$background = stripos($background, 'http') === 0 ? $background : config('site.cdnurl') . $background;
|
|
|
- $config = \app\common\model\Config::getConfigByGroup('basic');
|
|
|
- $googleVerify = isset($config['google_verify'])? $config['google_verify']['value'] : 0;
|
|
|
$this->view->assign('background', $background);
|
|
|
$this->view->assign('title', __('Login'));
|
|
|
$this->view->assign('google_verify',$googleVerify);
|