/** * 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; }
public function register(array $aCredentials, $blActivate = false) { $oUser = parent::register($aCredentials, $blActivate); $oUser->getApiKey(); $oUser->getSignature(); return $oUser; }
/** * Attempt to reset a user and send him a new password * * This will unsuspend a user and give him a new password. * * @param int $id The user id * @param string $reset_code The password reset code * @throws PasswordResetFailedException Throws an exception without further information on failure * @throws PasswordResetCodeInvalidException Throws an exception without further information on failure * @throws MailException Throws an exception containing further information as message * @throws UserNotFoundException Throws an exception without further information on failure * @return void */ public function sendNewPassword($id, $reset_code) { $user = $this->sentry->findUserById($id); $this->prepareResetResultMailData($user, $reset_code); $this->setMailErrorMessage('Sending the email containing the new password failed. ' . 'Please try again later or contact the administrator.'); $this->sendMail(); }
/** * Logout * * If you're actually logged in, it'll log you out and show a message. * Else it will silently redirect you to the login form. * * @return \Illuminate\Http\RedirectResponse */ public function getLogout() { if ($this->sentry->check()) { $this->sentry->logout(); $this->session->flash('success', 'You have successfully logged out.'); } return $this->redirect->route('larapress.home.login.get'); }
/** * @param string $user * @param string $password * * @return bool */ public function authenticate($user, $password) { if (empty($user) || empty($password)) { $this->authenticationMessage = "Missing Email or Password"; return false; } try { $this->sentry->authenticate(['email' => $user, 'password' => $password], false); } catch (UserNotFoundException $e) { $this->authenticationMessage = "Invalid Email or Password"; return false; } catch (UserNotActivatedException $e) { $this->authenticationMessage = "Your account hasn't been activated. Did you get the activation email?"; return false; } return true; }
/** * Add the admin user * * @param GroupInterface $admin_group The Administrator group * @return void */ public function add_the_admin_user($admin_group) { try { $user = $this->sentry->createUser(array('email' => $this->email, 'password' => $this->password, 'activated' => true)); $user->addGroup($admin_group); } catch (UnexpectedValueException $e) { $this->handle_unexpected_value_exception($e); } }
/** * Logs the given user into Sentry. * * @param \Cartalyst\Sentry\Users\UserInterface $user * @param bool $remember * @return void */ protected function login(UserInterface $user, $remember = false) { $throttleProvider = $this->sentry->getThrottleProvider(); // Now, we will check the throttling to ensure we are // not logging in a user which shouldn't be allowed. if ($throttleProvider->isEnabled()) { $throttle = $throttleProvider->findByUserId($user->getId(), $this->sentry->getIpAddress()); $throttle->check(); } $this->sentry->login($user, $remember); }
/** * Create user into storage * * @author ZZK * @link http://verecom.com * * @param array $credentials * @param bool $activate * * @return \Cartalyst\Sentry\Users\UserInterface */ protected function storeUser(array $credentials, $activate = false) { $cred = array('first_name' => $credentials['first_name'], 'last_name' => $credentials['last_name'], 'email' => $credentials['email'], 'password' => $credentials['password']); if (array_key_exists('permissions', $credentials)) { $cred['permissions'] = $credentials['permissions']; } $user = $this->sentry->register($cred, $activate); if (array_key_exists('groups', $credentials)) { $this->syncGroups($credentials['groups'], $user); } return $user; }
public function allWithChecked($resource = null) { $resourceGroups = []; if ($resource instanceof \Cartalyst\Sentry\Users\UserInterface) { $resourceGroups = array_column($resource->getGroups()->toArray(), 'id'); } else { foreach ($this->sentry->findAllGroups() as $group) { if ($group->hasAccess($resource)) { $resourceGroups[] = $group->getId(); } } } $groups = $this->all(); foreach ($groups as &$group) { $group['value'] = 0; if (in_array($group['id'], $resourceGroups)) { $group['value'] = 1; } } return $groups; }
/** * Finds a throttling interface by the given user login. * * @param string $login * @param string $ipAddress * @return \Cartalyst\Sentry\Throttling\ThrottleInterface * @static */ public static function findThrottlerByUserLogin($login, $ipAddress = null) { return \Cartalyst\Sentry\Sentry::findThrottlerByUserLogin($login, $ipAddress); }
/** * Creates a group. * * @author Steve Montambeault * @link http://stevemo.ca * * @param array $attributes * * @return \Cartalyst\Sentry\Groups\GroupInterface */ public function create(array $attributes) { $group = $this->sentry->getGroupProvider()->create($attributes); $this->event->fire('groups.create', array($group)); return $group; }
/** * 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); }
/** * Get the decorated current user. * * @return \GrahamCampbell\Credentials\Presenters\UserPresenter */ public function getDecoratedUser() { if ($user = $this->sentry->getUser()) { return $this->decorator->decorate($user); } }