function testUserRegistration()
 {
     $login = "******" . rand(10000, 99999);
     $firstName = 'Test';
     $lastName = 'User';
     $email = "{$login}@myelin.co.nz";
     $password = '******';
     $home_network = Network::get_mothership_info();
     $orig_member_count = $home_network->member_count;
     // register a new user
     $reg = new User_Registration();
     $this->assertTrue($reg->register(array('login_name' => $login, 'first_name' => $firstName, 'last_name' => $lastName, 'email' => $email, 'password' => $password, 'confirm_password' => $password), $home_network));
     $this->assertEquals(Network::get_member_count($home_network->network_id), $orig_member_count + 1);
     // test the user
     $new_user = $reg->newuser;
     $new_uid = (int) $new_user->user_id;
     $this->assertEquals($new_user->first_name, $firstName);
     $this->assertEquals($new_user->last_name, $lastName);
     $this->assertEquals($new_user->email, $email);
     // reload user and make sure it works
     $user = new User();
     $user->load($new_uid);
     $this->assertEquals($user->first_name, $firstName);
     $this->assertEquals($user->last_name, $lastName);
     $this->assertEquals($user->email, $email);
     // now delete the user
     User::delete($new_uid);
     // and try to load again
     $user_fail = new User();
     try {
         $user_fail->load($new_uid);
     } catch (PAException $e) {
         $this->assertEquals($e->getCode(), USER_NOT_FOUND);
     }
     // make sure member_count is correct
     $this->assertEquals(Network::get_member_count($home_network->network_id), $orig_member_count);
 }
Ejemplo n.º 2
0
 static function create($namespace, $userinfo, $network_info)
 {
     Logger::log("ShadowUser::create " . serialize($userinfo), LOGGER_ACTION);
     // setup the needed info
     if (empty($userinfo['login_name'])) {
         $userinfo['display_login_name'] = $userinfo['first_name'] . '.' . $userinfo['last_name'];
     } else {
         $userinfo['display_login_name'] = $userinfo['login_name'];
     }
     // this is the real internal PA login_name
     // which should NOT be displayed
     // instead use the display_login_name
     $userinfo['login_name'] = $namespace . "." . $userinfo['user_id'];
     $userinfo['confirm_password'] = $userinfo['password'] = substr(md5($userinfo['email'] . rand()), 0, 12);
     // Test to see if the email was used before
     $res = Dal::query("SELECT user_id FROM users WHERE email=?", array($userinfo['email']));
     if ($res->numrows() > 0) {
         // oops email has been used
         // use the prefix.email@address,tld format
         // to ensure we have an unique string for email
         $userinfo['email'] = $userinfo['user_id'] . "+" . $userinfo['email'];
     }
     $reg_user = new User_Registration();
     if ($reg_user->register($userinfo, $network_info)) {
         // Success!
         $reg_user->newuser->set_last_login();
         // also save the external user_id
         $reg_user->newuser->set_profile_field($namespace, 'user_id', $userinfo['user_id'], 0);
         $reg_user->newuser->set_profile_field($namespace, 'display_login_name', $userinfo['display_login_name'], 0);
         $reg_user->newuser->is_active = ACTIVE;
         $reg_user->newuser->save();
         // load it as a shadow user
         Cache::reset();
         $su = new ShadowUser($namespace);
         $su->load($userinfo['user_id']);
         // and make sure all info is actually stored
         $su->sync($userinfo);
         Logger::log("ShadowUser::create done " . serialize($userinfo), LOGGER_ACTION);
         return $su;
     } else {
         throw new PAException(BAD_PARAMETER, $reg_user->msg);
         return NULL;
     }
 }
