diff --git a/QuickAuthLogin/Action.php b/QuickAuthLogin/Action.php index e45bf59..debb84b 100644 --- a/QuickAuthLogin/Action.php +++ b/QuickAuthLogin/Action.php @@ -1,11 +1,20 @@ QuickAuthLogin_Plugin::PLUGIN_VERSION ] ]; - $res = new Typecho_Response(); - $res->throwJson($data); + $this->throwJson($data); } /* 重置当前用户绑定数据 */ public function reset() { require_once __TYPECHO_ROOT_DIR__ . __TYPECHO_ADMIN_DIR__ . 'common.php'; - $res = new Typecho_Response(); $ret = []; if ($user->haslogin()) { @@ -43,19 +50,17 @@ class QuickAuthLogin_Action extends Typecho_Widget } else { $ret['msg'] = 'what are you doing?'; } - $res->throwJson($ret); + + $this->throwJson($ret); } /* 微信Callback跳转登录逻辑 */ public function wechatlogin() { $options = QuickAuthLogin_Plugin::getoptions(); - $res = new Typecho_Response(); - $req = new Typecho_Request(); $ret = []; - - $code = $req->get('code'); - $state = $req->get('state'); + $code = $_GET['code']; + $state = $_GET['state']; $api = $options->qauth_api."/user?code=".$code."&appkey=".$options->qauth_app_key."&secret=".$options->qauth_user_secret; $paras['header'] = 1; @@ -78,12 +83,12 @@ class QuickAuthLogin_Action extends Typecho_Widget $user = $db->fetchRow($db->select()->from('table.users')->where( 'qa_openid' . ' = ?', $openId[1])->limit(1)); if($user){ $this->widget('Widget_Notice')->set('此微信账号已被绑定!', 'error'); - $res->redirect("/admin/extending.php?panel=QuickAuthLogin/views/authbind.php"); + $this->redirect("/admin/extending.php?panel=QuickAuthLogin/views/authbind.php"); } //更新基础信息 $db->query($db->update('table.users')->rows(['qa_openid' => $openId[1], 'qa_nickname' => $nickName[1], 'qa_avatar' => $avatarUrl[1]])->where('name = ?', $name)); $this->widget('Widget_Notice')->set(_t('用户 %s 成功绑定微信账号 %s', $name, $nickName[1]), 'success'); - $res->redirect("/admin/extending.php?panel=QuickAuthLogin/views/authbind.php"); + $this->redirect("/admin/extending.php?panel=QuickAuthLogin/views/authbind.php"); } else{ $ret['login']['msg'] = 'Fail'; @@ -92,11 +97,11 @@ class QuickAuthLogin_Action extends Typecho_Widget $user = $db->fetchRow($db->select()->from('table.users')->where( 'qa_openid' . ' = ?', $openId[1])->limit(1)); if($user){ - $authCode = function_exists('openssl_random_pseudo_bytes') ? bin2hex(openssl_random_pseudo_bytes(16)) : sha1(Typecho_Common::randString(20)); + $authCode = function_exists('openssl_random_pseudo_bytes') ? bin2hex(openssl_random_pseudo_bytes(16)) : sha1(Common::randString(20)); $user['authCode'] = $authCode; - Typecho_Cookie::set('__typecho_uid', $user['uid'], $expire); - Typecho_Cookie::set('__typecho_authCode', Typecho_Common::hash($authCode), $expire); + Typecho_Cookie::set('__typecho_uid', $user['uid']); + Typecho_Cookie::set('__typecho_authCode', Typecho_Common::hash($authCode)); $db->query($db->update('table.users')->expression('logged', 'activated')->rows(['authCode' => $authCode])->where('uid = ?', $user['uid'])); @@ -107,7 +112,7 @@ class QuickAuthLogin_Action extends Typecho_Widget $this->_hasLogin = true; echo 'success'; - $res->redirect(Helper::options()->adminUrl); + $this->redirect(Helper::options()->adminUrl); } else{//该微信账号未绑定 if($options->allow_register){//匿名账号注册登录 @@ -137,8 +142,8 @@ class QuickAuthLogin_Action extends Typecho_Widget $authCode = function_exists('openssl_random_pseudo_bytes') ? bin2hex(openssl_random_pseudo_bytes(16)) : sha1(Typecho_Common::randString(20)); $user['authCode'] = $authCode; - Typecho_Cookie::set('__typecho_uid', $user['uid'], $expire); - Typecho_Cookie::set('__typecho_authCode', Typecho_Common::hash($authCode), $expire); + Typecho_Cookie::set('__typecho_uid', $user['uid']); + Typecho_Cookie::set('__typecho_authCode', Typecho_Common::hash($authCode)); $db->query($db->update('table.users')->expression('logged', 'activated')->rows(['authCode' => $authCode])->where('uid = ?', $user['uid'])); @@ -148,21 +153,21 @@ class QuickAuthLogin_Action extends Typecho_Widget $this->_hasLogin = true; $this->widget('Widget_Notice')->set(_t('用户 %s 已经成功注册, 密码为 %s', $newUserName, $generatedPassword), 'success'); - $res->redirect(Helper::options()->adminUrl); + $this->redirect(Helper::options()->adminUrl); } else{ $this->widget('Widget_Notice')->set('该微信未绑定用户,无法登陆!', 'error'); - $res->redirect(Helper::options()->loginUrl); + $this->redirect(Helper::options()->loginUrl); } } } - $res->throwJson($ret); + $this->throwJson($ret); } else{ $ret['msg'] = $msg[1]; - $res->throwJson($ret); + $this->throwJson($ret); } } diff --git a/QuickAuthLogin/Plugin.php b/QuickAuthLogin/Plugin.php index f3f85ce..7ec6437 100644 --- a/QuickAuthLogin/Plugin.php +++ b/QuickAuthLogin/Plugin.php @@ -4,14 +4,14 @@ * * @package QuickAuthLogin * @author wixy - * @version 0.9.2 + * @version 0.9.3 * @link https://blog.wixy.cn */ class QuickAuthLogin_Plugin implements Typecho_Plugin_Interface { const PLUGIN_NAME = 'QuickAuthLogin'; - const PLUGIN_VERSION = '0.9.2'; + const PLUGIN_VERSION = '0.9.3'; const PLUGIN_PATH = __TYPECHO_ROOT_DIR__.__TYPECHO_PLUGIN_DIR__.'/QuickAuthLogin/'; /** diff --git a/QuickAuthLogin/README.md b/QuickAuthLogin/README.md index 14891c3..6da9ccc 100644 --- a/QuickAuthLogin/README.md +++ b/QuickAuthLogin/README.md @@ -4,6 +4,10 @@ #### 更新记录 +##### 2022/04/08 v0.9.3 + +1. 适配Typecho1.2版本 + ##### 2022/03/31 v0.9.2 1. 支持QuickAuth平台测试功能,可测试插件是否安装成功 @@ -40,15 +44,15 @@ Github: [https://github.com/mr-wixy/QuickAuthLogin](https://github.com/mr-wixy/Q ![建接入应用](https://cdn.wixy.cn/blog-picture/20220407133031.png) -第 6 步:发布应用; +第 5 步:发布应用; ![发布应用](https://cdn.wixy.cn/blog-picture/20220407133237.png) -第 7 步:[获取](https://qauth.cn/config/secret)UserSecretKey; +第 6 步:[获取](https://qauth.cn/config/secret)UserSecretKey; ![](https://cdn.wixy.cn/blog-picture/blog-picture20220127161157.png) -第 8 步:进入博客插件后台配置AppKey和UserSecret; +第 7 步:进入博客插件后台配置AppKey和UserSecret; ![](https://cdn.wixy.cn/blog-picture/20220307165220.png) diff --git a/README.md b/README.md index 14891c3..6da9ccc 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,10 @@ #### 更新记录 +##### 2022/04/08 v0.9.3 + +1. 适配Typecho1.2版本 + ##### 2022/03/31 v0.9.2 1. 支持QuickAuth平台测试功能,可测试插件是否安装成功 @@ -40,15 +44,15 @@ Github: [https://github.com/mr-wixy/QuickAuthLogin](https://github.com/mr-wixy/Q ![建接入应用](https://cdn.wixy.cn/blog-picture/20220407133031.png) -第 6 步:发布应用; +第 5 步:发布应用; ![发布应用](https://cdn.wixy.cn/blog-picture/20220407133237.png) -第 7 步:[获取](https://qauth.cn/config/secret)UserSecretKey; +第 6 步:[获取](https://qauth.cn/config/secret)UserSecretKey; ![](https://cdn.wixy.cn/blog-picture/blog-picture20220127161157.png) -第 8 步:进入博客插件后台配置AppKey和UserSecret; +第 7 步:进入博客插件后台配置AppKey和UserSecret; ![](https://cdn.wixy.cn/blog-picture/20220307165220.png)