Tips
In the front, do not think it is difficult to configure. In fact, it is just copying and pasting. The code is ready-made.
JOE template Small bulb Spimes 5.0
Detailed introduction and download address:
Installation tutorial:
Description of secondary development:
Tutorial of member system takeover (it's OK if you don't take over, just look at your mood):
<script src="/ruleuser/configs.js?v1.02"></script> <script src="/ruleuser/main/RuleUser.js?v1.02"></script> <script> loadPostBtn(<? php echo $this->cid; ?>); loadPostShop(<? php echo $this->cid; ?>) </script>
<div id="RuleUser-PostShop"></div> <div id="RuleUser-PostBtn"></div>
<button type="button" onclick="UserLogin()">Login</button> <button type="button" onclick="UserRegister()">Register</button> <button type="button" onclick="UserForgot()">Retrieve the password</button> <button type="button" onclick="UserScan()">Scan code to log in</button> <button type="button" onclick="UserQuit()">Log out</button>
<a href="<?php $this->options->adminUrl('login.php'); ?> "><? Php _e ('Login ');?></ a>
<a href="javascript:;" onclick="UserLogin()" ><? Php _e ('log in ');?></ a>
<a href="javascript:;" onclick="openApp ('? Info=<? Php echo $this ->cid;?>')">Read in APP</a>
Scheme 1: PHP takeover (simple and fast, requiring PHP foundation)
function toLogin($token,$uid){ //If it does not exist, write the cookie Typecho_Cookie::set('__typecho_token', $token); Typecho_Cookie::set('__typecho_token_uid', $uid); if($uid==0){ Typecho_Cookie::set('__typecho_token', 0); Typecho_Cookie::set('__typecho_token_uid', 0); Typecho_Cookie::delete('__typecho_token'); Typecho_Cookie::delete('__typecho_token_uid'); } } function getLogin(){ if (empty($recording = Typecho_Cookie::get('__typecho_token'))) { return 0; } else { $uid = Typecho_Cookie::get('__typecho_token_uid'); return $uid; } } function quitUser(){ Typecho_Cookie::set('__typecho_token', 0); Typecho_Cookie::set('__typecho_token_uid', 0); Typecho_Cookie::delete('__typecho_token'); Typecho_Cookie::delete('__typecho_token_uid'); } //Get user information according to fields function userInfo($value,$uid) { $db = Typecho_Db::get(); $prow = $db->fetchRow($db->select($value)->from('table.users')->where('uid = ?', $uid)); $text = $prow[$value]; return $text; }
<? php if (! defined('__TYPECHO_ROOT_DIR__')) exit; ?>
<? php if (! defined('__TYPECHO_ROOT_DIR__')) exit; if(isset( $_POST["token"])){ $token = $_POST["token"]; $uid = $_POST["uid"]; toLogin($token,$uid); } if(isset( $_GET["quit"])){ toLogin(0,0); } ?>
<? php if(getLogin()!= 0): ?> //Logged in <? php else : ?> //Not logged in <? php endif; ?>
<? php echo getLogin(); ?> // Output Member ID <? php echo userInfo('mail',getLogin()); ?> // Member Email <? php echo userInfo('name',getLogin()); ?> // Member user name <? php echo userInfo('screenName',getLogin()); ?> // Member nickname <? php echo userInfo('url',getLogin()); ?> // Member website <? php echo userInfo('group',getLogin()); ?> // Member user group <? php echo userInfo('assets',getLogin()); ?> // Member Assets //In short, all the fields in the user table of the database can be called out
<button type="submit" class="submit"><? Php _e ('submit comments');?></ button>
<button type="button" class="submit" onclick="addComments(<?php echo $this->cid; ?>,'#new_comment_form')"><? Php _e ('submit comments');?></ button>
onclick="addComments(<?php echo $this->cid; ?>,'#new_comment_form')"
Scheme II: js mode (JS foundation is required)
if(localStorage.getItem("token")){ //Logged in }else{ //Not logged in }
<div class="login" id="login"> </div>
var html=``; if(localStorage.getItem("token")){ var userData = JSON.parse(localStorage.getItem('userinfo')); if(userInfo.screenName){ name = userInfo.screenName; } html = ` <a href="javascript:;" id="auStats" class="dropdown-toggle"><img src="${userData.avatar}" width="32px" height="32px" class="navtar" > ${userData.name} </a> <div class="austats" id="aus"> <ul> <li><a href="javascript:;" onclick="UserQuit()"><i class="icon iconfont icon shibai"></i>Log out</a></li> </ul> </div> ` }else{ html=` <i class="icon iconfont icon-zengjia"></i><a href="javascript:;" onclick="UserLogin()"><? Php _e ('log in ');?></ a> `; } $("#login").html(html);
Front end submission js reference:
function toLogin(){ var username = $("#username").val(); var userpass = $("#userpass").val(); if(username==""||userpass==""){ Layer.msg ("Please input correct parameters", {icon: 2}); return false; } var data = { name: username, password: userpass, } var index = layer.load(1, { shade: [0.4,'#000'] }); $.ajax({ type : "post", data:{"params":JSON.stringify(API.removeObjectEmptyKey(data))}, url : API.userLogin(), dataType: 'json', success : function(result) { layer.close(index); if(result.code==1){ Layer. msg ("Login succeeded!", {icon: 1}); //Save user information localStorage.setItem('userinfo',JSON.stringify(result.data)); localStorage.setItem('token',result.data.token); //The following is responsible for synchronizing login status with typecho typechoLogin(result.data.token,result.data.uid,1); if(TypechoUserLogin==0){ var timer = setTimeout(function() { location.reload(); clearTimeout('timer') }, 1000) } }else{ layer.msg(result.msg, {icon: 2}); } }, error : function(e){ layer.close(index); Layer. alert ("Request failed, please check the network", {icon: 2}); } }); }
function addComments(cid,sumbit){ //Judge whether the user information exists var token; if(localStorage.getItem("token")){ token = localStorage.getItem("token"); }else{ //If it doesn't exist, go to typecho's default comment login $(sumbit).submit(); return false; } //Superior comment ID and typocho template are basically the following ID var coid = $("#comment-parent").val(); var text = $("#RuleText").val(); if(coid==""||cid==""||text==""){ Layer.msg ("Please input correct parameters", {icon: 2}); return false; } var data = { "cid":cid, "parent":coid, "text":text, } var index = layer.load(1, { shade: [0.4,'#000'] }); $.ajax({ type : "post", url: API.setComments(), data:{ "params":JSON.stringify(API.removeObjectEmptyKey(data)), "token":token }, dataType: 'json', success : function(result) { layer.close(index); if(result.code==1){ Layer. msg ("Publish successfully!", {icon: 1}); var timer = setTimeout(function() { location.reload(); clearTimeout('timer') }, 1000) }else{ layer.msg(result.msg, {icon: 2}); } }, error : function(e){ layer.close(index); Layer. alert ("Request failed, please check the network", {icon: 2}); } }); }
One more point
last