Home  >  Article  >  CMS Tutorial  >  How discuz implements automatic registration and login

How discuz implements automatic registration and login

咔咔
咔咔Original
2020-05-03 21:38:345048browse

Functions implemented in this article:

1. Enter the forum from the original system to automatically log in and register

2. Implement pop-up boxes on this page without jumping

3.js directly initiates a registration request when the page is loaded

This function was previously handled by the uc_user_register function, but today it will be used when developing user space problem appear.

Project requirements

Add a forum to our original system, but user information needs to be shared.

Implementation method: Bring the user information of the original system when entering the forum, and then get the information from the forum and register directly.

Enter the forum from the original system to automatically register and log in

Prepare such a buffer page and put it in upload/template/default/touch/member/ In the page of register.htm

How discuz implements automatic registration and login

then we need to put the original registration code into upload/template/default /touch/member/register.htm

The reason for putting this code is thatdsicuzThere will be many parameter restrictions when submitting the form, we can just keep it as it is.

<form method="post" autocomplete="off" name="register" id="registerform" action="member.php?mod={$_G[setting][regname]}&mobile=2">
   <input type="hidden" name="regsubmit" value="yes" />
   <input type="hidden" id="hash" name="formhash" value="{FORMHASH}" />
   <!--{eval $dreferer = str_replace(&#39;&&#39;, &#39;&&#39;, dreferer());}-->
   <input type="hidden" id="referer" name="referer" value="$dreferer" />
   <input type="hidden" name="activationauth" value="{if $_GET[action] == &#39;activation&#39;}$activationauth{/if}" />
   <input type="hidden" name="agreebbrule" value="$bbrulehash" id="agreebbrule" checked="checked" />
   <!--{if $_G[&#39;setting&#39;][&#39;sendregisterurl&#39;]}-->
   <input type="hidden" name="hash" value="$_GET[hash]" />
   <!--{/if}-->
   <!--{if $secqaacheck || $seccodecheck}-->
   <!--{subtemplate common/seccheck}-->
   <!--{/if}-->
   </div>
</form>

Then we need to directly send a request when the page is loaded, just add the following code.

Implement the pop-up box on this page, without jumping, and directly initiate a registration request when loading

The function implemented by this js code: directly initiate a registration request when the page is loaded, and then return the information , displayed directly on this page instead of jumping to another page

<script>
    var hash = $(&#39;#hash&#39;).val();
    var referer = $(&#39;#referer&#39;).val();
    $.ajax({
        type:&#39;POST&#39;,
        url:"member.php?mod={$_G[setting][regname]}&mobile=2" +&#39;&inajax=1&#39;,
        data:{
            "handlekey":"registerform",
            "inajax" : 1,
            "regsubmit" :"yes",
            "formhash":hash,
            "referer" :referer
        },
        dataType:&#39;xml&#39;
    })
        .success(function(s) {
            popup.open(s.lastChild.firstChild.nodeValue);
            evalscript(s.lastChild.firstChild.nodeValue);
        })
        .error(function() {
            window.location.href = obj.attr(&#39;href&#39;);
            popup.close();
        });
</script>

The last step required at this time is what form to use to transmit it from the original system. This method is not provided here. I will make a simulated data.

Add your own code according to the comments in the upload/source/module/member/member_register.php method on_register

How discuz implements automatic registration and login

Test the effect

We register a ceshi123 account

How discuz implements automatic registration and login

Test post

How discuz implements automatic registration and login

##Why not useuc_user_register The reason for this method to register users

If

uc_user_register is used to register users directly, all the following information will not be obtained

How discuz implements automatic registration and login

The above is the detailed content of How discuz implements automatic registration and login. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn