登陆页面同时具有登录和注册功能

时间:2015-05-18 13:34:55

标签: php authentication laravel-5

我对Laravel很新。我正在尝试自定义内置的身份验证系统。

1)我希望登录表单和注册表单在同一页面上

2)我希望上面的页面显示在localhost:8000而不是localhost:8000 / auth / login而不是localhost:8000 / auth / register

2)更改表单字段。 (通过用户名登录,而不是通过电子邮件等登录。)

同样需要配置什么?

1 个答案:

答案 0 :(得分:1)

<强> 1 只需创建一个视图(例如home.blade.php)并插入两个表单。

<!-- Form 1 -->
<form role="form" method="POST" action="{{ url('/auth/login') }}"> ... </form>
<!-- Form 2 -->
<form role="form" method="POST" action="{{ url('/auth/register') }}"> ... </form>

2. :修改routes.php文件

Route::get('/', function()
{
    return \View::make('home.blade.php'); 
});

3。要通过用户名登录,请修改AuthenticatesAndRegistersUsers.php文件并在postLogin()方法中进行以下更改

$credentials = $request->only('name', 'password');

...

return redirect($this->loginPath())
            ->withInput($request->only('name', 'remember'))
            ->withErrors([
                'name' => $this->getFailedLoginMessage(),
            ]);

并在视图中更改登录表单..

// Change this..
<input type="text" class="form-control" name="email" value="{{ old('email') }}">
// to..
<input type="text" class="form-control" name="name" value="{{ old('name') }}">