public static function authenticateWithUserCredentials($username, $password) { $instance = new self(); $instance->setUsername($username); $instance->setUsername($password); return $instance; }
public static function inicializar($params) { $usuario = new self(); $usuario->setId($params['id']); $usuario->setUsername($params['username']); $usuario->setClave($params['clave']); $usuario->setRol($params['rol']); return $usuario; }
/** * Read digest realm and accompanying data from HTTP response * and construct an instance of this class. * * @param string $header * @param string $user * @param security.SecureString $pass * @return peer.http.DigestAuthorization */ public static function fromChallenge($header, $user, $pass) { if (!preg_match_all('#(([a-z]+)=("[^"$]+)")#m', $header, $matches, PREG_SET_ORDER)) { throw new IllegalStateException('Invalid WWW-Authenticate line'); } $values = array('algorithm' => 'md5', 'opaque' => NULL); foreach ($matches as $m) { $values[$m[2]] = trim($m[3], '"'); } if ($values['algorithm'] != 'md5') { throw new MethodNotImplementedException('Digest auth only supported via algo "md5".', 'digest-md5'); } $auth = new self($values['realm'], $values['qop'], $values['nonce'], $values['opaque']); $auth->setUsername($user); $auth->setPassword($pass); return $auth; }
public static function factory($config = array()) { // Provide a hash of default client configuration options $default = array('base_url' => 'https://campbx.com/api'); // The following values are required when creating the client $required = array('base_url', 'username', 'password'); // merge in default settings and validate the config $config = Collection::fromConfig($config, $default, $required); $client = new self($config->get('base_url'), $config); $client->setUsername($config['username']); $client->setPassword($config['password']); // use description file to configure the client $servicesDescriptionFilename = dirname(__FILE__) . '/service-description.json'; $description = ServiceDescription::factory($servicesDescriptionFilename); $client->setDescription($description); return $client; }
/** * @param Campaign $campaign * @param array $array * @return Campaign|Content */ public static function createFromArray(Campaign $campaign = null, array $array = array()) { $defaults = array("view_count" => 0, "like_count" => 0, "dislike_count" => 0, "favorite_count" => 0, "comment_count" => 0, "tw_share_count" => 0, "fb_share_count" => 0); $array = array_merge($defaults, $array); $content = new self($array['id'], $campaign); $content->setSource($array['source']); $content->setFoundAt(new \DateTime($array['found_at'])); $content->setNativeId($array['native_id']); $content->setCreatedAt(new \DateTime($array['created_at'])); $content->setUrl($array['url']); $content->setThumb($array['thumb']); $content->setVideoSrc($array['video_src']); $content->setTitle($array['title']); $content->setDescription($array['description']); $content->setVideoLength($array['video_length']); $content->setUsername($array['username']); $content->setViewCount($array['view_count']); $content->setLikeCount($array['like_count']); $content->setDislikeCount($array['dislike_count']); $content->setFavCount($array['favorite_count']); $content->setCommentCount($array['comment_count']); $content->setTwCount($array['tw_share_count']); $content->setFbCount($array['fb_share_count']); $content->setProcessed($array['processed']); if ($array['processed']) { $content->setProcessedAt(new \DateTime($array['processed_at'])); } $content->setKeyword($array['keyword']); $content->setUserNativeId($array['user_native_id']); if (isset($array['popularity'])) { $content->setPopularity($array['popularity']); } if (isset($array['sr_status'])) { $content->setSrStatus($array['sr_status']); } else { if (isset($array['srstatus'])) { $content->setSrStatus($array['srstatus']); } } if (isset($array['followers'])) { $content->setUserReach($array['followers']); } return $content; }
public static function getById($id) { /** * @var $userdb \PDO */ global $userdb; $stmt = $userdb->prepare("SELECT `id`, `name`, `username`, `email`, `password` FROM jos_users WHERE `id` = :user_id"); $stmt->bindParam(':user_id', $id); $stmt->execute(); $userData = $stmt->fetch(\PDO::FETCH_ASSOC); $user = new self(); $user->setIsNew(false); $user->setId($userData['id']); $user->setName($userData['name']); $user->setUsername($userData['username']); $user->setEmail($userData['email']); $user->setPasswordHash($userData['password']); return $user; }
/** * Return (or create, assuming no external auth backend) a user based on * a provided openid identity * * @param string $identity * * @return \thebuggenie\core\entities\User */ public static function getByOpenID($identity) { $user = null; if ($user_id = tables\OpenIdAccounts::getTable()->getUserIDfromIdentity($identity)) { $user = \thebuggenie\core\entities\User::getB2DBTable()->selectById($user_id); } elseif (!framework\Settings::isUsingExternalAuthenticationBackend() && framework\Settings::getOpenIDStatus() == 'all') { $user = new self(); $user->setPassword(self::createPassword()); $user->setUsername(self::createPassword() . self::createPassword()); $user->setOpenIdLocked(); $user->setActivated(); $user->setEnabled(); $user->setValidated(); $user->save(); } return $user; }
/** * Creates a new Credentials object with the AuthMode::PUBLIC_KEY authorizationmdoe. Requires username and keys details. * @param string $username Authorization username * @param string $publicKey Public key path * @param string $privateKey Private key path * @param string $passphrase Passphrase for Private key (if required) * @return Credentials */ public static function withPublicKey($username, $publicKey, $privateKey, $passphrase = null) { $instance = new self(); $instance->setMode(AuthMode::PUBLIC_KEY); $instance->setUsername($username); $instance->setPublicKey($publicKey); $instance->setPrivateKey($privateKey, $passphrase); return $instance; }
/** * Returns Data Source Name String. * @access public * @static * @param string $driver Database Driver (cubrid|dblib|firebird|informix|mysql|mssql|oci|odbc|pgsql|sqlite|sybase) * @param string $database Database Name * @param string $host Host Name or URI * @param int $port Host Port * @param string $username Username * @param string $password Password * @return string */ public static function renderStatic($driver, $database, $host = NULL, $port = NULL, $username = NULL, $password = NULL) { $dsn = new self($driver, $database); $dsn->setHost($host); $dsn->setPort($port); $dsn->setUsername($username); $dsn->setPassword($password); return $dsn->render(); }
/** * Factory that fills the required fields of the user. * * @param string $username * @param string $password * @param string $email * * @return User */ public static function create($username, $password, $email) { $user = new self(); $user->setUsername($username); $user->setPassword($password); $user->setEmail($email); return $user; }
/** * @inheritdoc */ public static function initializeByObject(stdClass $Object) { $User = new self(); $User->setId($Object->id); $User->setFirstName($Object->first_name); if (isset($Object->last_name)) { $User->setLastName($Object->last_name); } if (isset($Object->username)) { $User->setUsername($Object->username); } return $User; }
/** * @param UserResponseInterface $response * @return User * @throws \InvalidArgumentException */ public static function fromOAuthResponse(UserResponseInterface $response) { $user = new self(); $user->setPassword('whatever'); $user->setEnabled(true); switch ($response->getResourceOwner()->getName()) { case 'facebook': $user->setFacebookId($response->getResponse()['id']); $user->setUsername('fb-' . $response->getResponse()['id']); $user->setDisplayableName($response->getResponse()['name']); if (isset($response->getResponse()['email']) && $response->getResponse()['email']) { $user->setEmail($response->getResponse()['email']); } else { $user->setEmail('fb-no-email-' . md5(rand()) . '@example.com'); } $user->setPictureUrl($response->getResponse()['picture']['data']['url']); break; case 'vkontakte': $responseInner = $response->getResponse()['response'][0]; $user->setVkontakteId($responseInner['uid']); $user->setUsername('vk-' . $responseInner['uid']); $user->setDisplayableName($responseInner['first_name'] . ' ' . $responseInner['last_name']); if ($response->getResponse()['email']) { $user->setEmail($response->getResponse()['email']); } else { //in VK user can hide his email, but FOS treats email as mandatory $user->setEmail('vk-hidden-email-' . md5(rand()) . '@example.com'); } $user->setPictureUrl($responseInner['photo_medium']); break; case 'twitter': $user->setTwitterId($response->getResponse()['id']); $user->setUsername('twitter-' . $response->getResponse()['id']); $user->setDisplayableName($response->getResponse()['name']); $user->setEmail('twitter-email-' . md5(rand()) . '@example.com'); $user->setPictureUrl($response->getResponse()['profile_image_url']); break; case 'google': $user->setGoogleId($response->getResponse()['id']); $user->setUsername('google-' . $response->getResponse()['id']); $user->setDisplayableName($response->getResponse()['name']); $user->setEmail($response->getResponse()['email']); $user->setPictureUrl($response->getResponse()['picture']); break; default: throw new \InvalidArgumentException(sprintf('Resource owner `%` is not supported', $response->getResourceOwner()->getName())); } return $user; }
/** * Builds a new URI object from server environment * * @param array $environment Server environment (e.g. $_SERVER) * @return Uri */ public static function fromEnvironment(array $environment) { $uri = new self(); $uri->setScheme(isset($environment['HTTPS']) && ($environment['HTTPS'] == 'on' || $environment['HTTPS'] == 1) || isset($environment['HTTP_X_FORWARDED_PROTO']) && $environment['HTTP_X_FORWARDED_PROTO'] == 'https' ? 'https' : 'http'); $uri->setHostname($environment['HTTP_HOST']); $uri->setPort(isset($environment['SERVER_PORT']) ? (int) $environment['SERVER_PORT'] : NULL); $uri->setUsername(isset($environment['PHP_AUTH_USER']) ? $environment['PHP_AUTH_USER'] : NULL); $uri->setPassword(isset($environment['PHP_AUTH_PW']) ? $environment['PHP_AUTH_PW'] : NULL); $requestUriParts = explode('?', $environment['REQUEST_URI'], 2); $uri->setPath($requestUriParts[0]); if (isset($requestUriParts[1])) { $queryParts = explode('#', $requestUriParts[1], 2); $uri->setQuery($queryParts[0]); $uri->setFragment(isset($queryParts[1]) ? $queryParts[1] : NULL); } return $uri; }
/** * {@inheritdoc} */ public static function fromArray(array $values) { $message = new self(); $values = array_merge(['creation_timestamp_ms' => null, 'username' => null, 'team' => null, 'tutorial_state' => [], 'avatar' => null, 'max_pokemon_storage' => null, 'max_item_storage' => null, 'daily_bonus' => null, 'equipped_badge' => null, 'contact_settings' => null, 'currencies' => [], 'remaining_codename_claims' => null, 'buddy_pokemon' => null, 'battle_lockout_end_ms' => null], $values); $message->setCreationTimestampMs($values['creation_timestamp_ms']); $message->setUsername($values['username']); $message->setTeam($values['team']); $message->setAvatar($values['avatar']); $message->setMaxPokemonStorage($values['max_pokemon_storage']); $message->setMaxItemStorage($values['max_item_storage']); $message->setDailyBonus($values['daily_bonus']); $message->setEquippedBadge($values['equipped_badge']); $message->setContactSettings($values['contact_settings']); $message->setRemainingCodenameClaims($values['remaining_codename_claims']); $message->setBuddyPokemon($values['buddy_pokemon']); $message->setBattleLockoutEndMs($values['battle_lockout_end_ms']); foreach ($values['tutorial_state'] as $item) { $message->addTutorialState($item); } foreach ($values['currencies'] as $item) { $message->addCurrencies($item); } return $message; }