v0.9.3 版本更新

Signed-off-by: wixy <wixy@wixy.cn>
This commit is contained in:
wixy 2022-04-08 09:56:03 +08:00
parent c8e5d13235
commit 4118154405
4 changed files with 43 additions and 30 deletions

View File

@ -1,11 +1,20 @@
<?php
if (!defined('__TYPECHO_ROOT_DIR__')) {
exit;
}
class QuickAuthLogin_Action extends Typecho_Widget
{
private function throwJson($data){
header('Content-Type:application/json; charset=utf-8');
exit(json_encode($data));
}
private function redirect($location){
header("Location: $location");
exit();
}
/* 测试插件安装接口 */
public function ping(){
@ -18,15 +27,13 @@ class QuickAuthLogin_Action extends Typecho_Widget
"version" => 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('用户 <strong>%s</strong> 成功绑定微信账号 <strong>%s</strong>', $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('用户 <strong>%s</strong> 已经成功注册, 密码为 <strong>%s</strong>', $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);
}
}

View File

@ -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/';
/**

View File

@ -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)

View File

@ -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)