示例#1
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];
 }
示例#2
0
 /**
  * Setter for `password`
  * @return mixed
  */
 protected final function setPassword($value)
 {
     return String::password($value);
 }
示例#3
0
 /**
  * {@inheritdoc}
  * @internal
  */
 public function __set($columnName, $value)
 {
     $setter = String::camelize($columnName, true);
     if (method_exists($this, "set{$setter}")) {
         $value = call_user_func_array([$this, "set{$setter}"], [$value]);
     }
     parent::__set($columnName, $value);
 }
示例#4
0
 /**
  * Setter for `slug`
  * @return mixed
  */
 protected final function setSlug($value)
 {
     return String::slugfy($value);
 }
示例#5
0
 /**
  * Getter for `description`
  * @return mixed
  */
 protected final function getDescription()
 {
     return String::escape($this->description);
 }