Example #1
0
/**
 * Activate a signup.
 *
 * Hook to 'nxtmu_activate_user' or 'nxtmu_activate_blog' for events
 * that should happen only when users or sites are self-created (since
 * those actions are not called when users and sites are created
 * by a Super Admin).
 *
 * @since MU
 * @uses nxt_generate_password()
 * @uses nxtmu_welcome_user_notification()
 * @uses add_user_to_blog()
 * @uses add_new_user_to_blog()
 * @uses nxtmu_create_user()
 * @uses nxtmu_create_blog()
 * @uses nxtmu_welcome_notification()
 *
 * @param string $key The activation key provided to the user.
 * @return array An array containing information about the activated user and/or blog
 */
function nxtmu_activate_signup($key)
{
    global $nxtdb, $current_site;
    $signup = $nxtdb->get_row($nxtdb->prepare("SELECT * FROM {$nxtdb->signups} WHERE activation_key = %s", $key));
    if (empty($signup)) {
        return new nxt_Error('invalid_key', __('Invalid activation key.'));
    }
    if ($signup->active) {
        if (empty($signup->domain)) {
            return new nxt_Error('already_active', __('The user is already active.'), $signup);
        } else {
            return new nxt_Error('already_active', __('The site is already active.'), $signup);
        }
    }
    $meta = unserialize($signup->meta);
    $user_login = $nxtdb->escape($signup->user_login);
    $user_email = $nxtdb->escape($signup->user_email);
    $password = nxt_generate_password(12, false);
    $user_id = username_exists($user_login);
    if (!$user_id) {
        $user_id = nxtmu_create_user($user_login, $password, $user_email);
    } else {
        $user_already_exists = true;
    }
    if (!$user_id) {
        return new nxt_Error('create_user', __('Could not create user'), $signup);
    }
    $now = current_time('mysql', true);
    if (empty($signup->domain)) {
        $nxtdb->update($nxtdb->signups, array('active' => 1, 'activated' => $now), array('activation_key' => $key));
        if (isset($user_already_exists)) {
            return new nxt_Error('user_already_exists', __('That username is already activated.'), $signup);
        }
        nxtmu_welcome_user_notification($user_id, $password, $meta);
        add_new_user_to_blog($user_id, $user_email, $meta);
        do_action('nxtmu_activate_user', $user_id, $password, $meta);
        return array('user_id' => $user_id, 'password' => $password, 'meta' => $meta);
    }
    $blog_id = nxtmu_create_blog($signup->domain, $signup->path, $signup->title, $user_id, $meta, $nxtdb->siteid);
    // TODO: What to do if we create a user but cannot create a blog?
    if (is_nxt_error($blog_id)) {
        // If blog is taken, that means a previous attempt to activate this blog failed in between creating the blog and
        // setting the activation flag.  Let's just set the active flag and instruct the user to reset their password.
        if ('blog_taken' == $blog_id->get_error_code()) {
            $blog_id->add_data($signup);
            $nxtdb->update($nxtdb->signups, array('active' => 1, 'activated' => $now), array('activation_key' => $key));
        }
        return $blog_id;
    }
    $nxtdb->update($nxtdb->signups, array('active' => 1, 'activated' => $now), array('activation_key' => $key));
    nxtmu_welcome_notification($blog_id, $user_id, $password, $signup->title, $meta);
    do_action('nxtmu_activate_blog', $blog_id, $user_id, $password, $signup->title, $meta);
    return array('blog_id' => $blog_id, 'user_id' => $user_id, 'password' => $password, 'title' => $signup->title, 'meta' => $meta);
}
Example #2
0
    // Roles are stored in memory, not the DB.
    $editblog_roles = $nxt_roles->roles;
}
$default_role = get_blog_option($id, 'default_role');
$action = $nxt_list_table->current_action();
if ($action) {
    switch_to_blog($id);
    switch ($action) {
        case 'newuser':
            check_admin_referer('add-user', '_nxtnonce_add-new-user');
            $user = $_POST['user'];
            if (!is_array($_POST['user']) || empty($user['username']) || empty($user['email'])) {
                $update = 'err_new';
            } else {
                $password = nxt_generate_password(12, false);
                $user_id = nxtmu_create_user(esc_html(strtolower($user['username'])), $password, esc_html($user['email']));
                if (false == $user_id) {
                    $update = 'err_new_dup';
                } else {
                    nxt_new_user_notification($user_id, $password);
                    add_user_to_blog($id, $user_id, $_POST['new_role']);
                    $update = 'newuser';
                }
            }
            break;
        case 'adduser':
            check_admin_referer('add-user', '_nxtnonce_add-user');
            if (!empty($_POST['newuser'])) {
                $update = 'adduser';
                $newuser = $_POST['newuser'];
                $userid = $nxtdb->get_var($nxtdb->prepare("SELECT ID FROM " . $nxtdb->users . " WHERE user_login = %s", $newuser));
Example #3
0
 if (!is_email($email)) {
     nxt_die(__('Invalid email address.'));
 }
 if (is_subdomain_install()) {
     $newdomain = $domain . '.' . preg_replace('|^www\\.|', '', $current_site->domain);
     $path = $base;
 } else {
     $newdomain = $current_site->domain;
     $path = $base . $domain . '/';
 }
 $password = '******';
 $user_id = email_exists($email);
 if (!$user_id) {
     // Create a new user with a random password
     $password = nxt_generate_password(12, false);
     $user_id = nxtmu_create_user($domain, $password, $email);
     if (false == $user_id) {
         nxt_die(__('There was an error creating the user.'));
     } else {
         nxt_new_user_notification($user_id, $password);
     }
 }
 $nxtdb->hide_errors();
 $id = nxtmu_create_blog($newdomain, $path, $title, $user_id, array('public' => 1), $current_site->id);
 $nxtdb->show_errors();
 if (!is_nxt_error($id)) {
     if (!is_super_admin($user_id) && !get_user_option('primary_blog', $user_id)) {
         update_user_option($user_id, 'primary_blog', $id, true);
     }
     $content_mail = sprintf(__("New site created by %1s\n\nAddress: %2s\nName: %3s"), $current_user->user_login, get_site_url($id), stripslashes($title));
     nxt_mail(get_site_option('admin_email'), sprintf(__('[%s] New Site Created'), $current_site->site_name), $content_mail, 'From: "Site Admin" <' . get_site_option('admin_email') . '>');