laravolt / auth
Laravel 扩展认证
Requires
- php: >=7.1.3
- anhskohbo/no-captcha: ^3.0.1
- doctrine/dbal: ~2.5
- illuminate/auth: 5.6.*|5.7.*|5.8.*|^6.0
- illuminate/mail: 5.6.*|5.7.*|5.8.*|^6.0
- illuminate/support: 5.6.*|5.7.*|5.8.*|^6.0
- laravolt/password: ^1.6
- laravolt/ui: ~0.5
Requires (Dev)
- mockery/mockery: ^1.0
- orchestra/database: ^3.4|^4.0
- orchestra/testbench-browser-kit: 3.6.*|3.7.*|3.8.*|^4.0
- phpunit/phpunit: ^7.0
Suggests
- adldap2/adldap2-laravel: Required if ldap login enabled
- subfission/cas: Required if cas login enabled
- dev-master / 5.0.x-dev
- v4.x-dev
- 4.10.5
- 4.10.4
- 4.10.3
- 4.10.2
- 4.10.1
- 4.10.0
- 4.9.3
- 4.9.2
- 4.9.1
- 4.9.0
- 4.8.4
- 4.8.3
- 4.8.2
- 4.8.1
- 4.8.0
- 4.7.0
- 4.6.17
- 4.6.16
- 4.6.15
- 4.6.14
- 4.6.13
- 4.6.12
- 4.6.11
- 4.6.10
- 4.6.9
- 4.6.8
- 4.6.7
- 4.6.6
- 4.6.5
- 4.6.4
- 4.6.3
- 4.6.2
- 4.6.1
- 4.6.0
- 4.5.1
- 4.5.0
- 4.4.3
- 4.4.2
- 4.4.1
- 4.4.0
- 4.3.2
- 4.3.1
- 4.3.0
- 4.2.1
- 4.2.0
- 4.1.0
- 4.0.0
- v2.x-dev
- 2.1.4
- 2.1.3
- 2.1.2
- 2.1.1
- 2.1.0
- 2.0
- 1.1
- 1.0.2
- 1.0.1
- 1.0.0
- 0.x-dev
- 0.6.x-dev
- 0.6
- 0.5
- 0.4
- 0.3
- 0.2
- 0.1
- dev-analysis-4xlADG
This package is auto-updated.
Last update: 2020-10-28 05:10:44 UTC
README
具有一些附加功能的 Laravel 认证
- 激活
- 启用/禁用注册
- 验证码
- 自定义电子邮件模板
- 功能测试
安装
- 运行
composer require laravolt/auth
- 对于 Laravel 5.4 或更低版本,添加
Laravolt\Auth\ServiceProvider::class
作为服务提供者 - 可选,您可以运行
php artisan vendor:publish --provider="Laravolt\Auth\ServiceProvider" --tag="migrations"
以发布迁移文件以便进一步编辑
配置
<?php return [ // Base layout to extend by every view 'layout' => 'ui::layouts.auth', // Enable captcha (Google reCaptcha) on login form 'captcha' => false, // Column name to be checked for authentication (login) 'identifier' => 'email', // Configuration related to login process 'login' => [ 'implementation' => \Laravolt\Auth\DefaultLogin::class, ], // Configuration related to registration process 'registration' => [ // Enable or disable registration form 'enable' => true, // Default status for newly registered user 'status' => 'ACTIVE', // During the process, data from registration form will be passed to this class. // You may create your own implementation by creating UserRegistrar class. 'implementation' => \Laravolt\Auth\DefaultUserRegistrar::class, ], // Configuration related to registration process 'activation' => [ // If enabled, newly registered user are not allowed to login until they click // activation link that sent to their email. 'enable' => false, // Status for newly registered user, before activation 'status_before' => 'PENDING', // Status for newly registered user, after successfully activate their account 'status_after' => 'ACTIVE', ], // Routes configuration 'router' => [ 'middleware' => ['web'], 'prefix' => 'auth', ], // Redirect configuration 'redirect' => [ // Where to redirect after successfully login 'after_login' => '/', // Where to redirect after successfully register 'after_register' => '/', // Where to redirect after successfully reset password 'after_reset_password' => '/', ], // Whether to auto load migrations or not. // If set to false, then you must publish the migration files first before running the migrate command 'migrations' => false, ];
验证码
如果您启用验证码(在配置文件中将 'captcha' => true
设置为 true),请将以下条目添加到 .env
NOCAPTCHA_SECRET=YOUR_RECAPTCHA_SECRET
NOCAPTCHA_SITEKEY=YOUR_RECAPTCHA_SITEKEY
您可以从 www.google.com/recaptcha/admin 获取它们。
自定义登录表单
修改表单(视图文件)
运行 php artisan vendor:publish --provider="Laravolt\Auth\ServiceProvider"
。您可以修改位于 resources/views/vendor/auth/login.blade.php
的视图。
修改逻辑
创建一个新类来处理用户登录,该类实现了 Laravolt\Auth\Contracts\Login
协议。您必须实现两个与注册相关的方法
rules(Request $request)
获取验证规则。credentials(Request $request)
检查有效凭证。可选authenticated(Request $request, $user)
处理登录后,应返回\Illuminate\Http\Response
或null
failed(Request $request)
处理自定义失败响应
自定义注册表单
有时您需要修改注册表单,例如添加更多字段、更改逻辑或添加一些验证。您可以通过几种方法来完成这些操作。
修改表单(视图文件)
运行 php artisan vendor:publish --provider="Laravolt\Auth\ServiceProvider"
。您可以修改位于 resources/views/vendor/auth/register.blade.php
的视图。
修改逻辑
创建一个新类来处理用户注册,该类实现了 Laravolt\Auth\Contracts\UserRegistrar
协议。您必须实现两个与注册相关的方法
validate($data)
处理验证逻辑。register($data)
处理用户创建逻辑。可选registered(Request $request, $user)
处理注册完成后,应返回\Illuminate\Http\Response
或null
<?php namespace App\Registration; use Illuminate\Support\Facades\Validator; use Laravolt\Auth\Contracts\UserRegistrar; class CustomUserRegistrar implements UserRegistrar { /** * Validate data. * * @param array $data */ public function validate(array $data) { // Modify default behaviour, or completely change it return Validator::make( $data, [ 'name' => 'required|max:255', 'email' => 'required|email|max:255|unique:users', 'password' => 'required|min:6', ] ); } /** * Create model. * * @param $ * */ public function register(array $data) { // create Authenticatable model. $user = User::create($data); // return Authenticatable model. return $user; } }
修改激活逻辑
通过将这些函数添加到您的注册器类中,将 Laravolt\Auth\Contracts\ShouldActivate
实现添加到您的 registration.implementation
类中。
notify(Model $user, $token)
activate($token)
... class CustomUserRegistrar implements UserRegistrar, ShouldActivate { ... /** * Notify if user to activate the user with the token provided. * * @param \Illuminate\Database\Eloquent\Model|Authenticatable $user * @param string $token * @return void */ public function notify(Model $user, $token) { // } /** * Activation method by the token provided. * * @param string $token * @return \Illuminate\Http\Response */ public function activate($token) { $token = \DB::table('users_activation')->whereToken($token)->first(); if (! $token) { abort(404); } \User::where('id', $token->user_id)->update(['status' => config('laravolt.auth.activation.status_after')]); \DB::table('users_activation')->where('user_id', $token->user_id)->delete(); return redirect()->route('auth::login')->withSuccess(trans('auth::auth.activation_success')); } }
之后,您必须更新认证配置(位于 config/laravolt/auth.php
,如果没有,只需运行 php artisan vendor:publish
)。
... 'registration' => [ // During the process, data from registration form will be passed to this class. // You may create your own implementation by creating UserRegistrar class. 'implementation' => \App\Registration\CustomUserRegistrar::class, ], ...
LDAP
环境变量
LDAP_HOSTS=ldap.forumsys.com
LDAP_BASE_DN='dc=example,dc=com'
LDAP_PORT=389
LDAP_USERNAME='cn=read-only-admin,dc=example,dc=com'
LDAP_PASSWORD='password'
LDAP_USE_SSL=false
LDAP_USE_TLS=false