Example #1
0
 /**
  * Get a single user, ready to be serialized and assigned to the JsonApi
  * response.
  *
  * @param \Flarum\Api\JsonApiRequest $request
  * @param \Flarum\Api\JsonApiResponse $response
  * @return \Flarum\Core\Models\Discussion
  */
 protected function data(JsonApiRequest $request, JsonApiResponse $response)
 {
     $id = $request->get('id');
     if (!is_numeric($id)) {
         $id = $this->users->getIdForUsername($id);
     }
     return $this->users->findOrFail($id, $request->actor->getUser());
 }
 public function handle(RequestPasswordResetCommand $command)
 {
     $user = $this->users->findByEmail($command->email);
     if (!$user) {
         throw new ModelNotFoundException();
     }
     $token = PasswordToken::generate($user->id);
     $token->save();
     $data = ['username' => $user->username, 'url' => route('flarum.forum.resetPassword', ['token' => $token->id]), 'forumTitle' => Core::config('forum_title')];
     $this->mailer->send(['text' => 'flarum::emails.resetPassword'], $data, function ($message) use($user) {
         $message->to($user->email);
         $message->subject('Reset Your Password');
     });
     return $user;
 }
 public function handle(DeleteAvatarCommand $command)
 {
     $user = $this->users->findOrFail($command->userId);
     // Make sure the current user is allowed to edit the user profile.
     // This will let admins and the user themselves pass through, and
     // throw an exception otherwise.
     $user->assertCan($command->actor, 'edit');
     $avatarPath = $user->avatar_path;
     $user->changeAvatarPath(null);
     event(new AvatarWillBeDeleted($user, $command));
     $this->uploadDir->delete($avatarPath);
     $user->save();
     $this->dispatchEventsFor($user);
     return $user;
 }
 public function handle(UploadAvatarCommand $command)
 {
     $user = $this->users->findOrFail($command->userId);
     // Make sure the current user is allowed to edit the user profile.
     // This will let admins and the user themselves pass through, and
     // throw an exception otherwise.
     $user->assertCan($command->actor, 'edit');
     $manager = new ImageManager(array('driver' => 'imagick'));
     $manager->make($command->file->getRealPath())->fit(100, 100)->save();
     $filename = $command->file->getFilename();
     $uploadName = Str::lower(Str::quickRandom()) . '.jpg';
     $mount = new MountManager(['source' => new Filesystem(new Local($command->file->getPath())), 'target' => $this->uploadDir]);
     if ($user->avatar_path && $mount->has($file = "target://{$user->avatar_path}")) {
         $mount->delete($file);
     }
     $user->changeAvatarPath($uploadName);
     event(new AvatarWillBeUploaded($user, $command));
     $mount->move("source://{$filename}", "target://{$uploadName}");
     $user->save();
     $this->dispatchEventsFor($user);
     return $user;
 }
Example #5
0
 /**
  * Get the activity results, ready to be serialized and assigned to the
  * document response.
  *
  * @param \Flarum\Api\JsonApiRequest $request
  * @param \Flarum\Api\JsonApiResponse $response
  * @return \Illuminate\Database\Eloquent\Collection
  */
 protected function data(JsonApiRequest $request, JsonApiResponse $response)
 {
     $actor = $request->actor->getUser();
     $user = $this->users->findOrFail($request->get('users'), $actor);
     return $this->activity->findByUser($user->id, $actor, $request->limit, $request->offset, $request->get('type'))->load($request->include);
 }