function peopleaggregator_newUser($args)
{
    // check admin password
    global $admin_password;
    if (!$admin_password) {
        header('HTTP/1.1 412 Precondition Failed');
        throw new PAException(OPERATION_NOT_PERMITTED, "newUser API method may not be called without an admin password defined in the Application Configuration File");
    } else {
        if (!isset($args['adminPassword']) || !$args['adminPassword']) {
            header('HTTP/1.1 412 Precondition Failed');
            throw new PAException(OPERATION_NOT_PERMITTED, "newUser API method may not be called without an admin password");
        } else {
            if ($admin_password != $args['adminPassword']) {
                header('HTTP/1.1 401 Unauthorized');
                throw new PAException(USER_INVALID_PASSWORD, "adminPassword incorrect");
            }
        }
    }
    // fetch network info
    $home_network = Network::get_network_by_address($args['homeNetwork']);
    if (!$home_network) {
        //TODO: read this from AppConfig.xml
        $home_network = "default";
    }
    // register the user
    $reg = new User_Registration();
    $reg->api_call = true;
    // api_call indicates that this is a PeopleAggregator API request
    $profile_picture_dimensions = User::image_dimensions_to_array($args['profilePictureWidth'], $args['profilePictureHeight']);
    $profile_avatar_dimensions = User::image_dimensions_to_array($args['profileAvatarWidth'], $args['profileAvatarHeight']);
    $profile_avatar_small_dimensions = User::image_dimensions_to_array($args['profileAvatarSmallWidth'], $args['profileAvatarSmallHeight']);
    $newUserData = array('core_id' => $args['id'], 'login_name' => $args['login'], 'first_name' => $args['firstName'], 'last_name' => $args['lastName'], 'email' => $args['email'], 'password' => $args['password'], 'confirm_password' => $args['password'], 'profile_picture_url' => $args['profilePictureURL'], 'profile_avatar_url' => $args['profileAvatarURL'], 'profile_avatar_small_url' => $args['profileAvatarSmallURL'], 'profile_picture_dimensions' => $profile_picture_dimensions, 'profile_avatar_dimensions' => $profile_avatar_dimensions, 'profile_avatar_small_dimensions' => $profile_avatar_small_dimensions);
    if (!$reg->register($newUserData, $home_network)) {
        //	header('HTTP/1.1 500 Internal Server Error');
        return array('success' => FALSE, 'msg' => $reg->msg);
    }
    // success!
    $user = $reg->newuser;
    return array('success' => TRUE, 'msg' => "Created a user: id={$user->user_id}; login={$user->login_name}; firstName={$user->first_name}; lastName={$user->last_name}; email={$user->email}; password={$user->password}; joined to network id {$home_network->network_id} name {$home_network->address}", 'id' => $user->user_id, 'network_id' => (int) $home_network->network_id);
}
 static function create($namespace, $userinfo, $network_info)
 {
     // setup the needed info
     if (empty($userinfo['login_name'])) {
         $userinfo['display_login_name'] = $userinfo['first_name'] . '.' . $userinfo['last_name'];
     } else {
         $userinfo['display_login_name'] = $userinfo['login_name'];
     }
     // this is the real internal PA login_name
     // which should NOT be displayed
     // instead use the display_login_name
     $userinfo['login_name'] = $namespace . "." . $userinfo['user_id'];
     $userinfo['confirm_password'] = $userinfo['password'] = substr(md5($userinfo['email'] . rand()), 0, 12);
     $reg_user = new User_Registration();
     if ($reg_user->register($userinfo, $network_info)) {
         // Success!
         $reg_user->newuser->set_last_login();
         // also save the external user_id
         $reg_user->newuser->set_profile_field($namespace, 'user_id', $userinfo['user_id'], 0);
         $reg_user->newuser->set_profile_field($namespace, 'display_login_name', $userinfo['display_login_name'], 0);
         // load it as a shadow user
         Cache::reset();
         $su = new ShadowUser($namespace);
         $su->load($userinfo['user_id']);
         return $su;
     } else {
         throw new PAException(BAD_PARAMETER, $reg_user->msg);
         return NULL;
     }
 }
Ejemplo n.º 5
0
function peopleaggregator_newUser($args)
{
    // check admin password
    global $admin_password;
    if (!$admin_password) {
        throw new PAException(OPERATION_NOT_PERMITTED, "newUser API method may not be called without an admin password defined in local_config.php");
    }
    if ($admin_password != $args['adminPassword']) {
        throw new PAException(USER_INVALID_PASSWORD, "adminPassword incorrect");
    }
    // fetch network info
    $home_network = Network::get_network_by_address($args['homeNetwork']);
    if (!$home_network) {
        throw new PAException(INVALID_ID, "Network " . $args['homeNetwork'] . " not found");
    }
    // register the user
    $reg = new User_Registration();
    if (!$reg->register(array('login_name' => $args['login'], 'first_name' => $args['firstName'], 'last_name' => $args['lastName'], 'email' => $args['email'], 'password' => $args['password'], 'confirm_password' => $args['password']), $home_network)) {
        return array('success' => FALSE, 'msg' => $reg->msg);
    }
    // success!
    $user = $reg->newuser;
    return array('success' => TRUE, 'msg' => "Created a user: id={$user->user_id}; login={$user->login_name}; firstName={$user->first_name}; lastName={$user->last_name}; email={$user->email}; password={$user->password}; joined to network id {$home_network->network_id} name {$home_network->address}", 'id' => 'user:' . $user->user_id);
}