用户认证
登录注册
php artisan make:auth
会在routes/web下面生成,也会生成相关页面[这里view就不做介绍了]
Auth::routes();
Route::get('/home', 'HomeController@index')->name('home');
Auth::routes(); 这个就是laravel的用户认证路由 定义地方 vendor/laravel/framework/src/Illuminate/Routing/Router.php
public function auth(array $options = [])
{
$this->get('login', 'Auth\LoginController@showLoginForm')->name('login');
$this->post('login', 'Auth\LoginController@login');
$this->post('logout', 'Auth\LoginController@logout')->name('logout');
if ($options['register'] ?? true) {
$this->get('register', 'Auth\RegisterController@showRegistrationForm')->name('register');
$this->post('register', 'Auth\RegisterController@register');
}
if ($options['reset'] ?? true) {
$this->resetPassword();
}
if ($options['verify'] ?? false) {
$this->emailVerification();
}
}
public function resetPassword()
{
$this->get('password/reset', 'Auth\ForgotPasswordController@showLinkRequestForm')->name('password.request');
$this->post('password/email', 'Auth\ForgotPasswordController@sendResetLinkEmail')->name('password.email');
$this->get('password/reset/{token}', 'Auth\ResetPasswordController@showResetForm')->name('password.reset');
$this->post('password/reset', 'Auth\ResetPasswordController@reset')->name('password.update');
}
public function emailVerification()
{
$this->get('email/verify', 'Auth\VerificationController@show')->name('verification.notice');
$this->get('email/verify/{id}', 'Auth\VerificationController@verify')->name('verification.verify');
$this->get('email/resend', 'Auth\VerificationController@resend')->name('verification.resend');
}
可以直接使用,也可以把这些路由直接copy到web.php中
Route::get('login', 'Auth\LoginController@showLoginForm')->name('login');
Route::post('login', 'Auth\LoginController@login');
Route::post('logout', 'Auth\LoginController@logout')->name('logout');
Route::get('register', 'Auth\RegisterController@showRegistrationForm')->name('register');
Route::post('register', 'Auth\RegisterController@register');
Route::get('password/reset', 'Auth\ForgotPasswordController@showLinkRequestForm')->name('password.request');
Route::post('password/email', 'Auth\ForgotPasswordController@sendResetLinkEmail')->name('password.email');
Route::get('password/reset/{token}', 'Auth\ResetPasswordController@showResetForm')->name('password.reset');
Route::post('password/reset', 'Auth\ResetPasswordController@reset')->name('password.update');
Route::get('email/verify', 'Auth\VerificationController@show')->name('verification.notice');
Route::get('email/verify/{id}', 'Auth\VerificationController@verify')->name('verification.verify');
Route::get('email/resend', 'Auth\VerificationController@resend')->name('verification.resend');
语言包
composer require overtrue/laravel-lang
- 根据config/app.php的locale选项选择语言
- 如果想修改扩展包语言,可以使用以下命令发布语言文件到项目
php artisan lang:publish zh-CN
验证码
composer require mews/captcha
目前只支持 laravel5&6
php artisan vendor:publish --provider='Mews\Captcha\CaptchaServiceProvider'
生成config/captcha.php
邮箱认证
图片裁剪
composer require intervention/image
php artisan vendor:publish --provider="Intervention\Image\ImageServiceProviderLaravel5"
xss
composer require mews/purifier
php artisan vendor:publish --provider="Mews\Purifier\PurifierServiceProvider"
会生成 config/purifier.php
http请求套件
composer require guzzlehttp/guzzle
中文转拼音
composer require overtrue/pinyin
消息通知
php artisan make:notification Message
生成消息类 via方法决定发生用哪个频道,database数据库,email,邮箱 如果是数据库 roDatabase($notifiable) 是一个实例。返回数组,会自动转为json数据
获取用户的登录时间
- 用户登录之后,获取当日日期,以当日日期创建hash表 比如 user_denglu_2021-07-28
- 键名为 user_$id ,
- 写入redis
Redis::hSet(哈希表, 键名, 当前时间); [存在就会更新] - 写一个脚本每日凌晨0点执行
- 内容为,获取昨日日期得到hash表,获取表中所有数据,循环比对数据,把时间更新到user表的最后登陆时间字段
- 执行完成之后删除hash表
|