예제 #1
0
 /**
  * @param RegisterUser $command
  * @return User
  * @throws PermissionDeniedException
  */
 public function handle(RegisterUser $command)
 {
     if (!$this->settings->get('allow_sign_up')) {
         throw new PermissionDeniedException();
     }
     $actor = $command->actor;
     $data = $command->data;
     $user = User::register(array_get($data, 'attributes.username'), array_get($data, 'attributes.email'), array_get($data, 'attributes.password'));
     event(new UserWillBeSaved($user, $actor, $data));
     $user->save();
     $this->dispatchEventsFor($user);
     return $user;
 }
예제 #2
0
 /**
  * @param RegisterUser $command
  *
  * @throws PermissionDeniedException if signup is closed and the actor is
  *     not an administrator.
  * @throws \Flarum\Core\Exceptions\InvalidConfirmationTokenException if an
  *     email confirmation token is provided but is invalid.
  *
  * @return User
  */
 public function handle(RegisterUser $command)
 {
     $actor = $command->actor;
     $data = $command->data;
     if (!$this->settings->get('allow_sign_up') && !$actor->isAdmin()) {
         throw new PermissionDeniedException();
     }
     $username = array_get($data, 'attributes.username');
     $email = array_get($data, 'attributes.email');
     $password = array_get($data, 'attributes.password');
     // If a valid authentication token was provided as an attribute,
     // then we won't require the user to choose a password.
     if (isset($data['attributes']['token'])) {
         $token = AuthToken::validOrFail($data['attributes']['token']);
         $password = $password ?: str_random(20);
     }
     $user = User::register($username, $email, $password);
     // If a valid authentication token was provided, then we will assign
     // the attributes associated with it to the user's account. If this
     // includes an email address, then we will activate the user's account
     // from the get-go.
     if (isset($token)) {
         foreach ($token->payload as $k => $v) {
             $user->{$k} = $v;
         }
         if (isset($token->payload['email'])) {
             $user->activate();
         }
     }
     event(new UserWillBeSaved($user, $actor, $data));
     $user->save();
     if (isset($token)) {
         $token->delete();
     }
     $this->dispatchEventsFor($user);
     return $user;
 }
예제 #3
0
 protected function createAdminUser()
 {
     $admin = $this->adminUser;
     if ($admin['password'] !== $admin['password_confirmation']) {
         throw new Exception('The password did not match its confirmation.');
     }
     $this->info('Creating admin user ' . $admin['username']);
     $user = User::register($admin['username'], $admin['email'], $admin['password']);
     $user->is_activated = 1;
     $user->save();
     $user->groups()->sync([1]);
 }