[英]Disable Auto Login after registration in Laravel 5.3
Please can someone help me. 请有人帮助我。 How do I disable auto login after registration in laravel 5.3.
如何在laravel 5.3中注册后禁用自动登录。 I can do it in 5.2, but not in 5.3.
我可以在5.2中完成,但不能在5.3中完成。
In 5.3
you just need to override the register method. 在
5.3
您只需要覆盖寄存器方法。 You can add the following to your App\\Http\\Controllers\\Auth\\RegisterController
: 您可以将以下内容添加到
App\\Http\\Controllers\\Auth\\RegisterController
:
/**
* Handle a registration request for the application.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function register(Request $request)
{
$this->validator($request->all())->validate();
event(new Registered($user = $this->create($request->all())));
//The auto login code has been removed from here.
return redirect($this->redirectPath());
}
Furthermore, you can either change the redirect path in the register
method itself or just update the $redirectTo
property towards the top of the class. 此外,您可以更改
register
方法本身的重定向路径,也可以将$redirectTo
属性更新为类的顶部。
Hope this helps! 希望这可以帮助!
There is no AuthController.php in Laravel 5.3.* so modify your RegisterController.php and add these lines Laravel 5.3中没有AuthController.php。*所以修改你的RegisterController.php并添加这些行
use Illuminate\\Http\\Request; use Illuminate\\Auth\\Events\\Registered;
then, add this line to handle registration request for the above parameters 然后,添加此行以处理上述参数的注册请求
public function register(Request $request)
{
$this->validator($request->all())->validate();
event(new Registered($user = $this->create($request->all())));
return $this->registered($request, $user)
?: redirect($this->redirectPath());
}
$this->guard()->login($user);
In 5.3 you need to override register()
method in RegisterController.php
which will be build after using make:auth
command. 在5.3,你需要重写
register()
的方法RegisterController.php
这将是建立用后make:auth
命令。 Just comment login()
part: 只需评论
login()
部分:
//$this->guard()->login($user);
Inside RegistersUsers trait there is a function 在RegistersUsers里面有一个功能
protected function registered(Request $request, $user)
{
if(!$user->active){
// store msg in session and display to user
Auth::logout();
}
}
this is the function that executes as soon the user registers, here even you check check if user is verified and any other code and Auth::logout(), this is the best way to do it. 这是用户注册后立即执行的函数,这里甚至你检查用户是否经过验证以及任何其他代码和Auth :: logout(),这是最好的方法。 No need to change any code elsewhere that can messup with framework.
无需在其他地方更改任何可能会破坏框架的代码。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.