Interconnect other CodeIgniter class libraries, tank_auth, which are easy to configure and use, and the author has been updating them. This article mainly introduces how to integrate the TankAuth permission class library with Codeigniter. If you need it, you can refer to the class libraries that interwork with other CodeIgniter. tank_auth is easy to configure and use, and the author has been updating it, it is 1.0.9 now. 1.0.8 already supports CI2.0, so I recommend it to you for general projects.
Install Tankauth
Download the latest class library (: http://www.konyukhov.com/soft/tank_auth/tank_auth.zip)
Decompress the file
Copy the corresponding files under the application to your CIapplication folder.
Copy the captcha folder to your CI folder (the project directory, the same as the application directory) and make sure that the directory is writable under the web server.
Install the database (schema. SQL file) structure in your MySQL database.
Open the application/config. php file in your CI project, and change the value of $ config ['sess _ use_database '] to TRUE.
Installation complete!
If the following error occurs during access:
AnErrorWasEncountered
InordertousetheSessionclassyouarerequiredtosetanencryptionkeyinyourconfigfile.
This error indicates that a key is required. Open config. php and add a key after $ config ['encryption _ key.
TankAuth official website address:Http://www.konyukhov.com/soft/tank_auth/
If an error occurs, do not forget to check the configuration file (tank_auth.php and email. php). After the installation is complete, the class library should work perfectly. But it is best to modify the library according to your server conditions and your needs.
Tip: by default, the Class Library generates a powerful system-specific password and The HSR value cannot be transplanted. This means that once created, the user database cannot be exported and imported to other databases, this feature can also be modified through the configuration file.
Brief description of Tankauth class library
The class library uses the MVC model, which means that all database-related methods are encapsulated in the model file, and the class library itself serves as an interface for these methods. Request from the Controller (auth), call the method in the class library, and render the view (displayed in the browser or sent by email ). The controller includes the following methods:
Login: log on to the website. If the logon succeeds and the user account is activated, the user will be redirected to the home page. If it is not activated, send_again will be called (see below ). If logon fails, the user will remain on the same page (logon page );
Logout: log out of the user.
Register: register a user to the website. If the account is successfully registered, a user account is created. If the value of the email_activation item in the configuration file is set to TRUE, You need to click a special connection sent to the email to activate the account; otherwise, the account is activated by default. Note: after registration, the user does not pass the logon verification and still needs to log on.
Send_again: Send an activation email to the same or new email address. This method is called every time you log on to activate a user. This function is useful when a user does not receive a letter due to a mailbox problem or incorrect emial address. Users can change their email or remain unchanged.
Activate: activate the user account. This method is usually activated by clicking the link in the email. You can click "forgotpassword" and enter email to activate the account. Users are authenticated by the user Id and verification code in the URL.
Forgot_password: generate a special reset code (to change the password) and send it to the user. Obviously, this method is used only when the user forgets the password.
Reset_password: replace the old (forgot) password with a new (User-set) password. This method can be called by clicking the connection in the email. Users are authenticated by the user Id and verification code in the URL.
Change_password: "normal" Password Change (compared to password reset ). Users can only be called upon logon and activation. To ensure security, you still need to verify the user's secret.
Change_email: Modify the user's email. Users can only be called upon logon and activation. To ensure security, you still need to verify the user's secret. This new email can be activated only by clicking the link sent to this email.
Reset_email: Activate the new email address and replace it with a new email address. You can call this method by clicking the link in the email. Users are authenticated by the user Id and verification code in the URL.
Unregister: deletes a user account. Users can only be called upon logon and activation. To ensure security, you still need to verify the user's secret.
Since the auth controller manages the user's methods (including logon and logout), you may not have to directly call the methods in the class library. However, the following must be called:
Is_logged_in: checks whether users log on to the website.
Get_user_id: if the user logs on, the user ID is obtained; otherwise, FALSE is returned.
Get_username: Obtain the User Name of the authenticated user; otherwise, FALSE is returned. If the user name is not registered, calling this method is meaningless (at this time, any user will return an empty string ).