Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.3] fire new Registered event when user registers #15401

Merged
merged 2 commits into from
Sep 16, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions src/Illuminate/Auth/Events/Registered.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace Illuminate\Auth\Events;

use Illuminate\Queue\SerializesModels;

class Registered
{
use SerializesModels;

/**
* The authenticated user.
*
* @var \Illuminate\Contracts\Auth\Authenticatable
*/
public $user;

/**
* Create a new event instance.
*
* @param \Illuminate\Contracts\Auth\Authenticatable $user
* @return void
*/
public function __construct($user)
{
$this->user = $user;
}
}
19 changes: 18 additions & 1 deletion src/Illuminate/Foundation/Auth/RegistersUsers.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Auth\Events\Registered;
use Illuminate\Contracts\Auth\Authenticatable;

trait RegistersUsers
{
Expand All @@ -29,11 +31,26 @@ public function register(Request $request)
{
$this->validator($request->all())->validate();

$this->guard()->login($this->create($request->all()));
$user = $this->create($request->all());

$this->fireRegisteredEvent($user);

$this->guard()->login($user);

return redirect($this->redirectPath());
}

/**
* Fire an event when a user registers.
*
* @param \Illuminate\Contracts\Auth\Authenticatable $authenticatable
* @return void
*/
protected function fireRegisteredEvent(Authenticatable $authenticatable)
{
event(new Registered($authenticatable));
}

/**
* Get the guard to be used during registration.
*
Expand Down