本文整理汇总了PHP中UserController::apiCreate方法的典型用法代码示例。如果您正苦于以下问题:PHP UserController::apiCreate方法的具体用法?PHP UserController::apiCreate怎么用?PHP UserController::apiCreate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UserController
的用法示例。
在下文中一共展示了UserController::apiCreate方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: createUser
/**
* Creates a native user in Omegaup and returns the DAO populated
*
* @param string $username optional
* @param string $password optional
* @param string $email optional
* @return user (DAO)
*/
public static function createUser($username = null, $password = null, $email = null, $verify = true)
{
// If data is not provided, generate it randomly
if (is_null($username)) {
$username = Utils::CreateRandomString();
}
if (is_null($password)) {
$password = Utils::CreateRandomString();
}
if (is_null($email)) {
$email = Utils::CreateRandomString() . '@mail.com';
}
// Populate a new Request to pass to the API
UserController::$permissionKey = uniqid();
$r = new Request(array('username' => $username, 'name' => $username, 'password' => $password, 'email' => $email, 'permission_key' => UserController::$permissionKey));
// Call the API
$response = UserController::apiCreate($r);
// If status is not OK
if (strcasecmp($response['status'], 'ok') !== 0) {
throw new Exception('UserFactory::createUser failed');
}
// Get user from db
$user = UsersDAO::FindByUsername($username);
if ($verify) {
UserController::$redirectOnVerify = false;
$user = self::verifyUser($user);
} else {
$user->verified = 0;
UsersDAO::save($user);
}
// Password came hashed from DB. Set password in plaintext
$user->setPassword($password);
return $user;
}
示例2: LoginViaFacebook
public function LoginViaFacebook()
{
//ok, the user does not have any auth token
//if he wants to test facebook login
//Facebook must send me the state=something
//query, so i dont have to be testing
//facebook sessions on every single petition
//made from the front-end
if (!isset($_GET['state'])) {
return false;
}
//if that is not true, may still be logged with
//facebook, lets test that
$facebook = self::getFacebookInstance();
// Get User ID
$fb_user = $facebook->getUser();
if ($fb_user == 0) {
self::$log->info('FB session unavailable.');
return false;
}
// We may or may not have this data based on whether the user is logged in.
// If we have a $fb_user id here, it means we know the user is logged into
// Facebook, but we don't know if the access token is valid. An access
// token is invalid if the user logged out of Facebook.
try {
// Proceed knowing you have a logged in user who's authenticated.
$fb_user_profile = $facebook->api('/me');
} catch (FacebookApiException $e) {
$fb_user = null;
self::$log->error('FacebookException:' . $e);
return false;
}
//ok we know the user is logged in,
//lets look for his information on the database
//if there is none, it means that its the first
//time the user has been here, lets register his info
self::$log->info('User is logged in via facebook !!');
$results = UsersDAO::FindByEmail($fb_user_profile['email']);
if (!is_null($results)) {
//user has been here before with facebook!
$vo_User = $results;
self::$log->info('user has been here before with facebook!');
} else {
// The user has never been here before, let's register him
// I have a problem with this:
$username = self::getUniqueUsernameFromEmail($fb_user_profile['email']);
// Even if the user gave us his/her email, we should not
// just go ahead and assume its ok to share with the world
// maybe we could do:
// $username = str_replace(" ", "_", $fb_user_profile["name"] ),
UserController::$permissionKey = uniqid();
$r = new Request(array('name' => $fb_user_profile['name'], 'username' => $username, 'email' => $fb_user_profile['email'], 'facebook_user_id' => $fb_user_profile['id'], 'password' => null, 'permission_key' => UserController::$permissionKey, 'ignore_password' => true));
try {
$res = UserController::apiCreate($r);
} catch (ApiException $e) {
self::$log->error('Unable to login via Facebook ' . $e);
return false;
}
$vo_User = UsersDAO::getByPK($res['user_id']);
}
//since we got here, this user does not have
//any auth token, lets give him one
//so we dont have to call facebook to see
//if he is still logged in, and he can call
//the api
$this->RegisterSession($vo_User);
}
示例3: testUsernameWithInvalidChars
/**
* Tests usernames with invalid chars. Exception is expected
*
* @expectedException InvalidParameterException
*/
public function testUsernameWithInvalidChars()
{
UserController::$permissionKey = uniqid();
// Inflate request
$r = new Request(array('username' => 'ínvalid username', 'password' => Utils::CreateRandomString(), 'email' => Utils::CreateRandomString() . '@' . Utils::CreateRandomString() . '.com', 'permission_key' => UserController::$permissionKey));
// Call API
$response = UserController::apiCreate($r);
}
示例4: testUsernameWithInvalidChars
/**
* Tests usernames with invalid chars. Exception is expected
*
* @expectedException InvalidParameterException
*/
public function testUsernameWithInvalidChars()
{
UserController::$permissionKey = uniqid();
// Inflate request
$r = new Request(array("username" => "ínvalid username", "password" => Utils::CreateRandomString(), "email" => Utils::CreateRandomString() . "@" . Utils::CreateRandomString() . ".com", "permission_key" => UserController::$permissionKey));
// Call API
$response = UserController::apiCreate($r);
}