Beispiel #1
0
 public function run()
 {
     $faker = Faker::create();
     $log = new Stream('php://stdout');
     $log->info('Start ' . __CLASS__);
     /** @var Phalcon\Db\AdapterInterface $database */
     $database = $this->getDI()->get('db');
     $database->begin();
     for ($i = 0; $i <= self::USERS_TOTAL; $i++) {
         $user = new Users();
         $user->username = $faker->userName;
         $user->email = $faker->email;
         $user->timezone = $faker->timezone;
         $user->moderator = rand(0, 1) ? 'Y' : 'N';
         $user->karma = mt_rand(10, 20000);
         $user->vote = mt_rand(10, 200);
         $user->votePoint = mt_rand(10, 100);
         $user->gender = rand(0, 1) ? 1 : 2;
         //1-male, 2-female
         $user->passwd = 'todolate';
         $user->status = 1;
         //1-active, 2-pending
         $user->theme = 'D';
         if (!$user->save()) {
             var_dump($users->getMessages());
             $database->rollback();
             die;
         }
         $log->info('users: ' . $user->getUsername());
     }
 }
Beispiel #2
0
 /**
  * @param string $uid       to checking condition when authentication again
  * @param object $user      here is oauth
  * @param object $toekn     here it is token get by oauth
  * @param object $object    here is it is find in database
  * @param string $nameOauth there are google, github, facebook...
  *
  * @return mixed
  */
 public function commonOauthSave($uid, $user, $token, $object, $nameOauth)
 {
     if (!$object) {
         $object = new Users();
         //setTokenGithub or setTokenGoogle
         $tokenName = 'setToken' . $nameOauth;
         $object->{$tokenName}($token->accessToken);
         $object->setTokenType(Users::TOKEN_TYPE);
         $object->setUid($uid);
         $object->setEmail($user->email);
         $object->setFirstname($user->firstName);
         //@ Todo later, it perfect if we do haven't delete in database
         $username = '******' . (Users::count() + 1);
         $object->setUsername($username);
         if (empty($user->email)) {
             $object->setEmail($username . '*****@*****.**');
         }
         $object->setStatus(Users::STATUS_ACTIVE);
         $object->increaseKarma(Karma::LOGIN);
     }
     //Update session id
     session_regenerate_id(true);
     if (!$object->save()) {
         $this->displayModelErrors($object);
         return $this->indexRedirect();
     }
     //Store the user data in session
     $this->auth->setSession($object);
     //Store the user data in cookies
     $this->auth->setRememberEnviroment($object);
     //Dispaly notification when user login
     $this->notification($object);
     return $this->currentRedirect();
 }
Beispiel #3
0
 public function testValidateReturnsFalseIfDuplicateEmail()
 {
     $user = new Users();
     $user->email = '*****@*****.**';
     $this->assertFalse($user->save(), "New User should not created");
 }