php Model-User类(方法)实例源码

下面列出了php Model-User 类(方法)源码代码实例,从而了解它的用法。

作者:rbertan    项目:kanboar   
public function testHandlePayload()
 {
     $w = new MailgunWebhook($this->container);
     $p = new Project($this->container);
     $pp = new ProjectPermission($this->container);
     $u = new User($this->container);
     $tc = new TaskCreation($this->container);
     $tf = new TaskFinder($this->container);
     $this->assertEquals(2, $u->create(array('name' => 'me', 'email' => 'me@localhost')));
     $this->assertEquals(1, $p->create(array('name' => 'test1')));
     $this->assertEquals(2, $p->create(array('name' => 'test2', 'identifier' => 'TEST1')));
     // Empty payload
     $this->assertFalse($w->parsePayload(array()));
     // Unknown user
     $this->assertFalse($w->parsePayload(array('sender' => 'a@b.c', 'subject' => 'Email task', 'recipient' => 'foobar', 'stripped-text' => 'boo')));
     // Project not found
     $this->assertFalse($w->parsePayload(array('sender' => 'me@localhost', 'subject' => 'Email task', 'recipient' => 'foo+test@localhost', 'stripped-text' => 'boo')));
     // User is not member
     $this->assertFalse($w->parsePayload(array('sender' => 'me@localhost', 'subject' => 'Email task', 'recipient' => 'foo+test1@localhost', 'stripped-text' => 'boo')));
     $this->assertTrue($pp->addMember(2, 2));
     // The task must be created
     $this->assertTrue($w->parsePayload(array('sender' => 'me@localhost', 'subject' => 'Email task', 'recipient' => 'foo+test1@localhost', 'stripped-text' => 'boo')));
     $task = $tf->getById(1);
     $this->assertNotEmpty($task);
     $this->assertEquals(2, $task['project_id']);
     $this->assertEquals('Email task', $task['title']);
     $this->assertEquals('boo', $task['description']);
     $this->assertEquals(2, $task['creator_id']);
 }

作者:0xff-fanati    项目:kanboar   
public function testHtml2Markdown()
 {
     $w = new Postmark($this->container);
     $p = new Project($this->container);
     $pp = new ProjectPermission($this->container);
     $u = new User($this->container);
     $tc = new TaskCreation($this->container);
     $tf = new TaskFinder($this->container);
     $this->assertEquals(2, $u->create(array('username' => 'me', 'email' => 'me@localhost')));
     $this->assertEquals(1, $p->create(array('name' => 'test2', 'identifier' => 'TEST1')));
     $this->assertTrue($pp->addMember(1, 2));
     $this->assertTrue($w->receiveEmail(array('From' => 'me@localhost', 'Subject' => 'Email task', 'MailboxHash' => 'test1', 'TextBody' => 'boo', 'HtmlBody' => '<p><strong>boo</strong></p>')));
     $task = $tf->getById(1);
     $this->assertNotEmpty($task);
     $this->assertEquals(1, $task['project_id']);
     $this->assertEquals('Email task', $task['title']);
     $this->assertEquals('**boo**', $task['description']);
     $this->assertEquals(2, $task['creator_id']);
     $this->assertTrue($w->receiveEmail(array('From' => 'me@localhost', 'Subject' => 'Email task', 'MailboxHash' => 'test1', 'TextBody' => '**boo**', 'HtmlBody' => '')));
     $task = $tf->getById(2);
     $this->assertNotEmpty($task);
     $this->assertEquals(1, $task['project_id']);
     $this->assertEquals('Email task', $task['title']);
     $this->assertEquals('**boo**', $task['description']);
     $this->assertEquals(2, $task['creator_id']);
 }

作者:sdgdsffdsff    项目:open-sesam   
public function run()
 {
     $iAccountID = $this->get('id');
     $oAccount = new m\Account();
     $aDetail = $oAccount->getAccountDetail($iAccountID);
     if (empty($aDetail)) {
         c\Router::redirect(c\Router::genURL('Home'));
     }
     $aFields = $oAccount->getAccountFields($iAccountID);
     $oUser = new m\User();
     $aDefaultPassword = $oUser->getDefaultPassword();
     $aEmails = $oUser->getEmails();
     foreach ($aFields as $k => $v) {
         $aFields[$k]['display'] = u\Str::partCover($v['value'], 2, 1);
     }
     sort($aFields);
     $aFieldNames = array_map(function ($v) {
         foreach ($v as $key => $value) {
             if ($key !== 'name') {
                 unset($v[$key]);
             }
         }
         return $v;
     }, $aFields);
     $aAccountAll = $oAccount->getAllAccount();
     $aSiteList = [];
     foreach ($aAccountAll as $aAccountDetail) {
         $aSiteList[] = ['name' => 'link:' . $aAccountDetail['name']];
     }
     $aData = ['page_title' => 'Open Sesame - ' . $aDetail['name'], 'app' => $aDetail, 'fields' => $aFields, 'form_action_add' => c\Router::genURL('AddField'), 'form_action_del' => c\Router::genURL('DeleteField'), 'form_action_updatefield' => c\Router::genURL('UpdateField'), 'form_action_updateaccount' => c\Router::genURL('UpdateAccount'), 'site_list' => json_encode($aSiteList), 'field_names' => json_encode($aFieldNames), 'default_password' => $aDefaultPassword['data'], 'emails' => $aEmails['data']];
     return $aData;
 }

作者:jasonmoofan    项目:kanboar   
public function testCloneProjectWithUsers()
 {
     $p = new Project($this->container);
     $c = new Category($this->container);
     $pp = new ProjectPermission($this->container);
     $u = new User($this->container);
     $this->assertEquals(2, $u->create(array('username' => 'unittest1', 'password' => 'unittest')));
     $this->assertEquals(3, $u->create(array('username' => 'unittest2', 'password' => 'unittest')));
     $this->assertEquals(4, $u->create(array('username' => 'unittest3', 'password' => 'unittest')));
     $this->assertEquals(1, $p->create(array('name' => 'P1')));
     $this->assertTrue($pp->addMember(1, 2));
     $this->assertTrue($pp->addMember(1, 4));
     $this->assertTrue($pp->addManager(1, 3));
     $this->assertTrue($pp->isMember(1, 2));
     $this->assertTrue($pp->isMember(1, 3));
     $this->assertTrue($pp->isMember(1, 4));
     $this->assertFalse($pp->isManager(1, 2));
     $this->assertTrue($pp->isManager(1, 3));
     $this->assertFalse($pp->isManager(1, 4));
     $this->assertEquals(2, $p->duplicate(1));
     $project = $p->getById(2);
     $this->assertNotEmpty($project);
     $this->assertEquals('P1 (Clone)', $project['name']);
     $this->assertEquals(3, count($pp->getMembers(2)));
     $this->assertTrue($pp->isMember(2, 2));
     $this->assertTrue($pp->isMember(2, 3));
     $this->assertTrue($pp->isMember(2, 4));
     $this->assertFalse($pp->isManager(2, 2));
     $this->assertTrue($pp->isManager(2, 3));
     $this->assertFalse($pp->isManager(2, 4));
 }

作者:js223k    项目:1dv608_registe   
public function saveNewUser(\model\User $newUser)
 {
     $newUser->getUserName();
     $file = fopen("data/" . $newUser->getUserName() . ".txt", "w");
     fwrite($file, $newUser->getPassword());
     fclose($file);
 }

作者:johnnypesol    项目:1dv608-php-projec   
public function SaveLoginOnClient(\model\User $user)
 {
     // Prepare values
     $cookieValues = implode(':', array($user->GetUserName(), $user->GetToken(), $user->GetSignature()));
     // Save values in cookie (expires in 30 days)
     return setcookie(self::$COOKIE_ID, $cookieValues, time() + 60 * 60 * 24 * self::$COOKIE_VALID_DAYS);
 }

作者:praveencs8    项目:kanboar   
public function testGetAll()
 {
     $u = new User($this->container);
     $p = new Project($this->container);
     $cf = new CustomFilter($this->container);
     $this->assertEquals(1, $p->create(array('name' => 'UnitTest 1')));
     $this->assertEquals(2, $p->create(array('name' => 'UnitTest 2')));
     $this->assertEquals(2, $u->create(array('username' => 'user 2')));
     $this->assertEquals(1, $cf->create(array('name' => 'My filter 1', 'filter' => 'color:blue', 'project_id' => 1, 'user_id' => 1)));
     $this->assertEquals(2, $cf->create(array('name' => 'My filter 2', 'filter' => 'color:red', 'project_id' => 1, 'user_id' => 1, 'is_shared' => 1)));
     $this->assertEquals(3, $cf->create(array('name' => 'My filter 3', 'filter' => 'color:green', 'project_id' => 1, 'user_id' => 2, 'is_shared' => 1)));
     $this->assertEquals(4, $cf->create(array('name' => 'My filter 4', 'filter' => 'color:brown', 'project_id' => 1, 'user_id' => 2, 'is_shared' => 0)));
     $this->assertEquals(5, $cf->create(array('name' => 'My filter 5', 'filter' => 'color:grey', 'project_id' => 2, 'user_id' => 2)));
     // Get filters for the project 1 and user 1
     $filters = $cf->getAll(1, 1);
     $this->assertCount(3, $filters);
     $this->assertEquals(1, $filters[0]['id']);
     $this->assertEquals('My filter 1', $filters[0]['name']);
     $this->assertEquals('color:blue', $filters[0]['filter']);
     $this->assertEquals(1, $filters[0]['project_id']);
     $this->assertEquals(1, $filters[0]['user_id']);
     $this->assertEquals(0, $filters[0]['is_shared']);
     $this->assertEquals('', $filters[0]['owner_name']);
     $this->assertEquals('admin', $filters[0]['owner_username']);
     $this->assertEquals(2, $filters[1]['id']);
     $this->assertEquals('My filter 2', $filters[1]['name']);
     $this->assertEquals('color:red', $filters[1]['filter']);
     $this->assertEquals(1, $filters[1]['project_id']);
     $this->assertEquals(1, $filters[1]['user_id']);
     $this->assertEquals(1, $filters[1]['is_shared']);
     $this->assertEquals('', $filters[1]['owner_name']);
     $this->assertEquals('admin', $filters[1]['owner_username']);
     $this->assertEquals(3, $filters[2]['id']);
     $this->assertEquals('My filter 3', $filters[2]['name']);
     $this->assertEquals('color:green', $filters[2]['filter']);
     $this->assertEquals(1, $filters[2]['project_id']);
     $this->assertEquals(2, $filters[2]['user_id']);
     $this->assertEquals(1, $filters[2]['is_shared']);
     $this->assertEquals('', $filters[2]['owner_name']);
     $this->assertEquals('user 2', $filters[2]['owner_username']);
     // Get filters for the project 1 and user 2
     $filters = $cf->getAll(1, 2);
     $this->assertCount(3, $filters);
     $this->assertEquals(2, $filters[0]['id']);
     $this->assertEquals('My filter 2', $filters[0]['name']);
     $this->assertEquals(3, $filters[1]['id']);
     $this->assertEquals('My filter 3', $filters[1]['name']);
     $this->assertEquals(4, $filters[2]['id']);
     $this->assertEquals('My filter 4', $filters[2]['name']);
     // Get filters for the project 2 and user 1
     $filters = $cf->getAll(2, 1);
     $this->assertCount(0, $filters);
     // Get filters for the project 2 and user 2
     $filters = $cf->getAll(2, 2);
     $this->assertCount(1, $filters);
     $this->assertEquals(5, $filters[0]['id']);
     $this->assertEquals('My filter 5', $filters[0]['name']);
     $this->assertEquals(0, $filters[0]['is_shared']);
 }

作者:flonolog    项目:UrlKeepe   
/**
  * @param User $user
  * @return UserDataObject
  */
 public function mapToDataObject(User $user)
 {
     $userDataObject = new UserDataObject();
     $userDataObject->id = $user->getId();
     $userDataObject->name = $user->getName();
     $userDataObject->passwordHash = $user->getPasswordHash();
     return $userDataObject;
 }

作者:OskarKlintrotSkolarbeteWP1    项目:1dv608-Projec   
public function doUserExist(User $user)
 {
     $this->database->prepare('SELECT * FROM users WHERE username = :username');
     $this->database->bindValue(':username', $user->getUsername());
     $this->database->fetchAll();
     if ($this->database->rowCount() > 0) {
         throw new exception\UserAlreadyExistException();
     }
 }

作者:redarro    项目:kanboar   
public function testHandleFailedLogin()
 {
     $u = new User($this->container);
     $a = new Authentication($this->container);
     $this->assertFalse($u->isLocked('admin'));
     for ($i = 0; $i <= 6; $i++) {
         $a->handleFailedLogin('admin');
     }
     $this->assertTrue($u->isLocked('admin'));
 }

作者:Janst    项目:PHP_MVC_Simple_Social_Networ   
/**
  * Used when the person who is currently logged in wants to stop following another user
  * @param User $user, person who is already following
  * @param $followee, a person who is being followed
  * @return bool
  */
 public function removeFollowee(\model\User $user, $followee)
 {
     $follower = $user->getUsername();
     try {
         DB::getInstance()->deleteFollowee($follower, $followee);
         return true;
     } catch (\Exception $e) {
         return false;
     }
 }

