Home php教程 php手册 Codeigniter整合Tank Auth权限类库详解

Codeigniter整合Tank Auth权限类库详解

Jun 13, 2016 am 09:33 AM
codeigniter

相交其他CodeIgniter的类库,tank_auth,配置简单,使用也简单,并且作者也一直在更新,现在是1.0.9。1.0.8已经支持CI2.0了,我现在一般的项目都是用它,所以推荐给大家。

安装Tankauth的步骤

下载最新版类库(下载地址:http://www.konyukhov.com/soft/tank_auth/tank_auth.zip)

解压文件
将application下相应的文件复制到你的CIapplication文件夹下。
将captcha文件夹复制到你的CI文件夹(项目目录,和application同一个目录)下.并确保该目录在web服务器下可写。
在你的MySQL数据库里安装数据库(schema.sql文件)结构。
在你的CI项目下打开application/config/config.php文件,并且把$config['sess_use_database']的值改为TRUE.
安装完成!

如果访问出现如下错误:

AnErrorWasEncountered
InordertousetheSessionclassyouarerequiredtosetanencryptionkeyinyourconfigfile.

这个错误提示需要一个密钥。那么打开config.php,在$config['encryption_key']后面,随便加一个密钥即可。

TankAuth官网地址:http://www.konyukhov.com/soft/tank_auth/

如果出现了错误,不要忘记看配置文件(tank_auth.php和email.php),安装完成后类库应该可以完美工作了,但是根据你的服务器的条件和你的需要,最好有选择性的修改一下。

提示:默认情况下,类库产生强大的系统特定的密码哈系值是不可移植的,这就是说一旦创建,用户数据库就不能导出并导入到其他数据库中,这个特性也可以通过配置文件修改。

Tankauth类库的简单说明

类库运用了MVC模型,这也就是说所有的数据库相关的方法都封装在了模型(model)文件中,并且类库本身作也为了这些方法的接口。控制器(auth)处相关请求,并调用类库中的方法,渲染相应的视图(view)(显示在浏览器中或以email方式发送)。控制器包含如下的方法:

login:用户登录网站。如果登录成功,并且用户账户是激活的,用户将被重定向到首页。如果未被激活,send_again将被调用(看下面)。如果登录失败,用户将继续留在相同页面(登录页面);
logout:注销用户。
register:注册用户到网站。如果注册成功,将创建一个用户账户。如果在配置文件中的email_activation项的值被设置为TRUE,则用户需要通过点击发送到email中的特殊连接激活账户;否则默认激活。请注意:注册完后用户并没有通过登录验证,仍然需要登录。
send_again:再次发送激活email到相同或者新的email地址。当为激活用户登录是,每次调用这个方法。当用户由于信箱的问题或者错误的emial地址未收到信件时,这个功能是非常有用的。用户可以改变他们的email或者保持不变。
activate:激活用户账户。通常这个方法是通过点击email中的链接调用激活的。可以通过点击”forgotpassword”,输入email来激活账户。用户是通过在URL中的用户的Id和验证码来认证的。
forgot_password:生成特殊的重置码(为了修改密码)并发送给用户。很显然用户在忘记密码的时候才会用到该方法。
reset_password:用一个新的(用户设置的)密码替换旧的(忘记的)密码。这个方法可以通过点击邮件中的连接调用。用户是通过在URL中的用户的Id和验证码来认证的。
change_password:“正常的”密码修改(相比于重置密码)。只能在用户登录并且激活的时候才可调用。为了保证安全,仍然需要验证用户秘密。
change_email:修改用户的email。只能在用户登录并且激活的时候才可调用。为了保证安全,仍然需要验证用户秘密。这个新的email只有通过点击发到这个email中的链接才能被激活。
reset_email:激活新email地址并用一个新的email地址替换。可以通点击邮件中的链接调用该方法。用户是通过在URL中的用户的Id和验证码来认证的。
unregister:删除用户账户。只能在用户登录并且激活的时候才可调用。为了保证安全,仍然需要验证用户秘密。

既然auth控制器管理用户的所以方法(包括登录和注销),所以你未必一定要直接调用类库中的方法。但是下面这些是一定要调用的:

is_logged_in:检测用户是否登录网站。
get_user_id:如果用户登录,获得用户Id,否则返回FALSE。
get_username:获得验证用户的用户名,否则返回FALSE。如果该用户名没有注册,调用这个方法是无意义的(这时候任何用户都将返回一个空的字符串)。

Statement of this Website
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to implement custom middleware in CodeIgniter How to implement custom middleware in CodeIgniter Jul 29, 2023 am 10:53 AM

How to implement custom middleware in CodeIgniter Introduction: In modern web development, middleware plays a vital role in applications. They can be used to perform some shared processing logic before or after the request reaches the controller. CodeIgniter, as a popular PHP framework, also supports the use of middleware. This article will introduce how to implement custom middleware in CodeIgniter and provide a simple code example. Middleware overview: Middleware is a kind of request

CodeIgniter middleware: Accelerate application responsiveness and page rendering CodeIgniter middleware: Accelerate application responsiveness and page rendering Jul 28, 2023 pm 06:51 PM

CodeIgniter Middleware: Accelerating Application Responsiveness and Page Rendering Overview: As web applications continue to grow in complexity and interactivity, developers need to use more efficient and scalable solutions to improve application performance and responsiveness. . CodeIgniter (CI) is a lightweight PHP-based framework that provides many useful features, one of which is middleware. Middleware is a series of tasks that are performed before or after the request reaches the controller. This article will introduce how to use

How to use the database query builder (Query Builder) in the CodeIgniter framework How to use the database query builder (Query Builder) in the CodeIgniter framework Jul 28, 2023 pm 11:13 PM

Introduction to the method of using the database query builder (QueryBuilder) in the CodeIgniter framework: CodeIgniter is a lightweight PHP framework that provides many powerful tools and libraries to facilitate developers in web application development. One of the most impressive features is the database query builder (QueryBuilder), which provides a concise and powerful way to build and execute database query statements. This article will introduce how to use Co

Use PHP framework CodeIgniter to develop a real-time chat application to provide convenient communication services Use PHP framework CodeIgniter to develop a real-time chat application to provide convenient communication services Jun 27, 2023 pm 02:49 PM

With the development of mobile Internet, instant messaging has become more and more important and popular. For many companies, live chat is more like a communication service, providing a convenient communication method that can quickly and effectively solve business problems. Based on this, this article will introduce how to use the PHP framework CodeIgniter to develop a real-time chat application. Understand the CodeIgniter framework CodeIgniter is a lightweight PHP framework that provides a series of simple tools and libraries to help developers quickly

CodeIgniter middleware: Provides secure file upload and download functions CodeIgniter middleware: Provides secure file upload and download functions Aug 01, 2023 pm 03:01 PM

CodeIgniter middleware: Provides secure file upload and download functions Introduction: In the process of web application development, file upload and download are very common functions. However, for security reasons, handling file uploads and downloads often requires additional security measures. CodeIgniter is a popular PHP framework that provides a wealth of tools and libraries to support developers in building secure and reliable web applications. This article will introduce how to use CodeIgniter middleware to implement secure files

PHP development: Using CodeIgniter to implement MVC pattern and RESTful API PHP development: Using CodeIgniter to implement MVC pattern and RESTful API Jun 16, 2023 am 08:09 AM

As web applications continue to evolve, it is important to develop applications more quickly and efficiently. And, as RESTful API is widely used in web applications, it is necessary for developers to understand how to create and implement RESTful API. In this article, we will discuss how to implement MVC pattern and RESTful API using CodeIgniter framework. Introduction to MVC pattern MVC (Model-Vie

How to use CodeIgniter5 framework in php? How to use CodeIgniter5 framework in php? Jun 01, 2023 am 11:21 AM

CodeIgniter is a lightweight PHP framework that uses MVC architecture to support rapid development and simplify common tasks. CodeIgniter5 is the latest version of the framework and offers many new features and improvements. This article will introduce how to use the CodeIgniter5 framework to build a simple web application. Step 1: Install CodeIgniter5 Downloading and installing CodeIgniter5 is very simple, just follow these steps: Download the latest version

How does php use CodeIgniter\Config for configuration management? How does php use CodeIgniter\Config for configuration management? Jun 02, 2023 pm 06:01 PM

1. Introduction to CodeIgniter CodeIgniter is a lightweight and comprehensive PHP development framework designed to provide web developers with fast and powerful tools to build web applications. It is an open source framework that uses the MVC architecture pattern to achieve rapid development and basic functions, while supporting a variety of databases. 2. Introduction to the Config library The Config library is a component in the CodeIgniter framework and is used to configure and manage code. The Config library contains many

See all articles