gponster / laravel-auth-file
基于文件的认证驱动器
v1.0
2015-01-14 06:07 UTC
Requires
- php: >=5.4.0
- illuminate/support: 4.x
This package is not auto-updated.
Last update: 2024-09-24 16:04:28 UTC
README
- Laravel: 4.2
- 作者: Gponster
此包不是laravel默认Auth库的替代品,它是一个简单的认证驱动器,使用基于配置文件的数据库来存储用户名和密码。
安装
首先,您需要在composer.json文件中包含此包。
"require": {
"gponster/laravel-auth-file": "dev-master"
}
现在您可以通过composer更新或安装。
composer update
接下来,打开app/config/app.php,将AuthServiceProvider替换为
'Gonster\Auth\File\AuthServiceProvider',
注意 替换默认服务提供者非常重要。如果您不希望使用提醒,请删除原始的Reminder服务提供者,否则会导致错误。
配置也很简单,使用app/config/auth.php及其默认值
return array(
'driver' => 'eloquent',
'model' => 'User',
'table' => 'users',
'reminder' => array(
'email' => 'emails.auth.reminder',
'table' => 'password_reminders',
'expire' => 60,
),
);
将认证驱动器替换为'file'
'driver' => 'file',
'model' => 'AuthUser',
'username' => 'email',
'password' => 'password',
简单的AuthUser类
use Illuminate\Auth\UserInterface; use Illuminate\Auth\Reminders\RemindableInterface; use Illuminate\Auth\GenericUser; class AuthUser extends GenericUser implements UserInterface, RemindableInterface { public static $rules = array( 'email'=>'required|email', 'password'=>'required|alpha_num|between:6,12|confirmed', ); /** * Dynamically access the user's attributes. * * @param string $key * @return mixed */ public function getAttribute($key) { return $this->__get($key); } /** * Get the unique identifier for the user. * * @return mixed */ public function getAuthIdentifier() { return $this->attributes['email']; } /** * Get the password for the user, needs to return the hashed password * * @return string */ public function getAuthPassword() { return $this->attributes['password']; } /** * Get the e-mail address where password reminders are sent. * * @return string */ public function getReminderEmail() { return $this->attributes['email']; } }