|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * 简单、安全的身份验证服务 |
| 4 | + * |
| 5 | + * @package YangCong |
| 6 | + * @author 冰剑 |
| 7 | + * @version 2.0.0 |
| 8 | + * @link http://www.binjoo.net |
| 9 | + */ |
| 10 | +class YangCong_Plugin implements Typecho_Plugin_Interface { |
| 11 | + public static function activate() { |
| 12 | + Typecho_Plugin::factory('admin/header.php')->header = array('YangCong_Plugin', 'js_header'); |
| 13 | + Typecho_Plugin::factory('admin/profile.php')->bottom = array('YangCong_Plugin', 'js_profile'); |
| 14 | + Typecho_Plugin::factory('admin/login.php')->bottom = array('YangCong_Plugin', 'js_login'); |
| 15 | + Helper::addAction('YangCong', 'YangCong_Action'); |
| 16 | + return('微信助手已经成功激活,请进入设置Token!'); |
| 17 | + } |
| 18 | + |
| 19 | + public static function deactivate() { |
| 20 | + Helper::removeAction('YangCong'); |
| 21 | + } |
| 22 | + |
| 23 | + public static function config(Typecho_Widget_Helper_Form $form) { |
| 24 | + $yc_id = new Typecho_Widget_Helper_Form_Element_Text('yc_id', NULL, NULL, _t('应用 ID'), '啦啦啦啦'); |
| 25 | + $form->addInput($yc_id); |
| 26 | + |
| 27 | + $yc_key = new Typecho_Widget_Helper_Form_Element_Text('yc_key', NULL, NULL, _t('应用 KEY'), '啦啦啦啦'); |
| 28 | + $form->addInput($yc_key); |
| 29 | + |
| 30 | + $yc_input = new Typecho_Widget_Helper_Form_Element_Radio('yc_input', array('1' => '是', '0' => '否'), '0', '是否关闭传统登陆', '关闭后仅能使用扫码登陆。'); |
| 31 | + $form->addInput($yc_input); |
| 32 | + |
| 33 | + $yc_request = new Typecho_Widget_Helper_Form_Element_Text('yc_request', NULL, '5', _t('验证频率'), '请求洋葱服务器的频率,如果你不明白这是什么,请不要修改。'); |
| 34 | + $yc_request->input->setAttribute('class', 'mini'); |
| 35 | + $yc_request->addRule('isInteger','你不填写数字让我怎么办?实在搞不明白你就写个 5 得了。'); |
| 36 | + $form->addInput($yc_request); |
| 37 | + |
| 38 | + $yc_auth_type = new Typecho_Widget_Helper_Form_Element_Radio('yc_auth_type', array('1' => '确认按钮', '2' => '手势密码', '3' => '人脸', '4' => '声纹'), '1', '验证方式', '扫码成功后确认操作使用的验证方式'); |
| 39 | + $form->addInput($yc_auth_type); |
| 40 | + } |
| 41 | + |
| 42 | + public static function personalConfig(Typecho_Widget_Helper_Form $form){} |
| 43 | + |
| 44 | + public static function js_header($str) { |
| 45 | + $str .= '<style type="text/css"> |
| 46 | + .tab_panel, .typecho-login form{display: none} |
| 47 | + #tab_qrcode{padding-bottom: 1em; text-align: center} |
| 48 | + #tab_qrcode span{height: 100%; display: inline-block; vertical-align: middle} |
| 49 | + #tab_qrcode img, .bind_qrcode img{height: 280px; width: 280px; vertical-align: middle;cursor:pointer} |
| 50 | + #tab_qrcode img{margin-top: 1em} |
| 51 | + .bind_qrcode{display:none} |
| 52 | + </style>'; |
| 53 | + echo $str; |
| 54 | + } |
| 55 | + |
| 56 | + public static function js_profile($str) { |
| 57 | + $settings = Helper::options()->plugin('YangCong'); |
| 58 | + $str .= '<script type="text/javascript">'; |
| 59 | + $str .= 'jQuery(function($) { |
| 60 | + var bindTxt = \'<p class="bind_status">绑定状态:<span>未绑定</span></p><p class="bind_qrcode"><img src="" /></p>\'; |
| 61 | + $("div.typecho-page-main div:first").append(bindTxt); |
| 62 | + var timer = null; |
| 63 | +
|
| 64 | + $(".bind_qrcode img").click(function(){ |
| 65 | + $.getJSON("' . Helper::security()->getIndex('/action/YangCong?do=bind') . '", function(data){ |
| 66 | + if(!data){ |
| 67 | + $(".bind_status span").html("已绑定"); |
| 68 | + $(".bind_qrcode").remove(); |
| 69 | + } else if(data && data.status == 200){ |
| 70 | + $(".bind_status span").html("未绑定"); |
| 71 | + $(".bind_qrcode").show().find("img").attr("src", data.qrcode_url); |
| 72 | + timer = window.clearInterval(timer); |
| 73 | + timer = window.setInterval(function(){auth(data.event_id)},' . ($settings->yc_request * 1000) . '); |
| 74 | + } |
| 75 | + }); |
| 76 | + }).click(); |
| 77 | +
|
| 78 | + auth = function(event_id){ |
| 79 | + $.getJSON("' . Helper::security()->getIndex('/action/YangCong?do=auth') . '", {event_id : event_id, action : "bind"}, function(data){ |
| 80 | + if(data.status == 200){ |
| 81 | + timer = window.clearInterval(timer); |
| 82 | + $(".bind_status span").html("绑定成功"); |
| 83 | + $(".bind_qrcode").remove(); |
| 84 | + } |
| 85 | + }); |
| 86 | + } |
| 87 | + });'; |
| 88 | + $str .= '</script>'; |
| 89 | + echo $str; |
| 90 | + } |
| 91 | + |
| 92 | + public static function js_login($str) { |
| 93 | + $settings = Helper::options()->plugin('YangCong'); |
| 94 | + $str .= '<script type="text/javascript">'; |
| 95 | + $str .= 'jQuery(function($) { |
| 96 | + $("form[name=login]").wrap(\'<div id="tab_account" class="tab_panel"></div>\'); |
| 97 | + var tab = \'<ul class="typecho-option-tabs clearfix">\'; |
| 98 | + tab += \'<li class="w-50 active"><a href="#tab_qrcode">扫码登陆</a></li>\';'; |
| 99 | + if($settings->yc_input){ |
| 100 | + //$str .= '$("div.login_account").remove();'; |
| 101 | + } else { |
| 102 | + $str .= 'tab += \'<li class="w-50"><a href="#tab_account">传统登陆</a></li>\';'; |
| 103 | + $str .= '$(".typecho-login form").show();'; |
| 104 | + } |
| 105 | + $str .= 'tab += \'</ul>\'; |
| 106 | + $("div.typecho-login h1").after(tab); |
| 107 | + $("p.more-link").before(\'<div id="tab_qrcode" class="tab_panel"><span></span><img src="" /></div>\'); |
| 108 | + $("ul.typecho-option-tabs li a").click(function(){ |
| 109 | + $("ul.typecho-option-tabs li").removeClass("active"); |
| 110 | + $("div.tab_panel").hide(); |
| 111 | + $(this).parent("li").addClass("active"); |
| 112 | + $($(this).attr("href")).show(); |
| 113 | + }); |
| 114 | + $("#tab_qrcode").show(); |
| 115 | +
|
| 116 | + var timer = null; |
| 117 | + $("#tab_qrcode img").click(function(){ |
| 118 | + $.getJSON("' . Helper::security()->getIndex('/action/YangCong?do=login') . '", function(data){ |
| 119 | + if(data.status == 200){ |
| 120 | + $("#tab_qrcode img").attr("src", data.qrcode_url); |
| 121 | + timer = window.clearInterval(timer); |
| 122 | + timer = window.setInterval(function(){auth(data.event_id)},' . ($settings->yc_request * 1000) . '); |
| 123 | + } |
| 124 | + }); |
| 125 | + }).click(); |
| 126 | +
|
| 127 | + auth = function(event_id){ |
| 128 | + $.getJSON("' . Helper::security()->getIndex('/action/YangCong?do=auth') . '", {event_id : event_id, action : "login"}, function(data){ |
| 129 | + if(data.status == 200){ |
| 130 | + timer = window.clearInterval(timer); |
| 131 | + window.location.href = data.redirect; |
| 132 | + } |
| 133 | + }); |
| 134 | + } |
| 135 | + });'; |
| 136 | + $str .= '</script>'; |
| 137 | + echo $str; |
| 138 | + } |
| 139 | +} |
0 commit comments