Example #1
0
 /**
  * {@inheritdoc}
  */
 public final function getCurrentUser()
 {
     if ($this->hasAuth() && null === self::$user) {
         self::$user = User::loadWithPermissions(self::$auth, $this->getContext());
     }
     return self::$user;
 }
Example #2
0
 /**
  * Authenticates against the supplied adapter
  *
  * @param string username
  * @param string password in row format
  * @return ZfRest\Auth
  */
 public static function authenticate($username, $password)
 {
     if ('' === trim($username) || '' === trim($password)) {
         throw new Exception('ERR.IDENTITY_AMBIGUOUS', self::FAILURE_IDENTITY_AMBIGUOUS);
     }
     if (filter_var($username, FILTER_VALIDATE_EMAIL)) {
         $usedColumn = 'email';
     } else {
         $usedColumn = 'username';
     }
     if (null === ($user = User::locate($usedColumn, $username))) {
         throw new Exception('ERR.IDENTITY_NOT_FOUND', self::FAILURE_IDENTITY_NOT_FOUND);
     }
     if (!String::verifyPassword($password, $user->password)) {
         throw new Exception('ERR.CREDENTIAL_INVALID', self::FAILURE_CREDENTIAL_INVALID);
     }
     $token = String::password(static::getAccessToken($user));
     $user->token = $token;
     $user->save();
     return ['token_type' => 'bearer', 'access_token' => $token];
 }
Example #3
0
 /**
  * {@inheritdoc}
  */
 public static function loadUsers($groupId)
 {
     $table = new User();
     $select = $table->select()->setIntegrityCheck(false)->from(['us' => 'user'])->join(['ug' => 'user_to_group'], 'us.id = ug.user_id', [])->where('ug.group_id = ?', $groupId);
     return $table->fetchAll($select);
 }
Example #4
0
 /**
  * {@inheritdoc}
  */
 public static function loadUsers($entityId)
 {
     $table = new User();
     $select = $table->select()->setIntegrityCheck(false)->from(['us' => 'user'])->join(['ue' => 'user_to_entity'], 'us.id = ue.user_id', [])->where('ue.entity_id = ?', $entityId);
     return $table->fetchAll($select);
 }