/**
  * Retrieves the currently authenticate user's username.
  *
  * @return User
  *
  * @throws InvalidRequestException
  * @throws AccessDeniedException
  */
 public function getCurrentUser()
 {
     $this->server->isValidRequest();
     // Choooo chooo!!
     $ownerId = $this->server->getAccessToken()->getSession()->getOwnerId();
     return $this->speakerRepository->findById($ownerId);
 }
Beispiel #2
0
 /**
  * Retrieves a talk owned by a speaker.
  *
  * @param $speakerId
  * @param $talkId
  *
  * @return Talk
  * @throws NotAuthorizedException
  */
 public function getTalk($speakerId, $talkId)
 {
     $speaker = $this->speakerRepository->findById($speakerId);
     $talk = $speaker->talks->where(['id' => $talkId])->execute()->first();
     // If it can't grab by relation, it's likely not their talk.
     if (!$talk) {
         throw new NotAuthorizedException();
     }
     // Do an explicit check of ownership because why not.
     if ($talk->user_id !== $speaker->id) {
         throw new NotAuthorizedException();
     }
     return $talk;
 }