mirror of
https://github.com/flarum/core.git
synced 2025-07-31 13:40:20 +02:00
Finish signup process, including state restoration
This commit is contained in:
@@ -44,7 +44,7 @@ abstract class BaseAction extends Action
|
||||
}
|
||||
}
|
||||
|
||||
protected function dispatch($command, $params)
|
||||
protected function dispatch($command, $params = [])
|
||||
{
|
||||
$this->event(new CommandWillBeDispatched($command, $params));
|
||||
return $this->bus->dispatch($command);
|
||||
|
@@ -22,8 +22,8 @@ class CreateAction extends BaseAction
|
||||
$email = $params->get('users.email');
|
||||
$password = $params->get('users.password');
|
||||
|
||||
$command = new RegisterUserCommand($username, $email, $password, $this->actor->getUser());
|
||||
$this->dispatch($command, $params);
|
||||
$command = new RegisterUserCommand($username, $email, $password, $this->actor->getUser(), app('flarum.forum'));
|
||||
$user = $this->dispatch($command, $params);
|
||||
|
||||
// Presumably, the user was created successfully. (The command handler
|
||||
// would have thrown an exception if not.) We set this post as our
|
||||
|
@@ -21,7 +21,7 @@ class CoreServiceProvider extends ServiceProvider
|
||||
*/
|
||||
public function boot(Dispatcher $events, Bus $bus)
|
||||
{
|
||||
$this->loadViewsFrom(__DIR__.'../../views', 'flarum');
|
||||
$this->loadViewsFrom(__DIR__.'/../../views', 'flarum');
|
||||
|
||||
$this->registerEventHandlers($events);
|
||||
$this->registerPostTypes();
|
||||
|
@@ -2,7 +2,7 @@
|
||||
|
||||
use Flarum\Core\Models\User;
|
||||
|
||||
class EmailWasChanged
|
||||
class UserEmailWasChanged
|
||||
{
|
||||
public $user;
|
||||
|
||||
|
@@ -2,7 +2,7 @@
|
||||
|
||||
use Flarum\Core\Models\User;
|
||||
|
||||
class EmailWasConfirmed
|
||||
class UserEmailWasConfirmed
|
||||
{
|
||||
public $user;
|
||||
|
||||
|
@@ -2,7 +2,7 @@
|
||||
|
||||
use Flarum\Core\Models\User;
|
||||
|
||||
class PasswordWasChanged
|
||||
class UserPasswordWasChanged
|
||||
{
|
||||
public $user;
|
||||
|
||||
|
@@ -1,5 +1,7 @@
|
||||
<?php namespace Flarum\Core\Handlers\Commands;
|
||||
|
||||
use Flarum\Core\Models\User;
|
||||
use Flarum\Core\Events\UserWillBeSaved;
|
||||
use Flarum\Core\Support\DispatchesEvents;
|
||||
|
||||
class RegisterUserCommandHandler
|
||||
|
@@ -3,6 +3,7 @@
|
||||
use Illuminate\Mail\Mailer;
|
||||
use Flarum\Core\Events\UserWasRegistered;
|
||||
use Flarum\Core\Events\EmailWasChanged;
|
||||
use Config;
|
||||
|
||||
class EmailConfirmationMailer
|
||||
{
|
||||
@@ -29,7 +30,7 @@ class EmailConfirmationMailer
|
||||
{
|
||||
$user = $event->user;
|
||||
|
||||
$forumTitle = Config::get('flarum::forum_tite');
|
||||
$forumTitle = Config::get('flarum::forum_title');
|
||||
|
||||
$data = [
|
||||
'username' => $user->username,
|
||||
@@ -37,8 +38,10 @@ class EmailConfirmationMailer
|
||||
'url' => route('flarum.confirm', ['id' => $user->id, 'token' => $user->confirmation_token])
|
||||
];
|
||||
|
||||
$this->mailer->send(['text' => 'flarum::emails.confirm'], $data, function ($message) use ($user) {
|
||||
$message->to($user->email)->subject('['.$forumTitle.'] Email Address Confirmation');
|
||||
$this->mailer->send(['text' => 'flarum::emails.confirm'], $data, function ($message) use ($user, $forumTitle) {
|
||||
$message->to($user->email);
|
||||
$message->subject('['.$forumTitle.'] Email Address Confirmation');
|
||||
$message->from('noreply@localhost', $forumTitle);
|
||||
});
|
||||
}
|
||||
|
||||
|
@@ -6,10 +6,10 @@ use Flarum\Core\Exceptions\InvalidConfirmationTokenException;
|
||||
use Flarum\Core\Events\UserWasDeleted;
|
||||
use Flarum\Core\Events\UserWasRegistered;
|
||||
use Flarum\Core\Events\UserWasRenamed;
|
||||
use Flarum\Core\Events\EmailWasChanged;
|
||||
use Flarum\Core\Events\PasswordWasChanged;
|
||||
use Flarum\Core\Events\UserEmailWasChanged;
|
||||
use Flarum\Core\Events\UserPasswordWasChanged;
|
||||
use Flarum\Core\Events\UserWasActivated;
|
||||
use Flarum\Core\Events\EmailWasConfirmed;
|
||||
use Flarum\Core\Events\UserEmailWasConfirmed;
|
||||
|
||||
class User extends Model
|
||||
{
|
||||
@@ -115,7 +115,7 @@ class User extends Model
|
||||
{
|
||||
if ($email !== $this->email) {
|
||||
$this->email = $email;
|
||||
$this->raise(new EmailWasChanged($this));
|
||||
$this->raise(new UserEmailWasChanged($this));
|
||||
}
|
||||
|
||||
return $this;
|
||||
@@ -130,7 +130,7 @@ class User extends Model
|
||||
public function changePassword($password)
|
||||
{
|
||||
$this->password = $password ? static::$hasher->make($password) : null;
|
||||
$this->raise(new PasswordWasChanged($this));
|
||||
$this->raise(new UserPasswordWasChanged($this));
|
||||
|
||||
return $this;
|
||||
}
|
||||
@@ -211,7 +211,7 @@ class User extends Model
|
||||
$this->is_confirmed = true;
|
||||
$this->confirmation_token = null;
|
||||
|
||||
$this->raise(new EmailWasConfirmed($this));
|
||||
$this->raise(new UserEmailWasConfirmed($this));
|
||||
|
||||
return $this;
|
||||
}
|
||||
@@ -302,6 +302,16 @@ class User extends Model
|
||||
return Permission::whereIn('grantee', $this->getGrantees());
|
||||
}
|
||||
|
||||
/**
|
||||
* Define the relationship with the user's access tokens.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
*/
|
||||
public function accessTokens()
|
||||
{
|
||||
return $this->hasMany('Flarum\Core\Models\AccessToken');
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the hasher with which to hash passwords.
|
||||
*
|
||||
|
@@ -1,6 +1,7 @@
|
||||
<?php namespace Flarum\Web\Actions;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Contracts\Bus\Dispatcher;
|
||||
use Flarum\Web\Events\CommandWillBeDispatched;
|
||||
use Flarum\Core\Support\Actor;
|
||||
|
||||
@@ -8,9 +9,10 @@ abstract class Action
|
||||
{
|
||||
abstract public function handle(Request $request, $routeParams = []);
|
||||
|
||||
public function __construct(Actor $actor)
|
||||
public function __construct(Actor $actor, Dispatcher $bus)
|
||||
{
|
||||
$this->actor = $actor;
|
||||
$this->bus = $bus;
|
||||
}
|
||||
|
||||
protected function callAction($class, $params = [])
|
||||
@@ -19,9 +21,9 @@ abstract class Action
|
||||
return $action->call($params);
|
||||
}
|
||||
|
||||
protected function dispatch($command, $params)
|
||||
protected function dispatch($command, $params = [])
|
||||
{
|
||||
$this->event(new CommandWillBeDispatched($command, $params));
|
||||
event(new CommandWillBeDispatched($command, $params));
|
||||
return $this->bus->dispatch($command);
|
||||
}
|
||||
}
|
||||
|
@@ -1,25 +1,29 @@
|
||||
<?php namespace Flarum\Web\Actions;
|
||||
|
||||
use Flarum\Core\Users\Commands\ConfirmEmailCommand;
|
||||
use Cookie;
|
||||
use Illuminate\Http\Request;
|
||||
use Flarum\Core\Commands\ConfirmEmailCommand;
|
||||
use Flarum\Core\Commands\GenerateAccessTokenCommand;
|
||||
use Flarum\Core\Exceptions\InvalidConfirmationTokenException;
|
||||
|
||||
class ConfirmAction extends Action
|
||||
{
|
||||
use MakesRememberCookie;
|
||||
|
||||
public function respond(Request $request, $params = [])
|
||||
public function handle(Request $request, $routeParams = [])
|
||||
{
|
||||
try {
|
||||
$userId = array_get($routeParams, 'id');
|
||||
$token = array_get($routeParams, 'token');
|
||||
$command = new ConfirmEmailCommand($userId, $token);
|
||||
$user = $this->dispatch($command);
|
||||
} catch (InvalidConfirmationTokenException $e) {
|
||||
return 'Invalid confirmation token';
|
||||
}
|
||||
|
||||
$token = AccessToken::generate($user->id);
|
||||
$token->save();
|
||||
$command = new GenerateAccessTokenCommand($user->id);
|
||||
$token = $this->dispatch($command);
|
||||
|
||||
return Redirect::to('/')
|
||||
return redirect('/')
|
||||
->withCookie($this->makeRememberCookie($token->id))
|
||||
->with('alert', ['type' => 'success', 'message' => 'Thanks for confirming!']);
|
||||
}
|
||||
|
Reference in New Issue
Block a user