/** * get Current logged in user * * @return bollean */ public function getUser() { if (is_null($this->user)) { try { $this->user = $this->sentry->getUser(); } catch (\Cartalyst\Sentry\Users\UserNotFoundException $e) { $this->user = null; } } return $this->user; }
/** * Check if a user is logged in and has the desired permissions * * @param string|array $permission One permission as string or several in an array to check against * @throws PermissionMissingException Throws an exception containing further information as message * @return bool Returns true if the logged in user has the required permissions */ public function has($permission) { if (!$this->sentry->check()) { throw new PermissionMissingException('User is not logged in.'); } else { $user = $this->sentry->getUser(); if (!$user->hasAccess($permission)) { throw new PermissionMissingException('User is missing permissions.'); } return true; } }
/** * Find a project by id or name. * * @param string/int $id * @return Collection */ public function find($id) { if (is_string($id)) { $col = 'name'; } else { $col = 'id'; } $p = $this->model->with('pages.libraries')->where($col, $id)->where('public', 1)->first(); if (!$p) { if ($col === 'id') { $col = 'projects.id'; } $p = $this->sentry->getUser()->projects()->with('pages.libraries')->where($col, $id)->first(); } return $p; }
/** * Return all the registered groups * * @return stdObject Collection of groups */ public function all() { if ($this->sentry->getUser()->isSuperUser()) { $groups = $this->sentry->findAllGroups(); } else { $groups = $this->sentry->getUser()->getGroups(); } return $groups; }
/** * Authenticate against the current service. A closure may be provided * for a callback upon authentication as a shortcut for subscribing * to an event. * * @param string $slug * @param string $callbackUri * @param Closure $callback * @param bool $remmber * @return \Cartalyst\Sentry\Users\UserInterface */ public function authenticate($slug, $callbackUri, Closure $callback = null, $remember = false) { // If a callback is supplied, we'll treat it as a global linking // callback. Specific callbacks for registering and existing // users can be registered outside of this method. if ($callback) { $this->linking($callback); } $provider = $this->make($slug, $callbackUri); $token = $this->retrieveToken($provider); // We'll check if a user is already logged in. If so // Sentry Social will link the logged in user. if ($user = $this->sentry->getUser()) { $link = $this->linkLoggedIn($slug, $provider, $token, $user); } else { $link = $this->linkLoggedOut($slug, $provider, $token); $user = $link->getUser(); $this->login($user, $remember); } return $user; }
/** * Returns the current user being used by Sentry, if any. * * @return \Cartalyst\Sentry\Users\UserInterface * @static */ public static function getUser() { return \Cartalyst\Sentry\Sentry::getUser(); }
/** * Get value from the user to be saved as the author. * * @return string|null */ protected function getUserFieldValue() { if ($user = $this->provider->getUser()) { return ($field = $this->field) ? (string) $user->{$field} : $user->getLogin(); } }
/** * @param string $action * @param Entity $entity * * @return bool */ public function isPermitted($action, Entity $entity) { $key = "{$entity->getId()}.{$action}"; return ($user = $this->sentry->getUser()) && $user->hasAccess($key); }
/** * Returns the current user being used by Sentry, if any. * * @author ZZK * @link http://verecom.com * * @return mixed */ public function getUser() { return $this->sentry->getUser(); }
/** * Get the decorated current user. * * @return \GrahamCampbell\Credentials\Presenters\UserPresenter */ public function getDecoratedUser() { if ($user = $this->sentry->getUser()) { return $this->decorator->decorate($user); } }