parent
c8e5d13235
commit
4118154405
|
@ -6,6 +6,15 @@ if (!defined('__TYPECHO_ROOT_DIR__')) {
|
||||||
|
|
||||||
class QuickAuthLogin_Action extends Typecho_Widget
|
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(){
|
public function ping(){
|
||||||
|
@ -18,15 +27,13 @@ class QuickAuthLogin_Action extends Typecho_Widget
|
||||||
"version" => QuickAuthLogin_Plugin::PLUGIN_VERSION
|
"version" => QuickAuthLogin_Plugin::PLUGIN_VERSION
|
||||||
]
|
]
|
||||||
];
|
];
|
||||||
$res = new Typecho_Response();
|
$this->throwJson($data);
|
||||||
$res->throwJson($data);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 重置当前用户绑定数据 */
|
/* 重置当前用户绑定数据 */
|
||||||
public function reset()
|
public function reset()
|
||||||
{
|
{
|
||||||
require_once __TYPECHO_ROOT_DIR__ . __TYPECHO_ADMIN_DIR__ . 'common.php';
|
require_once __TYPECHO_ROOT_DIR__ . __TYPECHO_ADMIN_DIR__ . 'common.php';
|
||||||
$res = new Typecho_Response();
|
|
||||||
$ret = [];
|
$ret = [];
|
||||||
|
|
||||||
if ($user->haslogin()) {
|
if ($user->haslogin()) {
|
||||||
|
@ -43,19 +50,17 @@ class QuickAuthLogin_Action extends Typecho_Widget
|
||||||
} else {
|
} else {
|
||||||
$ret['msg'] = 'what are you doing?';
|
$ret['msg'] = 'what are you doing?';
|
||||||
}
|
}
|
||||||
$res->throwJson($ret);
|
|
||||||
|
$this->throwJson($ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 微信Callback跳转登录逻辑 */
|
/* 微信Callback跳转登录逻辑 */
|
||||||
public function wechatlogin()
|
public function wechatlogin()
|
||||||
{
|
{
|
||||||
$options = QuickAuthLogin_Plugin::getoptions();
|
$options = QuickAuthLogin_Plugin::getoptions();
|
||||||
$res = new Typecho_Response();
|
|
||||||
$req = new Typecho_Request();
|
|
||||||
$ret = [];
|
$ret = [];
|
||||||
|
$code = $_GET['code'];
|
||||||
$code = $req->get('code');
|
$state = $_GET['state'];
|
||||||
$state = $req->get('state');
|
|
||||||
|
|
||||||
$api = $options->qauth_api."/user?code=".$code."&appkey=".$options->qauth_app_key."&secret=".$options->qauth_user_secret;
|
$api = $options->qauth_api."/user?code=".$code."&appkey=".$options->qauth_app_key."&secret=".$options->qauth_user_secret;
|
||||||
$paras['header'] = 1;
|
$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));
|
$user = $db->fetchRow($db->select()->from('table.users')->where( 'qa_openid' . ' = ?', $openId[1])->limit(1));
|
||||||
if($user){
|
if($user){
|
||||||
$this->widget('Widget_Notice')->set('此微信账号已被绑定!', 'error');
|
$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));
|
$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');
|
$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{
|
else{
|
||||||
$ret['login']['msg'] = 'Fail';
|
$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));
|
$user = $db->fetchRow($db->select()->from('table.users')->where( 'qa_openid' . ' = ?', $openId[1])->limit(1));
|
||||||
|
|
||||||
if($user){
|
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;
|
$user['authCode'] = $authCode;
|
||||||
|
|
||||||
Typecho_Cookie::set('__typecho_uid', $user['uid'], $expire);
|
Typecho_Cookie::set('__typecho_uid', $user['uid']);
|
||||||
Typecho_Cookie::set('__typecho_authCode', Typecho_Common::hash($authCode), $expire);
|
Typecho_Cookie::set('__typecho_authCode', Typecho_Common::hash($authCode));
|
||||||
|
|
||||||
$db->query($db->update('table.users')->expression('logged',
|
$db->query($db->update('table.users')->expression('logged',
|
||||||
'activated')->rows(['authCode' => $authCode])->where('uid = ?', $user['uid']));
|
'activated')->rows(['authCode' => $authCode])->where('uid = ?', $user['uid']));
|
||||||
|
@ -107,7 +112,7 @@ class QuickAuthLogin_Action extends Typecho_Widget
|
||||||
$this->_hasLogin = true;
|
$this->_hasLogin = true;
|
||||||
|
|
||||||
echo 'success';
|
echo 'success';
|
||||||
$res->redirect(Helper::options()->adminUrl);
|
$this->redirect(Helper::options()->adminUrl);
|
||||||
}
|
}
|
||||||
else{//该微信账号未绑定
|
else{//该微信账号未绑定
|
||||||
if($options->allow_register){//匿名账号注册登录
|
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));
|
$authCode = function_exists('openssl_random_pseudo_bytes') ? bin2hex(openssl_random_pseudo_bytes(16)) : sha1(Typecho_Common::randString(20));
|
||||||
$user['authCode'] = $authCode;
|
$user['authCode'] = $authCode;
|
||||||
Typecho_Cookie::set('__typecho_uid', $user['uid'], $expire);
|
Typecho_Cookie::set('__typecho_uid', $user['uid']);
|
||||||
Typecho_Cookie::set('__typecho_authCode', Typecho_Common::hash($authCode), $expire);
|
Typecho_Cookie::set('__typecho_authCode', Typecho_Common::hash($authCode));
|
||||||
|
|
||||||
$db->query($db->update('table.users')->expression('logged',
|
$db->query($db->update('table.users')->expression('logged',
|
||||||
'activated')->rows(['authCode' => $authCode])->where('uid = ?', $user['uid']));
|
'activated')->rows(['authCode' => $authCode])->where('uid = ?', $user['uid']));
|
||||||
|
@ -148,21 +153,21 @@ class QuickAuthLogin_Action extends Typecho_Widget
|
||||||
$this->_hasLogin = true;
|
$this->_hasLogin = true;
|
||||||
|
|
||||||
$this->widget('Widget_Notice')->set(_t('用户 <strong>%s</strong> 已经成功注册, 密码为 <strong>%s</strong>', $newUserName, $generatedPassword), 'success');
|
$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{
|
else{
|
||||||
$this->widget('Widget_Notice')->set('该微信未绑定用户,无法登陆!', 'error');
|
$this->widget('Widget_Notice')->set('该微信未绑定用户,无法登陆!', 'error');
|
||||||
$res->redirect(Helper::options()->loginUrl);
|
$this->redirect(Helper::options()->loginUrl);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$res->throwJson($ret);
|
$this->throwJson($ret);
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
$ret['msg'] = $msg[1];
|
$ret['msg'] = $msg[1];
|
||||||
$res->throwJson($ret);
|
$this->throwJson($ret);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,14 +4,14 @@
|
||||||
*
|
*
|
||||||
* @package QuickAuthLogin
|
* @package QuickAuthLogin
|
||||||
* @author wixy
|
* @author wixy
|
||||||
* @version 0.9.2
|
* @version 0.9.3
|
||||||
* @link https://blog.wixy.cn
|
* @link https://blog.wixy.cn
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class QuickAuthLogin_Plugin implements Typecho_Plugin_Interface {
|
class QuickAuthLogin_Plugin implements Typecho_Plugin_Interface {
|
||||||
|
|
||||||
const PLUGIN_NAME = 'QuickAuthLogin';
|
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/';
|
const PLUGIN_PATH = __TYPECHO_ROOT_DIR__.__TYPECHO_PLUGIN_DIR__.'/QuickAuthLogin/';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -4,6 +4,10 @@
|
||||||
|
|
||||||
#### 更新记录
|
#### 更新记录
|
||||||
|
|
||||||
|
##### 2022/04/08 v0.9.3
|
||||||
|
|
||||||
|
1. 适配Typecho1.2版本
|
||||||
|
|
||||||
##### 2022/03/31 v0.9.2
|
##### 2022/03/31 v0.9.2
|
||||||
|
|
||||||
1. 支持QuickAuth平台测试功能,可测试插件是否安装成功
|
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)
|
![建接入应用](https://cdn.wixy.cn/blog-picture/20220407133031.png)
|
||||||
|
|
||||||
第 6 步:发布应用;
|
第 5 步:发布应用;
|
||||||
|
|
||||||
![发布应用](https://cdn.wixy.cn/blog-picture/20220407133237.png)
|
![发布应用](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)
|
![](https://cdn.wixy.cn/blog-picture/blog-picture20220127161157.png)
|
||||||
|
|
||||||
第 8 步:进入博客插件后台配置AppKey和UserSecret;
|
第 7 步:进入博客插件后台配置AppKey和UserSecret;
|
||||||
|
|
||||||
![](https://cdn.wixy.cn/blog-picture/20220307165220.png)
|
![](https://cdn.wixy.cn/blog-picture/20220307165220.png)
|
||||||
|
|
||||||
|
|
10
README.md
10
README.md
|
@ -4,6 +4,10 @@
|
||||||
|
|
||||||
#### 更新记录
|
#### 更新记录
|
||||||
|
|
||||||
|
##### 2022/04/08 v0.9.3
|
||||||
|
|
||||||
|
1. 适配Typecho1.2版本
|
||||||
|
|
||||||
##### 2022/03/31 v0.9.2
|
##### 2022/03/31 v0.9.2
|
||||||
|
|
||||||
1. 支持QuickAuth平台测试功能,可测试插件是否安装成功
|
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)
|
![建接入应用](https://cdn.wixy.cn/blog-picture/20220407133031.png)
|
||||||
|
|
||||||
第 6 步:发布应用;
|
第 5 步:发布应用;
|
||||||
|
|
||||||
![发布应用](https://cdn.wixy.cn/blog-picture/20220407133237.png)
|
![发布应用](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)
|
![](https://cdn.wixy.cn/blog-picture/blog-picture20220127161157.png)
|
||||||
|
|
||||||
第 8 步:进入博客插件后台配置AppKey和UserSecret;
|
第 7 步:进入博客插件后台配置AppKey和UserSecret;
|
||||||
|
|
||||||
![](https://cdn.wixy.cn/blog-picture/20220307165220.png)
|
![](https://cdn.wixy.cn/blog-picture/20220307165220.png)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue