本文整理汇总了PHP中UserFactory类的典型用法代码示例。如果您正苦于以下问题:PHP UserFactory类的具体用法?PHP UserFactory怎么用?PHP UserFactory使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了UserFactory类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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);
}
开发者ID:kukogit,项目名称:omegaup,代码行数:36,代码来源:ContestsFactory.php
示例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;
}
}
}
开发者ID:essif,项目名称:fadls-vaip,代码行数:32,代码来源:Models.php
示例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"]));
}
开发者ID:kukogit,项目名称:omegaup,代码行数:28,代码来源:ContestUsersTest.php
示例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);
}
开发者ID:kukogit,项目名称:omegaup,代码行数:43,代码来源:ProblemsFactory.php
示例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']);
}
开发者ID:andreasantillana,项目名称:omegaup,代码行数:31,代码来源:ContestStatsTest.php
示例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"]);
}
开发者ID:kukogit,项目名称:omegaup,代码行数:29,代码来源:ContestRunsTest.php
示例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']));
}
开发者ID:andreasantillana,项目名称:omegaup,代码行数:27,代码来源:ContestRemoveUserTest.php
示例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());
}
开发者ID:kukogit,项目名称:omegaup,代码行数:30,代码来源:ClarificationCreateTest.php
示例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());
}
开发者ID:andreasantillana,项目名称:omegaup,代码行数:30,代码来源:EmailVerificationUITest.php
示例10: instance
public static function instance()
{
if (!isset(self::$singleton)) {
self::$singleton = new UserFactory();
}
return self::$singleton;
}
开发者ID:Artorias91,项目名称:Progetto-AMM,代码行数:7,代码来源:UserFactory.php
示例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"]));
}
开发者ID:kukogit,项目名称:omegaup,代码行数:28,代码来源:UserUpdateTest.php
示例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);
}
开发者ID:RicardoMelgoza,项目名称:omegaup,代码行数:38,代码来源:ContestsFactory.php
示例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);
}
开发者ID:heduenas,项目名称:omegaup,代码行数:59,代码来源:RegisterToContestTest.php
示例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']));
}
开发者ID:andreasantillana,项目名称:omegaup,代码行数:8,代码来源:CoderOfTheMonthTest.php
示例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;
}
开发者ID:alachaum,项目名称:timetrex,代码行数:18,代码来源:UserSettingListFactory.class.php
示例16: testNoProblems
public function testNoProblems()
{
$author = UserFactory::createUser();
// Call API
// Call api
$r = new Request(array("auth_token" => self::login($author)));
$response = UserController::apiProblems($r);
$this->assertEquals(0, count($response["problems"]));
}
开发者ID:kukogit,项目名称:omegaup,代码行数:9,代码来源:UserProblemsTest.php
示例17: testUserRankByProblemsSolvedWith0Runs
/**
* Tests apiRankByProblemsSolved for a specific user with no runs
*/
public function testUserRankByProblemsSolvedWith0Runs()
{
// Create a user and sumbit a run with him
$contestant = UserFactory::createUser();
// Call API
$response = UserController::apiRankByProblemsSolved(new Request(array('username' => $contestant->getUsername())));
$this->assertEquals($response['name'], $contestant->getName());
$this->assertEquals($response['problems_solved'], 0);
$this->assertEquals($response['rank'], 0);
}
开发者ID:RicardoMelgoza,项目名称:omegaup,代码行数:13,代码来源:UserRankTest.php
示例18: testBadUserUpdate
/**
* @expectedException InvalidDatabaseOperationException
*/
public function testBadUserUpdate()
{
$user = UserFactory::createUser();
$r = new Request();
$r['auth_token'] = $this->login($user);
$r['name'] = Utils::CreateRandomString();
// Invalid state_id
$r['state_id'] = -1;
UserController::apiUpdate($r);
}
开发者ID:andreasantillana,项目名称:omegaup,代码行数:13,代码来源:UserUpdateTest.php
示例19: UserFactory
/**
* @test
*/
public function ユーザーエンティティを生成する()
{
$factory = new UserFactory();
$entity = $factory->entity(json_decode('{
"account_id": 123,
"room_id": 322,
"name": "John Smith",
"chatwork_id": "tarochatworkid",
"organization_id": 101,
"organization_name": "Hello Company",
"department": "Marketing",
"title": "CMO",
"url": "http://mycompany.com",
"introduction": "Self Introduction",
"mail": "[email protected]",
"tel_organization": "XXX-XXXX-XXXX",
"tel_extension": "YYY-YYYY-YYYY",
"tel_mobile": "ZZZ-ZZZZ-ZZZZ",
"skype": "myskype_id",
"facebook": "myfacebook_id",
"twitter": "mytwitter_id",
"avatar_image_url": "https://example.com/abc.png"
}', true));
$this->assertEquals(123, $entity->accountId);
$this->assertEquals(322, $entity->roomId);
$this->assertEquals('John Smith', $entity->name);
$this->assertEquals('tarochatworkid', $entity->chatworkId);
$this->assertEquals(101, $entity->organizationId);
$this->assertEquals('Hello Company', $entity->organizationName);
$this->assertEquals('Marketing', $entity->department);
$this->assertEquals('CMO', $entity->title);
$this->assertEquals('http://mycompany.com', $entity->url);
$this->assertEquals('Self Introduction', $entity->introduction);
$this->assertEquals('[email protected]', $entity->mail);
$this->assertEquals('XXX-XXXX-XXXX', $entity->telOrganization);
$this->assertEquals('YYY-YYYY-YYYY', $entity->telExtension);
$this->assertEquals('ZZZ-ZZZZ-ZZZZ', $entity->telMobile);
$this->assertEquals('myskype_id', $entity->skype);
$this->assertEquals('myfacebook_id', $entity->facebook);
$this->assertEquals('mytwitter_id', $entity->twitter);
$this->assertEquals('https://example.com/abc.png', $entity->avatarImageUrl);
}
开发者ID:polidog,项目名称:php-chatwork-api,代码行数:45,代码来源:UserFactoryTest.php
示例20: Login
function Login()
{
if (isset($_POST['submit'])) {
if ($user = UserFactory::login($_POST['email'], md5($_POST['password']))) {
setcookie('user_id', $user->getUserId(), time() + 3600, '/');
setcookie('email', $user->getEmail(), time() + 3600, '/');
setcookie('password', $user->getPassword(), time() + 3600, '/');
header('location: /Welcome/');
}
}
$this->views->flush('body', 'login');
}
开发者ID:bagvendt,项目名称:vaip,代码行数:12,代码来源:Users.php
注:本文中的UserFactory类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论