Ejemplo n.º 1
0
/**
 * Post handler for register form
 *
 * @param $event
 * @param $object_type
 * @param $object
 *
 * @return bool
 */
function inviteonly_post_handler($event, $object_type, $object)
{
    if (get_input('invitecode') && get_input('friend_guid')) {
        $friend = get_user(get_input('friend_guid'));
        if (!elgg_instanceof($friend, 'user')) {
            return inviteonly_redirect();
        }
        $friend_invitecode = generate_invite_code($friend->username);
        if ($friend_invitecode !== get_input('invitecode')) {
            return inviteonly_redirect();
        }
        return true;
    }
    return inviteonly_redirect();
}
Ejemplo n.º 2
0
/**
 * Add friends if invite code was set
 *
 * @param string $hook   Hook name
 * @param string $type   Hook type
 * @param bool   $result Whether to allow registration
 * @param array  $params Hook params
 * @return void
 */
function invitefriends_add_friends($hook, $type, $result, $params)
{
    $user = $params['user'];
    $friend_guid = $params['friend_guid'];
    $invite_code = $params['invitecode'];
    // If $friend_guid has been set, make mutual friends
    if ($friend_guid) {
        if ($friend_user = get_user($friend_guid)) {
            if ($invite_code == generate_invite_code($friend_user->username)) {
                $user->addFriend($friend_guid);
                $friend_user->addFriend($user->guid);
                // @todo Should this be in addFriend?
                elgg_create_river_item(array('view' => 'river/relationship/friend/create', 'action_type' => 'friend', 'subject_guid' => $user->getGUID(), 'object_guid' => $friend_guid));
                elgg_create_river_item(array('view' => 'river/relationship/friend/create', 'action_type' => 'friend', 'subject_guid' => $friend_guid, 'object_guid' => $user->getGUID()));
            }
        }
    }
}
/**
 * Registers a user, returning false if the username already exists
 *
 * @param string $username The username of the new user
 * @param string $password The password
 * @param string $name The user's display name
 * @param string $email Their email address
 * @param bool $allow_multiple_emails Allow the same email address to be registered multiple times?
 * @param int $friend_guid Optionally, GUID of a user this user will friend once fully registered 
 * @return int|false The new user's GUID; false on failure
 */
