ThinkPHP + Discuz integration method

Source: Internet
Author: User

ThinkPHP + Discuz integration method
The following is the integration method of Discuz6. For discuz5, follow the instructions in the preceding section to modify and use it.

1. Enter PublicAction. class. php in the action Directory of the project. Write as follows:
Code: copy the content to the clipboard
Class PublicAction extends Action

{

Function login ()

    {

$ This-> display ();

If (! Isset ($ _ SESSIONC ('User _ AUTH_KEY ') | $ _ SESSIONC ('User _ AUTH_KEY') = 0 ){

$ This-> display ();

Return;

} Else {

Redirect (_ APP __);

       }

    }

Function index ()

{

// Jump to the homepage after authentication

Redirect (_ APP __);

}

Function checkLogin ()

    {

// Here, the user name, password, and status are used for authentication. Here is discuz6.1, and the discuz5 encryption method is different. If discuz5 is used, you need to modify the following sentence.

// NOTE !!! It is not safe to directly put $ _ POST ['name'] and $ _ POST ['password'] into the query statement. Please handle it first! I handled it myself, but there is no post here. I am looking for the processing functions in ThinkPHP, but I have not found them yet.

$ AuthInfo = RBAC: authenticate ("'username' = '". $ _ POST ['name']. "'AND 'password' = md5 (concat (md5 ('". $ _ POST ['password']. "'), 'salt '))");

If (false ===$ authInfo ){

Echo 'logon failed. Check whether the user name and password are correct! ';

} Else {

// Set the authentication ID

Session_register (C ('User _ AUTH_KEY '));

Session_register ('loginid ');

$ _ SESSION [C ('User _ AUTH_KEY ')] = $ authInfo ["uid"]; // id field of the USER table

$ _ SESSION ["loginid"] = $ authInfo ["username"]; // the username field in the user table

// Obtain and save the user access permission list

RBAC: saveAccessList ();

Dump ($ _ SESSION );

Echo strtoupper (APP_NAME). "". strtoupper (MODULE_NAME). "". strtoupper (ACTION_NAME );

  }

    }

}
2. Then add a login template in the template. The path is Tpl/default/Public/Login.html. Paste the template in the official tutorial here, saving your time and searching:
Code: copy the content to the clipboard
<Body>

<Form method = post name = "login" id = "form1" action = "_ URL _/checkLogin">

<Div class = "tcenter hmargin">

<Table id = "checklist" class = "login shadow" cellpadding = 0 cellspacing = 0>

<Tr> <td height = "5" colspan = "2" class = "toptd"> </td> </tr>

<Tr class = "row"> <th colspan = "2" class = "tcenter space"> System Management logon </th> </tr>

<Tr> <td height = "5" colspan = "2" class = "toptd"> </td> </tr>

<Tr class = "row"> <td colspan = "2" class = "tcenter"> <div id = "result" class = "result none"> </div> </td> </tr>

<Tr class = "row"> <td class = "tright" width = "25%"> Account number: </td> <input type = "text" class = "medium bleftrequire" check = "require" warning = "enter an account" name = "name"> </ td> </tr>

<Tr class = "row"> <td class = "tright"> password: </td> <input type = "password" class = "medium bleftrequire" check = "require" warning = "enter the password" name = "password"> </ td> </tr>

<Tr class = "row"> <td class = "tcenter" align = "justify" colspan = "2">

<Input type = "button" value = "click New" onclick = "fleshverify () "class =" submit small "> <input type =" submit "value =" login "class =" submit small hmargin ">

<Input type = "reset" value = "reset" class = "submit small">

</Td> </tr>

<Tr> <td height = "5" colspan = "2" class = "bottomtd"> </td> </tr>

</Table>

</Div>

</Form>

</Body>
3. Add UserModel. class. php in the Model Directory.
The code is as follows:
Code: copy the content to the clipboard
Class UserModel extends Model

{

Protected $ trueTableName = 'UC _ members '; // The table name of the ucenter user table. If you modify the prefix in uc, change the uc part of the table name to your own.

 

}
4. You can log on. That's all. I read ThinkPHP documents for a whole day yesterday. TP is not very powerful. I personally feel much better than FLEAPHP.

If you are using the discuz5 version, because there is no ucenter, you need to modify the two parts.
First, in PublicAction. class. php
$ AuthInfo = RBAC: authenticate ("'username' = '". $ _ POST ['name']. "'AND 'password' = md5 (concat (md5 ('". $ _ POST ['password']. "'), 'salt '))");
Second, change 'UC _ members 'in UserModel. class. php to the corresponding data table.


5. Download RBAC.
In addition to the above, it is not enough. You must also grant permissions to RBAC. Here you need to download an official RBAC example, which is recommended to be placed in a directory at the same level as your program.

6. Modify RBAC
The content of UserModel. class. php under Model is the following code. This is consistent with UserModel. class. php. You can copy it directly.
Code: copy the content to the clipboard
Class UserModel extends Model

{

Var $ trueTableName = 'UC _ members ';

}
Modify the function user () in GroupAction. class. php ()
The code is as follows:
Code: copy the content to the clipboard
Function user ()

    {

// Read the user list of the system

// Modify the following three statements based on actual conditions:

$ UserDao = D ("User ");

$ List = $ userDao-> findAll ('', 'uid, username'); // Here we modified

$ UserList = $ userDao-> getCols ($ list, 'uid, username'); // here, do not change anything else.

$ GroupDao = D ("Group ");

$ List = $ groupDao-> findAll ('', 'id, name ');

$ GroupList = $ groupDao-> getCols ($ list, 'id, name ');

$ This-> assign ("groupList", $ groupList );

// Obtain information about the current user group

$ GroupId = isset ($ _ GET ['id'])? $ _ GET ['id']: '';

$ GroupUserList = array ();

If (! Empty ($ groupId )){

$ This-> assign ("selectGroupId", $ groupId );

// Obtain the user list of the current group

$ List = $ groupDao-> getGroupUserList ($ groupId );

$ GroupUserList = $ groupDao-> getCols ($ list, 'id, ID ');

               

  }

// $ UserList = array_diff_key ($ userList, $ groupUserList );

$ This-> assign ('groupuserlist', $ groupUserList );

$ This-> assign ('userlist', $ userList );

$ This-> display ();

Return;

    }
7. Now you can group data.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.