作者:redarro    项目:kanboar   
public function testSuccessfulAuthentication()
 {
     $_SERVER[REVERSE_PROXY_USER_HEADER] = 'my_user';
     $a = new ReverseProxy($this->container);
     $u = new User($this->container);
     $this->assertTrue($a->authenticate());
     $user = $u->getByUsername('my_user');
     $this->assertNotEmpty($user);
     $this->assertEquals(0, $user['is_admin']);
     $this->assertEquals(1, $user['is_ldap_user']);
     $this->assertEquals(1, $user['disable_login_form']);
 }

作者:hackathon-    项目:power-ragers-rep   
public function registerUser()
 {
     $user = new User();
     $user->setEmail($this->request_body->email);
     $user->setPassword(md5($this->request_body->password));
     $user->save();
     $token = new AccessToken();
     $token->setTokenContent(uniqid());
     $token->setUser($user);
     $token->save();
     return array('user' => $user->toArray(), 'token' => $token->toArray());
 }

作者:redarro    项目:kanboar   
public function testHandlePayload()
 {
     $w = new Sendgrid($this->container);
     $p = new Project($this->container);
     $pp = new ProjectPermission($this->container);
     $u = new User($this->container);
     $tc = new TaskCreation($this->container);
     $tf = new TaskFinder($this->container);
     $this->assertEquals(2, $u->create(array('username' => 'me', 'email' => 'me@localhost')));
     $this->assertEquals(1, $p->create(array('name' => 'test1')));
     $this->assertEquals(2, $p->create(array('name' => 'test2', 'identifier' => 'TEST1')));
     // Empty payload
     $this->assertFalse($w->receiveEmail(array()));
     // Unknown user
     $this->assertFalse($w->receiveEmail(array('envelope' => '{"to":["a@b.c"],"from":"a.b.c"}', 'subject' => 'Email task')));
     // Project not found
     $this->assertFalse($w->receiveEmail(array('envelope' => '{"to":["a@b.c"],"from":"me@localhost"}', 'subject' => 'Email task')));
     // User is not member
     $this->assertFalse($w->receiveEmail(array('envelope' => '{"to":["something+test1@localhost"],"from":"me@localhost"}', 'subject' => 'Email task')));
     $this->assertTrue($pp->addMember(2, 2));
     // The task must be created
     $this->assertTrue($w->receiveEmail(array('envelope' => '{"to":["something+test1@localhost"],"from":"me@localhost"}', 'subject' => 'Email task')));
     $task = $tf->getById(1);
     $this->assertNotEmpty($task);
     $this->assertEquals(2, $task['project_id']);
     $this->assertEquals('Email task', $task['title']);
     $this->assertEquals('', $task['description']);
     $this->assertEquals(2, $task['creator_id']);
     // Html content
     $this->assertTrue($w->receiveEmail(array('envelope' => '{"to":["something+test1@localhost"],"from":"me@localhost"}', 'subject' => 'Email task', 'html' => '<strong>bold</strong> text')));
     $task = $tf->getById(2);
     $this->assertNotEmpty($task);
     $this->assertEquals(2, $task['project_id']);
     $this->assertEquals('Email task', $task['title']);
     $this->assertEquals('**bold** text', $task['description']);
     $this->assertEquals(2, $task['creator_id']);
     // Text content
     $this->assertTrue($w->receiveEmail(array('envelope' => '{"to":["something+test1@localhost"],"from":"me@localhost"}', 'subject' => 'Email task', 'text' => '**bold** text')));
     $task = $tf->getById(3);
     $this->assertNotEmpty($task);
     $this->assertEquals(2, $task['project_id']);
     $this->assertEquals('Email task', $task['title']);
     $this->assertEquals('**bold** text', $task['description']);
     $this->assertEquals(2, $task['creator_id']);
     // Text + html content
     $this->assertTrue($w->receiveEmail(array('envelope' => '{"to":["something+test1@localhost"],"from":"me@localhost"}', 'subject' => 'Email task', 'html' => '<strong>bold</strong> html', 'text' => '**bold** text')));
     $task = $tf->getById(4);
     $this->assertNotEmpty($task);
     $this->assertEquals(2, $task['project_id']);
     $this->assertEquals('Email task', $task['title']);
     $this->assertEquals('**bold** html', $task['description']);
     $this->assertEquals(2, $task['creator_id']);
 }

