Пример #1
0
 /**
  * UserTest::testUserDataIntegrity()
  * 
  * @return void
  */
 public function testUserDataIntegrity()
 {
     # See if basic data matched
     $pilot = PilotData::getPilotByEmail('*****@*****.**');
     foreach ($this->registrationData as $key => $value) {
         if ($key == 'password') {
             continue;
         }
         $this->assertEquals($value, $pilot->{$key}, "Checking {$key}");
     }
     # Did they get added to the default group?
     $defaultGroup = SettingsData::getSettingValue('DEFAULT_GROUP');
     $pilotGroups = PilotGroups::getUserGroups($pilot->pilotid);
     $this->assertNotEmpty($pilotGroups, 'PilotGroups::getUserGroups()');
     $found = false;
     foreach ($pilotGroups as $group) {
         if (strtolower(trim($group->name)) == strtolower(trim($defaultGroup))) {
             $found = true;
             break;
         }
     }
     $this->assertTrue($found, 'User found in default group');
 }
Пример #2
0
 /**
  * Add a  User
  * 
  * $data = array(
  * 'firstname' => '',
  * 'lastname' => '',
  * 'email' => '',
  * 'password' => '',
  * 'code' => '',
  * 'location' => '',
  * 'hub' => '',
  * 'confirm' => false);
  */
 public static function addUser($data)
 {
     /*$data = array(
       'firstname' => '',
       'lastname' => '',
       'email' => '',
       'password' => '',
       'code' => '',
       'location' => '',
       'hub' => '',
       'confirm' => false);*/
     $exists = self::CheckUserEmail($data['email']);
     if (is_object($exists)) {
         self::$error = 'Email already exists';
         return false;
     }
     //Set the password, add some salt
     $salt = md5(date('His'));
     $password = md5($data['password'] . $salt);
     //Stuff it into here, the confirmation email will use it.
     self::$salt = $salt;
     $code = DB::escape(strtoupper($data['code']));
     $firstname = DB::escape(ucwords($data['firstname']));
     $lastname = DB::escape(ucwords($data['lastname']));
     $location = DB::escape(strtoupper($data['location']));
     //Add this stuff in
     if ($data['confirm'] === true) {
         $confirm = 1;
     } else {
         $confirm = 0;
     }
     $sql = "INSERT INTO " . TABLE_PREFIX . "pilots (firstname, lastname, email,\n\t\t\t\t\tcode, location, hub, password, salt, confirmed, joindate, lastip)\n\t\t\t\t  VALUES ('{$firstname}', '{$lastname}', '{$data['email']}', '{$code}',\n\t\t\t\t\t\t\t'{$location}', '{$data['hub']}', '{$password}', '{$salt}', {$confirm}, NOW(), '{$_SERVER['REMOTE_ADDR']}')";
     $res = DB::query($sql);
     if (DB::errno() != 0) {
         if (DB::errno() == 1062) {
             self::$error = 'This email address is already registered';
             return false;
         }
         self::$error = DB::error();
         return false;
     }
     //Grab the new pilotid, we need it to insert those "custom fields"
     $pilotid = DB::$insert_id;
     RanksData::CalculateUpdatePilotRank($pilotid);
     PilotData::GenerateSignature($pilotid);
     /* Add them to the default group */
     $defaultGroup = SettingsData::getSettingValue('DEFAULT_GROUP');
     PilotGroups::addUsertoGroup($pilotid, $defaultGroup);
     // For later
     self::$pilotid = $pilotid;
     //Get customs fields
     $fields = self::GetCustomFields();
     if (!$fields) {
         return true;
     }
     foreach ($fields as $field) {
         $value = Vars::POST($field->fieldname);
         $value = DB::escape($value);
         if ($value != '') {
             $sql = "INSERT INTO " . TABLE_PREFIX . "fieldvalues (fieldid, pilotid, value)\n\t\t\t\t\t\t\tVALUES ({$field->fieldid}, {$pilotid}, '{$value}')";
             DB::query($sql);
         }
     }
     return true;
 }