function register_user($username, $password, $name, $email, $allow_multiple_emails = false, $friend_guid = 0, $invitecode = '')
{
    // Load the configuration
    global $CONFIG;
    $username = trim($username);
    $password = trim($password);
    $name = trim($name);
    $email = trim($email);
    // A little sanity checking
    if (empty($username) || empty($password) || empty($name) || empty($email)) {
        return false;
    }
    // See if it exists and is disabled
    $access_status = access_get_show_hidden_status();
    access_show_hidden_entities(true);
    // Validate email address
    if (!validate_email_address($email)) {
        throw new RegistrationException(elgg_echo('registration:emailnotvalid'));
    }
    // Validate password
    if (!validate_password($password)) {
        throw new RegistrationException(elgg_echo('registration:passwordnotvalid'));
    }
    // Validate the username
    if (!validate_username($username)) {
        throw new RegistrationException(elgg_echo('registration:usernamenotvalid'));
    }
    // Check to see if $username exists already
    if ($user = get_user_by_username($username)) {
        //return false;
        throw new RegistrationException(elgg_echo('registration:userexists'));
    }
    // If we're not allowed multiple emails then see if this address has been used before
    if (!$allow_multiple_emails && get_user_by_email($email)) {
        throw new RegistrationException(elgg_echo('registration:dupeemail'));
    }
    access_show_hidden_entities($access_status);
    // Check to see if we've registered the first admin yet.
    // If not, this is the first admin user!
    $admin = datalist_get('admin_registered');
    // Otherwise ...
    $user = new ElggUser();
    $user->username = $username;
    $user->email = $email;
    $user->name = $name;
    $user->access_id = ACCESS_PUBLIC;
    $user->salt = generate_random_cleartext_password();
    // Note salt generated before password!
    $user->password = generate_user_password($user, $password);
    $user->owner_guid = 0;
    // Users aren't owned by anyone, even if they are admin created.
    $user->container_guid = 0;
    // Users aren't contained by anyone, even if they are admin created.
    $user->save();
    // If $friend_guid has been set, make mutual friends
    if ($friend_guid) {
        if ($friend_user = get_user($friend_guid)) {
            if ($invitecode == generate_invite_code($friend_user->username)) {
                $user->addFriend($friend_guid);
                $friend_user->addFriend($user->guid);
            }
        }
    }
    global $registering_admin;
    if (!$admin) {
        $user->admin = true;
        datalist_set('admin_registered', 1);
        $registering_admin = true;
    } else {
        $registering_admin = false;
    }
    // Turn on email notifications by default
    set_user_notification_setting($user->getGUID(), 'email', true);
    return $user->getGUID();
}
Ejemplo n.º 4
0
    $email = trim($email);
    if (empty($email)) {
        continue;
    }
    // send out other email addresses
    if (!is_email_address($email)) {
        $error = TRUE;
        $bad_emails[] = $email;
        continue;
    }
    if (get_user_by_email($email)) {
        $error = TRUE;
        $already_members[] = $email;
        continue;
    }
    $link = elgg_get_site_url() . 'register?friend_guid=' . $current_user->guid . '&invitecode=' . generate_invite_code($current_user->username);
    $message = elgg_echo('invitefriends:email', array($site->name, $current_user->name, $emailmessage, $link));
    $subject = elgg_echo('invitefriends:subject', array($site->name));
    // create the from address
    $site = get_entity($site->guid);
    if ($site && isset($site->email)) {
        $from = $site->email;
    } else {
        $from = 'noreply@' . get_site_domain($site->guid);
    }
    elgg_send_email($from, $email, $subject, $message);
    $sent_total++;
}
if ($error) {
    register_error(elgg_echo('invitefriends:invitations_sent', array($sent_total)));
    if (count($bad_emails) > 0) {
    forward($_SERVER['HTTP_REFERER']);
}
$error = FALSE;
$bad_emails = array();
foreach ($emails as $email) {
    $email = trim($email);
    if (empty($email)) {
        continue;
    }
    // send out other email addresses
    if (!is_email_address($email)) {
        $error = TRUE;
        $bad_emails[] = $email;
        continue;
    }
    $link = $CONFIG->wwwroot . 'pg/register?friend_guid=' . $_SESSION['guid'] . '&invitecode=' . generate_invite_code($_SESSION['user']->username);
    $message = sprintf(elgg_echo('invitefriends:email'), $CONFIG->site->name, $_SESSION['user']->name, $emailmessage, $link);
    // **** this should be replaced by a core function for sending emails to people who are not members
    $site = get_entity($CONFIG->site_guid);
    // If there's an email address, use it - but only if its not from a user.
    if ($site && isset($site->email)) {
        // Has the current site got a from email address?
        $from = $site->email;
    } else {
        if (isset($from->url)) {
            // If we have a url then try and use that.
            $breakdown = parse_url($from->url);
            $from = 'noreply@' . $breakdown['host'];
            // Handle anything with a url
        } else {
            // If all else fails, use the domain of the site.
Ejemplo n.º 6
0
Archivo: users.php Proyecto: riggo/Elgg
/**
 * Registers a user, returning false if the username already exists
 *
 * @param string $username              The username of the new user
 * @param string $password              The password
 * @param string $name                  The user's display name
 * @param string $email                 Their email address
 * @param bool   $allow_multiple_emails Allow the same email address to be
 *                                      registered multiple times?
 * @param int    $friend_guid           GUID of a user to friend once fully registered
 * @param string $invitecode            An invite code from a friend
 *
 * @return int|false The new user's GUID; false on failure
 */
function register_user($username, $password, $name, $email, $allow_multiple_emails = false, $friend_guid = 0, $invitecode = '')
{
    // Load the configuration
    global $CONFIG;
    // no need to trim password.
    $username = trim($username);
    $name = trim(strip_tags($name));
    $email = trim($email);
    // A little sanity checking
    if (empty($username) || empty($password) || empty($name) || empty($email)) {
        return false;
    }
    // Make sure a user with conflicting details hasn't registered and been disabled
    $access_status = access_get_show_hidden_status();
    access_show_hidden_entities(true);
    if (!validate_email_address($email)) {
        throw new RegistrationException(elgg_echo('registration:emailnotvalid'));
    }
    if (!validate_password($password)) {
        throw new RegistrationException(elgg_echo('registration:passwordnotvalid'));
    }
    if (!validate_username($username)) {
        throw new RegistrationException(elgg_echo('registration:usernamenotvalid'));
    }
    if ($user = get_user_by_username($username)) {
        throw new RegistrationException(elgg_echo('registration:userexists'));
    }
    if (!$allow_multiple_emails && get_user_by_email($email)) {
        throw new RegistrationException(elgg_echo('registration:dupeemail'));
    }
    access_show_hidden_entities($access_status);
    // Create user
    $user = new ElggUser();
    $user->username = $username;
    $user->email = $email;
    $user->name = $name;
    $user->access_id = ACCESS_PUBLIC;
    $user->salt = generate_random_cleartext_password();
    // Note salt generated before password!
    $user->password = generate_user_password($user, $password);
    $user->owner_guid = 0;
    // Users aren't owned by anyone, even if they are admin created.
    $user->container_guid = 0;
    // Users aren't contained by anyone, even if they are admin created.
    $user->language = get_current_language();
    $user->save();
    // If $friend_guid has been set, make mutual friends
    if ($friend_guid) {
        if ($friend_user = get_user($friend_guid)) {
            if ($invitecode == generate_invite_code($friend_user->username)) {
                $user->addFriend($friend_guid);
                $friend_user->addFriend($user->guid);
                // @todo Should this be in addFriend?
                add_to_river('river/relationship/friend/create', 'friend', $user->getGUID(), $friend_guid);
                add_to_river('river/relationship/friend/create', 'friend', $friend_guid, $user->getGUID());
            }
        }
    }
    // Turn on email notifications by default
    set_user_notification_setting($user->getGUID(), 'email', true);
    return $user->getGUID();
}
function siteaccess_register_hook($hook, $entity_type, $returnvalue, $params)
{
    $error = false;
    if (siteaccess_invitecode_enabled()) {
        $friend_guid = get_input('friend_guid');
        $invitecode = get_input('invitecode');
        if ($friend_guid) {
            if ($friend_user = get_user($friend_guid)) {
                if (!$invitecode == generate_invite_code($friend_user->username)) {
                    $error = true;
                }
            } else {
                $error = true;
            }
        } else {
            $error = true;
        }
    }
    if ($error) {
        register_error(elgg_echo('siteaccess:invitecode:invalid'));
    }
    if (siteaccess_key_enabled()) {
        $sitekey = get_plugin_setting('siteaccesskey', 'siteaccess');
        $inputkey = get_input('siteaccesskey');
        if (trim($inputkey) == "" || strcmp($inputkey, $sitekey) != 0) {
            register_error(elgg_echo('siteaccess:key:invalid'));
            $error = true;
        }
    }
    if (siteaccess_coppa_enabled()) {
        $coppa = get_input('coppa');
        if (!$coppa) {
            register_error(elgg_echo('siteaccess:coppa:fail'));
            $error = true;
        }
    }
    if (extension_loaded("gd")) {
        if (!siteaccess_validate_captcha()) {
            $error = true;
        }
    }
    if ($error) {
        siteaccess_register_fail();
    }
}
Ejemplo n.º 8
0
}
$emails = explode("\n", $emails);
global $CONFIG;
if (empty($emails)) {
    register_error(elgg_echo('invitefriends:failure'));
    forward(REFERER);
}
$user = elgg_get_logged_in_user_entity();
$site = elgg_get_site_entity();
if (isset($site->email)) {
    $from = $site->email;
} else {
    $from = 'noreply@' . $site->getDomain();
}
$from = "{$site->name} <{$from}>";
$base_link_attributes = ['friend_guid' => $user->getGUID(), 'invitecode' => generate_invite_code($user->username)];
foreach ($emails as $email) {
    $email = trim($email);
    if (empty($email)) {
        continue;
    }
    $link_attributes = $base_link_attributes;
    if (!empty($author) && !empty($publication)) {
        $author = urlencode($author);
        $link_attributes['author'] = $author;
        $link_attributes['publication'] = $publication;
    }
    $link = elgg_normalize_url('account/register.php');
    $link = elgg_http_add_url_query_elements($link, $link_attributes);
    $subject = elgg_echo('invitefriends:subject', [$site->name]);
    $message = elgg_echo('invitefriends:email', [$site->name, $user->name, $emailmessage, $link]);
Ejemplo n.º 9
0
    $email = trim($email);
    if (empty($email)) {
        continue;
    }
    // send out other email addresses
    if (!is_email_address($email)) {
        $error = TRUE;
        $bad_emails[] = $email;
        continue;
    }
    if (get_user_by_email($email)) {
        $error = TRUE;
        $already_members[] = $email;
        continue;
    }
    $link = elgg_get_site_url() . 'register?' . http_build_query(array('friend_guid' => $current_user->guid, 'invitecode' => generate_invite_code($current_user->username)));
    $message = elgg_echo('invitefriends:email', array($site->name, $current_user->name, $emailmessage, $link));
    $subject = elgg_echo('invitefriends:subject', array($site->name));
    // create the from address
    $site = get_entity($site->guid);
    if ($site && $site->email) {
        $from = $site->email;
    } else {
        $from = 'noreply@' . $site->getDomain();
    }
    elgg_send_email($from, $email, $subject, $message);
    $sent_total++;
}
if ($error) {
    register_error(elgg_echo('invitefriends:invitations_sent', array($sent_total)));
    if (count($bad_emails) > 0) {
Ejemplo n.º 10
0
Archivo: invite.php Proyecto: elgg/elgg
    $email = trim($email);
    if (empty($email)) {
        continue;
    }
    // send out other email addresses
    if (!is_email_address($email)) {
        $error = true;
        $bad_emails[] = $email;
        continue;
    }
    if (get_user_by_email($email)) {
        $error = true;
        $already_members[] = $email;
        continue;
    }
    $link = elgg_get_registration_url(array('friend_guid' => $current_user->guid, 'invitecode' => generate_invite_code($current_user->username)));
    $message = elgg_echo('invitefriends:email', array($site->name, $current_user->name, $emailmessage, $link));
    $subject = elgg_echo('invitefriends:subject', array($site->getDisplayName()));
    // create the from address
    if ($site->email) {
        $from = $site->email;
    } else {
        $from = 'noreply@' . $site->getDomain();
    }
    elgg_send_email($from, $email, $subject, $message);
    $sent_total++;
}
if ($error) {
    register_error(elgg_echo('invitefriends:invitations_sent', array($sent_total)));
    if (count($bad_emails) > 0) {
        register_error(elgg_echo('invitefriends:email_error', array(implode(', ', $bad_emails))));
Ejemplo n.º 11
0
 function method_pushMessage($params, $error = null)
 {
     if (!$this->is_loggedin()) {
         return array("err" => SESSION_ERROR);
     }
     global $CONFIG;
     $context = westorElggMan_get_context();
     westorElggMan_set_context('westorElggMan');
     // Plugin Settings
     // 'FullMail', 'Notify', 'NoMessage', 'NoInbox'
     $messageSendOption = westorElggMan_get_plugin_setting('messageSendOption', 'westorElggMan');
     if (!$messageSendOption) {
         $messageSendOption = 'FullMail';
     }
     $useCronOption = westorElggMan_get_plugin_setting('useCronOption', 'westorElggMan');
     if (!$useCronOption) {
         $useCronOption = 'no';
     }
     $allowSendToAllOption = westorElggMan_get_plugin_setting('allowSendToAllOption', 'westorElggMan');
     $owner = $_SESSION['user'];
     $from = (int) $owner->guid;
     $options = unserialize($owner->smsOptions);
     // SMS-HQ, SMS-BASIC, EMAIL, EMAILTXT, MMS
     $mType = $params[0];
     $lastSMSAccountBalance = $options["lastSMSAccountBalance"];
     $recipients = $params[1];
     $body = $params[2];
     $subject = $params[3];
     if (($mType == "EMAIL" || $mType == "EMAILTXT") && !($subject > '')) {
         $subject = elgg_echo("ElggMan_:noSubject");
     }
     // message empty?
     if ($subject == elgg_echo("ElggMan_:noSubject") && (!strlen($body) || $body == '<br />')) {
         return array("err" => elgg_echo("ElggMan_:noMessageTxt"));
     }
     // shedule
     if ($params[4]) {
         // in Form yyyy-mm-tt hh:mm:ss
         // $messageSchedule = "'" . mysql_real_escape_string($params[4]) . "'";
         $messageSchedule = mysql_real_escape_string($params[4]);
     } else {
         $messageSchedule = null;
     }
     $count = 0;
     if (is_array($recipients)) {
         foreach ($recipients as $recipient) {
             // Ersetzungen
             $link = $CONFIG->wwwroot . 'account/register.php?friend_guid=' . $_SESSION['guid'] . '&invitecode=' . generate_invite_code($_SESSION['user']->username);
             //            $search = array("/%%name%%/", "/%%registration_link%%/", "/%%sender_name%%/");
             //            $replace = array($recipient[1], $link, $owner->name);
             //            $body = preg_replace($search, $replace, $body);
             if (is_array($recipient)) {
                 $to = $recipient[0];
             } else {
                 $to = $recipient;
             }
             $recp = westorElggMan_get_entity($to);
             if ($recp instanceof ElggUser || $recp->getSubtype() == "PrivateContact") {
                 // if the user shall only send messages to friends and private contacs, continue
                 // normally this only occures when someone hacks the client code.
                 if ($allowSendToAllOption == 'no' && !($this->is_admin() || $recp->isFriendsWith($_SESSION['guid']) || $recp->getSubtype() == "PrivateContact")) {
                     continue;
                 }
                 if ($recp == $_SESSION['user']) {
                     continue;
                 }
                 // no message to current user
                 $msgObjToSend = $this->createMessageObject("messages", $mType, $from, $to, $subject, $body, $messageSchedule);
                 if ($recp->getSubtype() != "PrivateContact" && ($mType == "EMAIL" || $mType == "EMAILTXT")) {
                     $message_copy_for_recipient = clone $msgObjToSend;
                     $message_copy_for_recipient->waitForSend = 0;
                     $message_copy_for_recipient->state = 'copy';
                     $message_copy_for_recipient->save();
                     $message_copy_for_recipient->access_id = ACCESS_PRIVATE;
                     $message_copy_for_recipient->changeOwner($to);
                 }
                 if ($recp->getSubtype() != "PrivateContact" && $messageSendOption == 'Notify') {
                     $this->sendDirectNotification($recp, $body);
                 }
                 ///////////////////////////////
                 // for DEMO Account send direct
                 ///////////////////////////////
                 if ($useCronOption == 'yes' && $mType == "HQ-SMS") {
                     $smsRes[] = $this->sendMsgNow($msgObjToSend);
                 }
                 if ($useCronOption == 'no' && ($messageSendOption == 'FullMail' || $recp->getSubtype() == "PrivateContact" || $mType == "HQ-SMS")) {
                     $smsRes[] = $this->sendMsgNow($msgObjToSend);
                 }
                 $count++;
             }
         }
     }
     westorElggMan_set_context($context);
     $result["txt"] = sprintf(elgg_echo('ElggMan_:messagesSaved'), $count);
     if (is_array($smsRes)) {
         foreach ($smsRes as $smsR) {
             if ($smsR["txt"]) {
                 $result["txt"] .= "\n" . $smsR["txt"];
             }
         }
     }
     return $result;
 }