Compare commits

...

3 Commits

Author SHA1 Message Date
wixy 4118154405 v0.9.3 版本更新
Signed-off-by: wixy <wixy@wixy.cn>
2022-04-08 09:56:03 +08:00
wixy c8e5d13235 update readme
Signed-off-by: wixy <wixy@wixy.cn>
2022-04-07 13:42:27 +08:00
wixy 3df9a5e8fd v0.9.2 版本更新
Signed-off-by: wixy <wixy@wixy.cn>
2022-04-07 13:36:34 +08:00
4 changed files with 72 additions and 44 deletions

View File

@ -1,17 +1,39 @@
<?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(){
$version = Typecho_Cookie::get('__typecho_check_version');
$data = [
"code" => 0,
"msg" => "pong",
"data" => [
"name" => "QuickAuthLogin For Typecho",
"version" => QuickAuthLogin_Plugin::PLUGIN_VERSION
]
];
$this->throwJson($data);
}
/* 重置当前用户绑定数据 */
public function reset()
{
require_once __TYPECHO_ROOT_DIR__ . __TYPECHO_ADMIN_DIR__ . 'common.php';
$res = new Typecho_Response();
$ret = [];
if ($user->haslogin()) {
@ -28,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;
@ -63,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';
@ -77,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']));
@ -92,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){//匿名账号注册登录
@ -122,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']));
@ -133,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,13 +4,14 @@
*
* @package QuickAuthLogin
* @author wixy
* @version 0.9.1
* @link https://blog.wixy.cn/archives/quickauthlogin.html
* @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.3';
const PLUGIN_PATH = __TYPECHO_ROOT_DIR__.__TYPECHO_PLUGIN_DIR__.'/QuickAuthLogin/';
/**
@ -27,6 +28,7 @@ class QuickAuthLogin_Plugin implements Typecho_Plugin_Interface {
Helper::addPanel(1, 'QuickAuthLogin/views/authbind.php', '微信账号绑定', '微信账号绑定', 'subscriber');
Helper::addRoute('wechatlogin',__TYPECHO_ADMIN_DIR__.'QuickAuthLogin/wechatlogin','QuickAuthLogin_Action','wechatlogin');
Helper::addRoute('reset',__TYPECHO_ADMIN_DIR__.'QuickAuthLogin/reset','QuickAuthLogin_Action','reset');
Helper::addRoute('ping',__TYPECHO_ADMIN_DIR__.'QuickAuthLogin/ping','QuickAuthLogin_Action','ping');
}
public static function updateDb()

View File

@ -4,6 +4,15 @@
#### 更新记录
##### 2022/04/08 v0.9.3
1. 适配Typecho1.2版本
##### 2022/03/31 v0.9.2
1. 支持QuickAuth平台测试功能可测试插件是否安装成功
2. 更新接入教程
##### 2022/03/07 v0.9.1
1. 取消替换登录界面功能,改为在源登录界面注入微信登录按钮
@ -33,23 +42,17 @@ Github: [https://github.com/mr-wixy/QuickAuthLogin](https://github.com/mr-wixy/Q
第 4 步登录QuickAuth网站创建接入应用
![](https://cdn.wixy.cn/blog-picture/blog-picture20220127160420.png)
![建接入应用](https://cdn.wixy.cn/blog-picture/20220407133031.png)
<br/>
第 5 步:发布应用;
第 5 步填写应用的基本信息注意此时可以获取到AppKey回调地址请填写自己博客的域名+/index.php/admin/QuickAuthLogin/wechatlogin 此处必须为https
![发布应用](https://cdn.wixy.cn/blog-picture/20220407133237.png)
![](https://cdn.wixy.cn/blog-picture/blog-picture20220127160707.png)
第 6 步:发布应用;
![发布应用](https://cdn.wixy.cn/blog-picture/blog-picture20220127161055.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,15 @@
#### 更新记录
##### 2022/04/08 v0.9.3
1. 适配Typecho1.2版本
##### 2022/03/31 v0.9.2
1. 支持QuickAuth平台测试功能可测试插件是否安装成功
2. 更新接入教程
##### 2022/03/07 v0.9.1
1. 取消替换登录界面功能,改为在源登录界面注入微信登录按钮
@ -33,23 +42,17 @@ Github: [https://github.com/mr-wixy/QuickAuthLogin](https://github.com/mr-wixy/Q
第 4 步登录QuickAuth网站创建接入应用
![](https://cdn.wixy.cn/blog-picture/blog-picture20220127160420.png)
![建接入应用](https://cdn.wixy.cn/blog-picture/20220407133031.png)
<br/>
第 5 步:发布应用;
第 5 步填写应用的基本信息注意此时可以获取到AppKey回调地址请填写自己博客的域名+/index.php/admin/QuickAuthLogin/wechatlogin 此处必须为https
![发布应用](https://cdn.wixy.cn/blog-picture/20220407133237.png)
![](https://cdn.wixy.cn/blog-picture/blog-picture20220127160707.png)
第 6 步:发布应用;
![发布应用](https://cdn.wixy.cn/blog-picture/blog-picture20220127161055.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)