/** * 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]; }
/** * Setter for `password` * @return mixed */ protected final function setPassword($value) { return String::password($value); }
/** * {@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); }
/** * Setter for `slug` * @return mixed */ protected final function setSlug($value) { return String::slugfy($value); }
/** * Getter for `description` * @return mixed */ protected final function getDescription() { return String::escape($this->description); }