After the registration was successful I wanted to pass all the data to a login route as POST. How do you do this in laravel 4?
注册成功后,我想将所有数据作为POST传递到登录路由。你是如何在laravel 4中做到这一点的?
I know I can just authenticate the user after registration but the login page has other parameters and more required authentication process.
我知道我可以在注册后对用户进行身份验证,但登录页面有其他参数和更多必需的身份验证过程。
So I wish to push the username and password entered in the registration process into the login process so it can go through with the other processes inside the login route. (ex. Token generation which requires post data of app_id and app_secret)
因此,我希望将在注册过程中输入的用户名和密码推送到登录过程中,以便它可以通过登录路由中的其他进程。 (例如令牌生成需要app_id和app_secret的后期数据)
4 个解决方案
#1
0
You can use Laravel Events do to that:
您可以使用Laravel Events执行此操作:
Register your event in filters.php
or create an events.php
and add it to composer.json
:
在filters.php中注册您的事件或创建events.php并将其添加到composer.json:
Event::listen('user.registered', function($data)
{
var_dump($data['app_id']);
var_dump($data['app_secret']);
var_dump($data['user']);
});
And fire it in your register()
method:
并在你的register()方法中触发它:
public function register()
{
/// register your user:
$user = new User;
...
$user->save();
/// fire the event:
Event::fire('user.registered', array(
'app_id' => 'API',
'app_secret' => 'WHATEVER',
'user' => $user
));
/// Redirect the user to where it should go next:
return Redirect::to('/');
}
#2
0
Why not move alot of that extra logic into the User model. Then you can call $user->crazySecureLogin();
after logging in and after registering. That way you stay DRY, and it could possibly clean up your login controller method too. And to top it off, you don't have to worry about sending a post request as a response.
为什么不将大量额外的逻辑移动到用户模型中。然后你可以调用$ user-> crazySecureLogin();登录后和注册后。这样你就可以保持DRY,它也可能会清理你的登录控制器方法。最重要的是,您不必担心发送帖子请求作为回复。
#3
0
-
add namespace on top of your class
在您的类顶部添加命名空间
use Redirect;
-
add this code to your redirect stage.
将此代码添加到重定向阶段。
return Redirect::route('route_name',['username' => $request->username, 'password' => $request->password]);
#4
-1
return Redirect::to('routename')->withInput();
or
要么
return Redirect::to('routename')->with('email', $emailvalue)->with('password', $passwordValue)
etc
等等
#1
0
You can use Laravel Events do to that:
您可以使用Laravel Events执行此操作:
Register your event in filters.php
or create an events.php
and add it to composer.json
:
在filters.php中注册您的事件或创建events.php并将其添加到composer.json:
Event::listen('user.registered', function($data)
{
var_dump($data['app_id']);
var_dump($data['app_secret']);
var_dump($data['user']);
});
And fire it in your register()
method:
并在你的register()方法中触发它:
public function register()
{
/// register your user:
$user = new User;
...
$user->save();
/// fire the event:
Event::fire('user.registered', array(
'app_id' => 'API',
'app_secret' => 'WHATEVER',
'user' => $user
));
/// Redirect the user to where it should go next:
return Redirect::to('/');
}
#2
0
Why not move alot of that extra logic into the User model. Then you can call $user->crazySecureLogin();
after logging in and after registering. That way you stay DRY, and it could possibly clean up your login controller method too. And to top it off, you don't have to worry about sending a post request as a response.
为什么不将大量额外的逻辑移动到用户模型中。然后你可以调用$ user-> crazySecureLogin();登录后和注册后。这样你就可以保持DRY,它也可能会清理你的登录控制器方法。最重要的是,您不必担心发送帖子请求作为回复。
#3
0
-
add namespace on top of your class
在您的类顶部添加命名空间
use Redirect;
-
add this code to your redirect stage.
将此代码添加到重定向阶段。
return Redirect::route('route_name',['username' => $request->username, 'password' => $request->password]);
#4
-1
return Redirect::to('routename')->withInput();
or
要么
return Redirect::to('routename')->with('email', $emailvalue)->with('password', $passwordValue)
etc
等等