企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
# 5. 简单的用户认证 > 2017\.08.09 updated, 增加了动图,修改文字 上一篇文章 [Ruby 程序员学习 laravel 框架笔记 (4)-在数据库中创建一条数据](https://www.rails365.net/articles/ruby-cheng-xu-yuan-xue-xi-laravel-kuang-jia-bi-ji-4-zai-shu-ju-ku-zhong-chuang-jian-yi-tiao-shu-ju) 有讲过创建一条 user 记录,其实这个相当于注册功能,今天要学习的就是跟这个注册功能有关。 laravel 神奇的一个地方就是默认集成了登录和注册的功能,只要一条指令就可以启动,不仅如此,连 view 都给你写好了,也就是说界面都可以不用写,就有登录和注册的功能。 ![](https://box.kancloud.cn/e82d5eb826def265c4bc9b0d4a4c4e2f_2212x1328.gif) ## 1. 启用登录注册功能 只要一条指令: ``` php artisan make:auth ``` 我们来查一下路由,看到底产生了些啥功能: ``` php artisan route:list ``` 输出如下: ``` +--------+----------+------------------------+------------------+------------------------------------------------------------------------+--------------+ | Domain | Method | URI | Name | Action | Middleware | +--------+----------+------------------------+------------------+------------------------------------------------------------------------+--------------+ | | GET|HEAD | / | | Closure | web | | | GET|HEAD | api/user | | Closure | api,auth:api | | | GET|HEAD | home | home | App\Http\Controllers\HomeController@index | web,auth | | | GET|HEAD | login | login | App\Http\Controllers\Auth\LoginController@showLoginForm | web,guest | | | POST | login | | App\Http\Controllers\Auth\LoginController@login | web,guest | | | POST | logout | logout | App\Http\Controllers\Auth\LoginController@logout | web | | | POST | password/email | password.email | App\Http\Controllers\Auth\ForgotPasswordController@sendResetLinkEmail | web,guest | | | GET|HEAD | password/reset | password.request | App\Http\Controllers\Auth\ForgotPasswordController@showLinkRequestForm | web,guest | | | POST | password/reset | | App\Http\Controllers\Auth\ResetPasswordController@reset | web,guest | | | GET|HEAD | password/reset/{token} | password.reset | App\Http\Controllers\Auth\ResetPasswordController@showResetForm | web,guest | | | GET|HEAD | register | register | App\Http\Controllers\Auth\RegisterController@showRegistrationForm | web,guest | | | POST | register | | App\Http\Controllers\Auth\RegisterController@register | web,guest | | | GET|HEAD | users | | App\Http\Controllers\UsersController@index | web | | | POST | users | | App\Http\Controllers\UsersController@store | web | | | GET|HEAD | users/create | | App\Http\Controllers\UsersController@create | web | +--------+----------+------------------------+------------------+------------------------------------------------------------------------+--------------+ ``` ## 2. 展示功能 现在我们来验证一下这些功能。 打开浏览器,输入 `http://127.0.0.1/login`。 页面是这样子的: ![](https://box.kancloud.cn/0474ff0bb867547ee64ec58e4f565d72_2660x896.png) 页面还不错。 注册页面也有: ![](https://box.kancloud.cn/50308d66ab613bedf00aea49b6e446bc_2612x1010.png) 注册完会自动登录,登录后的页面如下: ![](https://box.kancloud.cn/0d10897ce9455f4b22f61d150102c94a_2638x568.png) 完结。 下一篇:[Ruby 程序员学习 laravel 框架笔记 (6)-修改 User model](https://www.rails365.net/articles/ruby-cheng-xu-yuan-xue-xi-laravel-kuang-jia-bi-ji-6-xiu-gai-user-model)