Example #1
0
 public function testCreate()
 {
     $user = new User();
     $user->setId(1);
     $user->setEmail('*****@*****.**');
     $user->setPassword('xxxx');
     $user->setFirstName('John');
     $user->setLastName('Doe');
     $user->addRole(new UserRole());
     $user->addVehicle(new Vehicle());
     $this->assertSame(null, $user->getUpdated());
     $user->setUpdated();
     $user->preUpdate();
     $this->assertSame(1, $user->getId());
     $this->assertTrue($user->getCreated() instanceof \DateTime);
     $this->assertTrue($user->getUpdated() instanceof \DateTime);
     $this->assertSame('*****@*****.**', $user->getEmail());
     $this->assertSame('John', $user->getFirstName());
     $this->assertSame('Doe', $user->getLastName());
     $this->assertTrue($user->getRoles()[0] instanceof UserRole);
     $this->assertTrue($user->getVehicles()[0] instanceof Vehicle);
 }
Example #2
0
 /**
  * Extra test: password migration.
  * Manually insert an old-style password hash in the database, then
  * make sure that the password field in the database gets updated when
  * the migration function is invoked.
  * @depends testLegacyPassword
  */
 public function testPasswordMigration()
 {
     global $testUserId1;
     $password = '******';
     $oldPasswordHash = '$0$6cc7c5a5a21978e5587a59186cadb5e3';
     $object = new User($testUserId1);
     $object->save();
     // Update the database and check for match
     $query = "UPDATE blogUser " . "SET password='******' " . "WHERE userId='{$testUserId1}'";
     mysql_query($query);
     $object->load($testUserId1);
     $rows = $this->countTestRows();
     $this->assertTrue($object->checkPassword($password));
     $object->updatePasswordHash($password);
     // make sure a new row has been inserted
     $this->assertEquals($rows + 1, $this->countTestRows());
     // Check that the password has been re-encoded in the
     // in the database
     $updated = $object->getUpdated();
     $query = "SELECT password " . "FROM blogUser " . "WHERE userId='{$testUserId1}' " . "AND updated='{$updated}'";
     // print "$query\n";
     $result = mysql_query($query);
     if ($result) {
         $this->assertTrue(mysql_num_rows($result) === 1);
         $line = mysql_fetch_array($result);
         $newPasswordHash = db_sql_decode($line[0]);
         $this->assertNotEquals($oldPasswordHash, $newPasswordHash);
     } else {
         $this->assertFalse(true, "Got error in mySQL query '{$query}'");
     }
     // After the password has been re-encoded, make sure it still matches
     $this->assertTrue($object->checkPassword($password));
     // Make sure repeated calls to updatePasswordHash succeed
     $object->updatePasswordHash($password);
 }
Example #3
0
 /**
  * Test #13. SYNCH request write new object.
  */
 public function testSynchPut()
 {
     global $testUserId1;
     global $synchAuthToken;
     $this->assertEquals(0, $this->countTestRows());
     $data = array('userId' => $testUserId1, 'created' => '2015-10-01', 'updated' => '2015-10-02', 'name' => 'Test User', 'externalType' => 'externaltype', 'externalId' => 'externalid', 'access' => 'Y', 'email' => '*****@*****.**', 'notification' => 'Y', 'tempCode' => 'tempcode', 'deleted' => 'Y', 'hash' => 'forced hash');
     $result = putApi('synchUser.php', $data, $synchAuthToken);
     $this->assertEquals(RESPONSE_SUCCESS, $result['resultCode']);
     $this->assertEquals(1, $this->countTestRows());
     $object = new User($testUserId1);
     $this->assertEquals('2015-10-01 00:00:00.000000', $object->getCreated());
     $this->assertEquals('2015-10-02 00:00:00.000000', $object->getUpdated());
     $this->assertEquals("Test User", $object->getName());
     $this->assertEquals("externaltype", $object->getExternalType());
     $this->assertEquals("externalid", $object->getExternalId());
     $this->assertEquals("Y", $object->getAccess());
     $this->assertEquals("*****@*****.**", $object->getEmail());
     $this->assertEquals("Y", $object->getNotification());
     $this->assertEquals("tempcode", $object->getTempCode());
     $this->assertEquals("Y", $object->getDeleted());
     $this->assertEquals('forced hash', $object->getHash());
 }
Example #4
0
        $userId = '';
    }
}
if (!isset($userId) || $userId === '') {
    $response = errorResponse(RESPONSE_BAD_REQUEST, 'Need user ID');
} else {
    if (!$auth->canGetUserBaseInfo($userId)) {
        $response = errorResponse(RESPONSE_UNAUTHORIZED);
    } else {
        $object = new User($userId);
        if ($object->getCreated() === null) {
            $response = errorResponse(RESPONSE_NOT_FOUND);
        } else {
            $response = successResponse();
            $response['userId'] = $object->getUserId();
            $response['name'] = $object->getName();
            $response['deleted'] = $object->getDeleted();
            if ($auth->canGetUserDetails($userId)) {
                $response['created'] = $object->getCreated();
                $response['updated'] = $object->getUpdated();
                $response['externalType'] = $object->getExternalType();
                $response['externalId'] = $object->getExternalId();
                $response['access'] = $object->getAccess();
                $response['email'] = $object->getEmail();
                $response['notification'] = $object->getNotification();
                $response['tempCode'] = $object->getTempCode();
            }
        }
    }
}
echo json_encode($response);