diff --git a/framework/core/ember/app/controllers/signup.js b/framework/core/ember/app/controllers/signup.js index 035816e09..d3326a313 100644 --- a/framework/core/ember/app/controllers/signup.js +++ b/framework/core/ember/app/controllers/signup.js @@ -28,6 +28,7 @@ export default Ember.Controller.extend(ModalController, { return user.save().then(function(user) { controller.set('welcomeUser', user); controller.set('loading', false); + controller.send('saveState'); }, function(reason) { controller.set('loading', false); }); diff --git a/framework/core/ember/app/routes/application.js b/framework/core/ember/app/routes/application.js index dab0ecef4..bf0e1ae78 100644 --- a/framework/core/ember/app/routes/application.js +++ b/framework/core/ember/app/routes/application.js @@ -7,6 +7,13 @@ export default Ember.Route.extend(ApplicationRouteMixin, { activate: function() { if (!Ember.isEmpty(FLARUM_ALERT)) { this.controllerFor('alerts').send('alert', AlertMessage.create(FLARUM_ALERT)); + FLARUM_ALERT = null; + } + + var restoreUrl = localStorage.getItem('restoreUrl'); + if (restoreUrl && this.get('session.isAuthenticated')) { + this.transitionTo(restoreUrl); + localStorage.removeItem('restoreUrl'); } }, @@ -42,6 +49,10 @@ export default Ember.Route.extend(ApplicationRouteMixin, { sessionChanged: function() { this.refresh(); + }, + + saveState: function() { + localStorage.setItem('restoreUrl', this.router.get('url')); } } }); diff --git a/framework/core/ember/app/templates/signup.hbs b/framework/core/ember/app/templates/signup.hbs index d91dd885d..72ec23249 100644 --- a/framework/core/ember/app/templates/signup.hbs +++ b/framework/core/ember/app/templates/signup.hbs @@ -28,7 +28,7 @@ {{ui/loading-indicator classNameBindings=":modal-loading loading:active"}} {{#if welcomeUser}} -
+
{{user-avatar welcomeUser}}

Welcome, {{welcomeUser.username}}!

diff --git a/framework/core/ember/app/views/signup.js b/framework/core/ember/app/views/signup.js index ea8379203..0f3388973 100644 --- a/framework/core/ember/app/views/signup.js +++ b/framework/core/ember/app/views/signup.js @@ -9,10 +9,10 @@ export default Ember.View.extend(ModalView, { didInsertElement: function() { }, - welcomeUserDidChange: Ember.observer('welcomeUser', function() { - if (this.get('welcomeUser')) { + welcomeUserDidChange: Ember.observer('controller.welcomeUser', function() { + if (this.get('controller.welcomeUser')) { Ember.run.scheduleOnce('afterRender', this, function() { - this.$('.signup-welcome').addClass('in'); + this.$('.signup-welcome').hide().fadeIn(); }); } }) diff --git a/framework/core/src/Api/Actions/BaseAction.php b/framework/core/src/Api/Actions/BaseAction.php index c4d41d56b..ee6b617c4 100644 --- a/framework/core/src/Api/Actions/BaseAction.php +++ b/framework/core/src/Api/Actions/BaseAction.php @@ -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); diff --git a/framework/core/src/Api/Actions/Users/CreateAction.php b/framework/core/src/Api/Actions/Users/CreateAction.php index f2c035a7b..166136674 100644 --- a/framework/core/src/Api/Actions/Users/CreateAction.php +++ b/framework/core/src/Api/Actions/Users/CreateAction.php @@ -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 diff --git a/framework/core/src/Core/CoreServiceProvider.php b/framework/core/src/Core/CoreServiceProvider.php index dc39ba23a..b1369ba90 100644 --- a/framework/core/src/Core/CoreServiceProvider.php +++ b/framework/core/src/Core/CoreServiceProvider.php @@ -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(); diff --git a/framework/core/src/Core/Events/UserEmailWasChanged.php b/framework/core/src/Core/Events/UserEmailWasChanged.php index 5bc42943d..774d783be 100644 --- a/framework/core/src/Core/Events/UserEmailWasChanged.php +++ b/framework/core/src/Core/Events/UserEmailWasChanged.php @@ -2,7 +2,7 @@ use Flarum\Core\Models\User; -class EmailWasChanged +class UserEmailWasChanged { public $user; diff --git a/framework/core/src/Core/Events/UserEmailWasConfirmed.php b/framework/core/src/Core/Events/UserEmailWasConfirmed.php index 4b9b2e0ba..75e6a92fc 100644 --- a/framework/core/src/Core/Events/UserEmailWasConfirmed.php +++ b/framework/core/src/Core/Events/UserEmailWasConfirmed.php @@ -2,7 +2,7 @@ use Flarum\Core\Models\User; -class EmailWasConfirmed +class UserEmailWasConfirmed { public $user; diff --git a/framework/core/src/Core/Events/UserPasswordWasChanged.php b/framework/core/src/Core/Events/UserPasswordWasChanged.php index 40c82a4b4..f1b58f429 100644 --- a/framework/core/src/Core/Events/UserPasswordWasChanged.php +++ b/framework/core/src/Core/Events/UserPasswordWasChanged.php @@ -2,7 +2,7 @@ use Flarum\Core\Models\User; -class PasswordWasChanged +class UserPasswordWasChanged { public $user; diff --git a/framework/core/src/Core/Handlers/Commands/RegisterUserCommandHandler.php b/framework/core/src/Core/Handlers/Commands/RegisterUserCommandHandler.php index 5838cef03..8cc70db32 100644 --- a/framework/core/src/Core/Handlers/Commands/RegisterUserCommandHandler.php +++ b/framework/core/src/Core/Handlers/Commands/RegisterUserCommandHandler.php @@ -1,5 +1,7 @@ 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); }); } diff --git a/framework/core/src/Core/Models/User.php b/framework/core/src/Core/Models/User.php index 5fa7296c2..8bcd84285 100755 --- a/framework/core/src/Core/Models/User.php +++ b/framework/core/src/Core/Models/User.php @@ -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. * diff --git a/framework/core/src/Web/Actions/Action.php b/framework/core/src/Web/Actions/Action.php index ac57010d7..bccb78908 100644 --- a/framework/core/src/Web/Actions/Action.php +++ b/framework/core/src/Web/Actions/Action.php @@ -1,6 +1,7 @@ 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); } } diff --git a/framework/core/src/Web/Actions/ConfirmAction.php b/framework/core/src/Web/Actions/ConfirmAction.php index b85a87161..510bfe7d7 100644 --- a/framework/core/src/Web/Actions/ConfirmAction.php +++ b/framework/core/src/Web/Actions/ConfirmAction.php @@ -1,25 +1,29 @@ 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!']); }