本文整理汇总了PHP中UserFactory类的典型用法代码示例。如果您正苦于以下问题:PHP UserFactory类的具体用法?PHP UserFactory怎么用?PHP UserFactory使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了UserFactory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getRequest
/**
* Returns a Request object with complete context to create a contest
*
* @param string $title
* @param string $public
* @param Users $contestDirector
* @return Request
*/
public static function getRequest($title = null, $public = 0, Users $contestDirector = null, $languages = null)
{
if (is_null($contestDirector)) {
$contestDirector = UserFactory::createUser();
}
if (is_null($title)) {
$title = Utils::CreateRandomString();
}
// Set context
$r = new Request();
$r["title"] = $title;
$r["description"] = "description";
$r["start_time"] = Utils::GetPhpUnixTimestamp() - 60 * 60;
$r["finish_time"] = Utils::GetPhpUnixTimestamp() + 60 * 60;
$r["window_length"] = null;
$r["public"] = $public;
$r["alias"] = substr($title, 0, 20);
$r["points_decay_factor"] = ".02";
$r["partial_score"] = "0";
$r["submissions_gap"] = "0";
$r["feedback"] = "yes";
$r["penalty"] = 100;
$r["scoreboard"] = 100;
$r["penalty_type"] = "contest_start";
$r["penalty_calc_policy"] = "sum";
$r['languages'] = $languages;
return array("request" => $r, "director" => $contestDirector);
}
示例2: __construct
function __construct($dbhost, $dbuser, $dbpswd, $dbname)
{
// assert that the resources we need are there
if (!defined('MODELS')) {
die;
}
// Model-specs
require_once MODELS . '/UserFactory.php';
require_once MODELS . '/EmployeeFactory.php';
/*
require_once 'Shifts.php';
require_once 'Schemas.php';
*/
// Database
$this->dbhost = $dbhost;
$this->dbuser = $dbuser;
$this->dbpswd = $dbpswd;
$this->dbname = $dbname;
mysql_connect($this->dbhost, $this->dbuser, $this->dbpswd, $this->dbname);
mysql_select_db($this->dbname);
// User
$this->user = null;
if (isset($_SESSION['user_id'])) {
$this->user = UserFactory::create($_SESSION['user_id']);
} elseif (isset($_COOKIE['user_id']) && isset($_COOKIE['email']) && isset($_COOKIE['password'])) {
$user = UserFactory::create($_COOKIE['user_id']);
if ($user->getEmail() == $_COOKIE['email'] && $user->getPassword() == $_COOKIE['password']) {
$_SESSION['user_id'] = $user->getUserId();
$this->user = $user;
}
}
}
示例3: testContestUsersValid
public function testContestUsersValid()
{
// Get a contest
$contestData = ContestsFactory::createContest();
// Create 10 users
$n = 10;
$users = array();
for ($i = 0; $i < $n; $i++) {
// Create a user
$users[$i] = UserFactory::createUser();
// Add it to the contest
ContestsFactory::addUser($contestData, $users[$i]);
}
// Create a n+1 user who will just join to the contest withot being
// added via API. For public contests, by entering to the contest, the user should be in
// the list of contest's users.
$nonRegisteredUser = UserFactory::createUser();
ContestsFactory::openContest($contestData, $nonRegisteredUser);
// Prepare request
$r = new Request();
$r["contest_alias"] = $contestData["request"]["alias"];
// Log in with the admin of the contest
$r["auth_token"] = $this->login($contestData["director"]);
// Call API
$response = ContestController::apiUsers($r);
// Check that we have n+1 users
$this->assertEquals($n + 1, count($response["users"]));
}
示例4: getRequest
/**
* Returns a Request object with valid info to create a problem and the
* author of the problem
*
* @param string $title
* @param string $zipName
* @return Array
*/
public static function getRequest($zipName = null, $title = null, $public = 1, Users $author = null, $languages = null)
{
if (is_null($author)) {
$author = UserFactory::createUser();
}
if (is_null($title)) {
$title = Utils::CreateRandomString();
}
if (is_null($zipName)) {
$zipName = OMEGAUP_RESOURCES_ROOT . 'testproblem.zip';
}
$r = new Request();
$r["title"] = $title;
$r['alias'] = substr(preg_replace('/[^a-zA-Z0-9_-]/', '', str_replace(' ', '-', $r['title'])), 0, 32);
$r["author_username"] = $author->getUsername();
$r["validator"] = "token";
$r["time_limit"] = 5000;
$r["overall_wall_time_limit"] = 60000;
$r["validator_time_limit"] = 30000;
$r["extra_wall_time"] = 0;
$r["memory_limit"] = 32000;
$r["source"] = "yo";
$r["order"] = "normal";
$r["public"] = $public;
$r["output_limit"] = 10240;
if ($languages == null) {
$r["languages"] = 'c,cpp,py';
} else {
$r["languages"] = $languages;
}
$r["stack_limit"] = 10000;
// Set file upload context
$_FILES['problem_contents']['tmp_name'] = $zipName;
return array("request" => $r, "author" => $author, "zip_path" => $zipName);
}
示例5: testGetStatsNoWaitTime
/**
* Checks that, if there's no wait time, 0 is posted in max_wait_time
*/
public function testGetStatsNoWaitTime()
{
// Get a problem
$problemData = ProblemsFactory::createProblem();
// Get a contest
$contestData = ContestsFactory::createContest();
// Add the problem to the contest
ContestsFactory::addProblemToContest($problemData, $contestData);
// Create our contestant
$contestant = UserFactory::createUser();
$ACRunsCount = 2;
$ACRunsData = array();
for ($i = 0; $i < $ACRunsCount; $i++) {
$ACRunsData[$i] = RunsFactory::createRun($problemData, $contestData, $contestant);
// Grade the run
RunsFactory::gradeRun($ACRunsData[$i]);
}
// Create request
$r = new Request();
$r['contest_alias'] = $contestData['request']['alias'];
$r['auth_token'] = $this->login($contestData['director']);
// Call API
$response = ContestController::apiStats($r);
// Check number of pending runs
$this->assertEquals($ACRunsCount, $response['total_runs']);
$this->assertEquals(0, $response['max_wait_time']);
$this->assertEquals(0, $response['max_wait_time_guid']);
}
示例6: testGetRunsForContest
/**
* Contestant submits runs and admin is able to get them
*/
public function testGetRunsForContest()
{
// Get a problem
$problemData = ProblemsFactory::createProblem();
// Get a contest
$contestData = ContestsFactory::createContest();
// Add the problem to the contest
ContestsFactory::addProblemToContest($problemData, $contestData);
// Create our contestant
$contestant = UserFactory::createUser();
// Create a run
$runData = RunsFactory::createRun($problemData, $contestData, $contestant);
// Grade the run
RunsFactory::gradeRun($runData);
// Create request
$r = new Request();
$r["contest_alias"] = $contestData["request"]["alias"];
$r["auth_token"] = $this->login($contestData["director"]);
// Call API
$response = ContestController::apiRuns($r);
// Assert
$this->assertEquals(1, count($response["runs"]));
$this->assertEquals($runData["response"]["guid"], $response["runs"][0]["guid"]);
$this->assertEquals($contestant->username, $response["runs"][0]["username"]);
$this->assertEquals("J1", $response["runs"][0]["judged_by"]);
}
示例7: testRemoveUser
public function testRemoveUser()
{
// Get a contest
$contestData = ContestsFactory::createContest();
// Create a user
$user = UserFactory::createUser();
// Add user to contest
ContestsFactory::addUser($contestData, $user);
// Validate 0 users
$r = new Request();
$r['contest_alias'] = $contestData['request']['alias'];
$r['auth_token'] = $this->login($contestData['director']);
$response = ContestController::apiUsers($r);
$this->assertEquals(1, count($response['users']));
// Remove user
$r = new Request();
$r['contest_alias'] = $contestData['request']['alias'];
$r['usernameOrEmail'] = $user->getUsername();
$r['auth_token'] = $this->login($contestData['director']);
ContestController::apiRemoveUser($r);
// Validate 0 users in contest
$r = new Request();
$r['contest_alias'] = $contestData['request']['alias'];
$r['auth_token'] = $this->login($contestData['director']);
$response = ContestController::apiUsers($r);
$this->assertEquals(0, count($response['users']));
}
示例8: testCreateValidClarification
/**
* Creates a valid clarification
*/
public function testCreateValidClarification()
{
// Get a problem
$problemData = ProblemsFactory::createProblem();
// Get a contest
$contestData = ContestsFactory::createContest();
// Add the problem to the contest
ContestsFactory::addProblemToContest($problemData, $contestData);
// Create our contestant who will submit the clarification
$contestant = UserFactory::createUser();
// Call the API
$this->detourBroadcasterCalls();
$clarificationData = ClarificationsFactory::createClarification($problemData, $contestData, $contestant);
// Assert status of new contest
$this->assertArrayHasKey("clarification_id", $clarificationData['response']);
// Verify that clarification was inserted in the database
$clarification = ClarificationsDAO::getByPK($clarificationData['response']['clarification_id']);
// Verify our retreived clarificatoin
$this->assertNotNull($clarification);
$this->assertEquals($clarificationData['request']['message'], $clarification->getMessage());
// We need to verify that the contest and problem IDs where properly saved
// Extractiing the contest and problem from DB to check IDs
$problem = ProblemsDAO::getByAlias($problemData["request"]["alias"]);
$contest = ContestsDAO::getByAlias($contestData["request"]["alias"]);
$this->assertEquals($contest->getContestId(), $clarification->getContestId());
$this->assertEquals($problem->getProblemId(), $clarification->getProblemId());
}
示例9: testLogin
public function testLogin()
{
// Turn off sending email on usere creation
UserController::$sendEmailOnVerify = false;
// Create a user
$contestant = UserFactory::createUserWithoutVerify();
// Open index
$this->open('/');
// Click in Iniciar Sesion
$this->clickAndWait('link=Inicia sesion');
// Type login data
$this->type('user', $contestant->getUsername());
$this->type('pass', $contestant->getPassword());
// Click inicia sesion
$this->clickAndWait("//input[@value='Inicia sesion']");
// Wait for message
$this->waitForElementPresent('//*[@id="content"]/div[2]/div');
$this->assertElementContainsText('//*[@id="content"]/div[2]/div', 'Your email is not verified yet. Please check your e-mail.');
// Go to verification page and wait for redirection to login page
$this->open('/api/user/verifyemail/id/' . $contestant->getVerificationId());
$this->waitForElementPresent('//*[@id="content"]/div[2]/div[1]/h1');
// Type login data
$this->type('user', $contestant->getUsername());
$this->type('pass', $contestant->getPassword());
// Click inicia sesion
$this->clickAndWait("//input[@value='Inicia sesion']");
// Sanity check that we are logged in
$this->waitForElementPresent('//*[@id="wrapper"]/div[1]/a');
$this->assertElementContainsText('//*[@id="wrapper"]/div[1]/a', $contestant->getUsername());
}
示例10: instance
public static function instance()
{
if (!isset(self::$singleton)) {
self::$singleton = new UserFactory();
}
return self::$singleton;
}
示例11: testUserUpdate
/**
* Basic update test
*/
public function testUserUpdate()
{
// Create the user to edit
$user = UserFactory::createUser();
$r = new Request();
// Login
$r["auth_token"] = $this->login($user);
// Change values
$r["name"] = Utils::CreateRandomString();
$r["country_id"] = 'MX';
$r["state_id"] = 3;
$r["scholar_degree"] = 'Maestría';
$r["birth_date"] = strtotime('1988-01-01');
$r["graduation_date"] = strtotime('2016-02-02');
// Call api
$response = UserController::apiUpdate($r);
// Check user from db
$user_db = AuthTokensDAO::getUserByToken($r["auth_token"]);
$this->assertEquals($user_db->getName(), $r["name"]);
$this->assertEquals($user_db->getCountryId(), $r["country_id"]);
$this->assertEquals($user_db->getStateId(), $r["state_id"]);
$this->assertEquals($user_db->getScholarDegree(), $r["scholar_degree"]);
$this->assertEquals($user_db->getBirthDate(), gmdate('Y-m-d', $r["birth_date"]));
$this->assertEquals($user_db->getGraduationDate(), gmdate('Y-m-d', $r["graduation_date"]));
}
示例12: getRequest
/**
* Returns a Request object with complete context to create a contest
*
* @param string $title
* @param string $public
* @param Users $contestDirector
* @return Request
*/
public static function getRequest($title = null, $public = 0, Users $contestDirector = null, $languages = null, $finish_time = null)
{
if (is_null($contestDirector)) {
$contestDirector = UserFactory::createUser();
}
if (is_null($title)) {
$title = Utils::CreateRandomString();
}
// Set context
$r = new Request();
$r['title'] = $title;
$r['description'] = 'description';
$r['start_time'] = Utils::GetPhpUnixTimestamp() - 60 * 60;
$r['finish_time'] = $finish_time == null ? Utils::GetPhpUnixTimestamp() + 60 * 60 : $finish_time;
$r['window_length'] = null;
$r['public'] = $public;
$r['alias'] = substr($title, 0, 20);
$r['points_decay_factor'] = '.02';
$r['partial_score'] = '0';
$r['submissions_gap'] = '0';
$r['feedback'] = 'yes';
$r['penalty'] = 100;
$r['scoreboard'] = 100;
$r['penalty_type'] = 'contest_start';
$r['penalty_calc_policy'] = 'sum';
$r['languages'] = $languages;
$r['recommended'] = 0;
// This is just a default value, it is not honored by apiCreate.
return array('request' => $r, 'director' => $contestDirector);
}
示例13: testSimpleRegistrationActions
public function testSimpleRegistrationActions()
{
self::log("Started");
//create a contest and its admin
$contestData = ContestsFactory::createContest(null, 1);
$contestAdmin = UserFactory::createUser();
ContestsFactory::addAdminUser($contestData, $contestAdmin);
//make it "registrable"
self::log("Udate contest to make it registrable");
$r1 = new Request();
$r1["contest_alias"] = $contestData["request"]["alias"];
$r1["contestant_must_register"] = true;
$r1["auth_token"] = $this->login($contestAdmin);
ContestController::apiUpdate($r1);
//some user asks for contest
$contestant = UserFactory::createUser();
$r2 = new Request();
$r2["contest_alias"] = $contestData["request"]["alias"];
$r2["auth_token"] = $this->login($contestant);
try {
$response = ContestController::apiDetails($r2);
$this->AssertFalse(true, "User gained access to contest even though its registration needed.");
} catch (ForbiddenAccessException $fae) {
// Expected. Continue.
}
self::log("user registers, into contest");
ContestController::apiRegisterForContest($r2);
//admin lists registrations
$r3 = new Request();
$r3["contest_alias"] = $contestData["request"]["alias"];
$r3["auth_token"] = $this->login($contestAdmin);
$result = ContestController::apiRequests($r3);
$this->assertEquals(sizeof($result["users"]), 1);
self::log("amin rejects registration");
$r3["username"] = $contestant->username;
$r3["resolution"] = false;
ContestController::apiArbitrateRequest($r3);
//ask for details again, this should fail again
$r2 = new Request();
$r2["contest_alias"] = $contestData["request"]["alias"];
$r2["auth_token"] = $this->login($contestant);
try {
$response = ContestController::apiDetails($r2);
$this->AssertFalse(true);
} catch (ForbiddenAccessException $fae) {
// Expected. Continue.
}
//admin admits user
$r3["username"] = $contestant->username;
$r3["resolution"] = true;
ContestController::apiArbitrateRequest($r3);
//user can now submit to contest
$r2 = new Request();
$r2["contest_alias"] = $contestData["request"]["alias"];
$r2["auth_token"] = $this->login($contestant);
// Explicitly join contest
ContestController::apiOpen($r2);
ContestController::apiDetails($r2);
}
示例14: testCoderOfTheMonthList
public function testCoderOfTheMonthList()
{
$user = UserFactory::createUser();
$auth_token = $this->login($user);
$r = new Request(array('auth_token' => $auth_token));
$response = UserController::apiCoderOfTheMonthList($r);
$this->assertEquals(1, count($response['coders']));
}
示例15: getByCompanyId
function getByCompanyId($company_id, $where = NULL, $order = NULL)
{
if ($company_id == '') {
return FALSE;
}
$uf = new UserFactory();
$ph = array('company_id' => $company_id);
$query = '
select a.*
from ' . $this->getTable() . ' as a
LEFT JOIN ' . $uf->getTable() . ' as uf ON a.user_id = uf.id
where uf.company_id = ?
AND ( uf.deleted = 0 )';
$query .= $this->getWhereSQL($where);
$query .= $this->getSortSQL($order);
$this->ExecuteSQL($query, $ph);
return $this;
}