作者:40mi    项目:testre   
/**
  * Write changes into history
  *
  * @param \Model\User $oldUser
  * @param \Model\User $newUser
  */
 protected function makeHistoryChanges(\Model\User $oldUser, \Model\User $newUser)
 {
     try {
         $history = new \Model\UsersHistory();
         $history->user_id = $oldUser->id;
         $history->was = $oldUser->toJson();
         $history->setted = $newUser->toJson();
         $history->save();
     } catch (\Exception $e) {
         // write err log
     }
 }

作者:OskarKlintrotSkolarbeteWP1    项目:1dv608-Projec   
public function validate()
 {
     unset($this->message);
     $this->message = array();
     $username = $this->getUsername();
     $password = $this->getPassword();
     $repeatedPassword = $this->getPasswordRepeat();
     $validateUser = new User($username, $password);
     try {
         $validateUser->testValidUsername();
     } catch (InvalidUsernameException $e) {
         $this->message[] = "Username contains invalid characters.";
     } catch (\Exception $e) {
         $this->message[] = $e;
     }
     try {
         $validateUser->testValidPassword();
     } catch (InvalidPasswordException $e) {
         $this->message[] = "Password contains invalid characters.";
     } catch (\Exception $e) {
         $this->message[] = $e;
     }
     try {
         $validateUser->testUsernameLength();
     } catch (ToShortUsernameException $e) {
         $this->message[] = "Username has too few characters, at least 3 characters.";
     } catch (\Exception $e) {
         $this->message[] = $e;
     }
     try {
         $validateUser->testPasswordLength();
     } catch (ToShortPasswordException $e) {
         $this->message[] = "Password has too few characters, at least 6 characters.";
     } catch (\Exception $e) {
         $this->message[] = $e;
     }
     if ($password != $repeatedPassword) {
         $this->message[] = "Passwords do not match.";
     }
     try {
         $this->dal->doUserExist($validateUser);
     } catch (UserAlreadyExistException $e) {
         $this->message[] = "User exists, pick another username.";
     } catch (\Exception $e) {
         $this->message[] = $e;
     }
     if (empty($this->message)) {
         return true;
     } else {
         return false;
     }
 }

作者:hj393    项目:kanboar   
public function testSendWithoutEmailAddress()
 {
     $en = new EmailNotification($this->container);
     $p = new Project($this->container);
     $tf = new TaskFinder($this->container);
     $tc = new TaskCreation($this->container);
     $u = new User($this->container);
     $this->assertEquals(1, $p->create(array('name' => 'test')));
     $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1)));
     $this->container['emailClient'] = $this->getMockBuilder('\\Core\\EmailClient')->setConstructorArgs(array($this->container))->setMethods(array('send'))->getMock();
     $this->container['emailClient']->expects($this->never())->method('send');
     $en->send($u->getById(1), Task::EVENT_CREATE, array('task' => $tf->getDetails(1)));
 }

作者:Janst    项目:PHP_MVC_Simple_Social_Networ   
public function addNewStatus(\model\User $user, $content)
 {
     if (strlen($content) > 255) {
         return false;
     }
     try {
         $username = $user->getUsername();
         DB::getInstance()->addStatusToDB($username, $content);
         return true;
     } catch (\Exception $e) {
         return false;
     }
 }

作者:rs222k    项目:1DV608_Logi   
public function save(\model\User $user)
 {
     if ($this->doExists($user->getUsername())) {
         throw new \Exception();
     }
     $stmt = $this->database->prepare("INSERT INTO  `lab4` (`username` , `password`) VALUES (?, ?)");
     if ($stmt === FALSE) {
         throw new \Exception($this->database->error);
     }
     $username = $user->getUsername();
     $password = $user->getPassword();
     $stmt->bind_param('ss', $username, $password);
     $stmt->execute();
 }

作者:schlef    项目:RuneAP   
public static function helloMathis($app)
 {
     $ajout = false;
     $username = 'mathis';
     $user = User::find($username);
     // Si $user n'est pas set, c'est qu'il n'y a rien et on ajoute donc en base !
     if (!isset($user)) {
         $user = new User();
         $user->name = $username;
         $user->save();
         $ajout = true;
     }
     $app->render('user.html.twig', array('ajout' => $ajout, 'autre' => 'ahah !', 'name' => $user->name));
 }


问题


面经


文章

微信
公众号

扫码关注公众号