Codeigniter Integration Tank Auth Permission Class Library Detailed Explanation

  • 2021-07-01 06:45:54
  • OfStack

Intersecting with other CodeIgniter class libraries, tank_auth, it is simple to configure and use, and the author is also updating it, which is now 1.0. 9. 1.0. 8 already supports CI 2.0, and I now use it for all my projects, so I recommend it to you.

To install Tankauth

Download the latest version of the class library (download address: http://www.konyukhov.com/soft/tank_auth/tank_auth. zip)

Extract a file
Copy the corresponding files under application to your CIapplication folder.
Copy the captcha folder to your CI folder (project directory, same directory as application). Make sure the directory is writable under the web server.
Install the database structure (schema. sql file) in your MySQL database.
Open the file application/config/config. php under your CI project and change the value of $config ['sess_use_database'] to TRUE.
Installation complete!

If the following error occurs in the access:

AnErrorWasEncountered
InordertousetheSessionclassyouarerequiredtosetanencryptionkeyinyourconfigfile.

This error prompt requires 1 key. Then open config. php and add a key after $config ['encryption_key'].

TankAuth official website address: http://www.konyukhov.com/soft/tank_auth/

If there is an error, don't forget to look at the configuration files (tank_auth. php and email. php). The class library should work perfectly after installation, but according to the conditions of your server and your needs, it is best to modify it selectively.

Tip: By default, the powerful system-specific password values generated by class libraries are not portable, which means that once created, the user database cannot be exported and imported into other databases, and this feature can also be modified through configuration files.

A Brief Description of the Tankauth Class Library

The class library uses the MVC model, which means that all database-related methods are encapsulated in the model (model) file, and the class library itself acts as an interface for these methods. The controller (auth) calls the method in the class library and renders the corresponding view (view) (displayed in the browser or sent as email). The controller includes the following methods:

login: The user logs in to the Web site. If the login is successful and the user account is active, the user will be redirected to the home page. If it is not activated, send_again will be called (see below). If login fails, the user will remain on the same page (login page);
logout: Log off the user.
register: Register users to the Web site. If the registration is successful, a user account will be created. If the value of email_activation item in the configuration file is set to TRUE, the user needs to activate the account by clicking on the special connection sent to email; Otherwise, it is activated by default. Please note: After registration, the user has not passed the login authentication, and still needs to log in.
send_again: Send the active email again to the same or new email address. This method is called every time the user is logged in for activation. This is useful when a user does not receive a message due to a mailbox problem or an incorrect emial address. Users can change their email or leave it unchanged.
activate: Activate the user account. Usually this method is activated by clicking the link call in email. Account can be activated by clicking "forgotpassword" and entering email. The user is authenticated by the user's Id and verification code in URL.
forgot_password: Generates a special reset code (to change the password) and sends it to the user. Obviously, users only use this method when they forget their passwords.
reset_password: Replace the old (forgotten) password with a new (user-set) password. This method can be called by clicking the connection in the mail. The user is authenticated by the user's Id and verification code in URL.
change_password: "Normal" password change (as opposed to password reset). It can only be called when the user is logged in and activated. In order to ensure security, it is still necessary to verify user secrets.
change_email: Modify the user's email. It can only be called when the user is logged in and activated. In order to ensure security, it is still necessary to verify user secrets. This new email can only be activated by clicking the link sent to this email.
reset_email: Activates the new email address and replaces it with a new email address. You can call this method by clicking the link in the message. The user is authenticated by the user's Id and verification code in URL.
unregister: Delete user account. It can only be called when the user is logged in and activated. In order to ensure security, it is still necessary to verify user secrets.

Since the auth controller manages all of the user's methods (including login and logout), you don't necessarily have to call the methods in the class library directly. But the following are what 1 must call:

is_logged_in: Detects whether the user is logged on to the Web site.
get_user_id: If the user logs in, get the user Id, otherwise return FALSE.
get_username: Gets the username of the authenticated user, otherwise returns FALSE. If the user name is not registered, it is meaningless to call this method (any user will return an empty string at this time).


Related articles: