示例#1
0
文件: users.php 项目: GeorgeLVP/mybb
     } else {
         $additionalgroups = '';
     }
     // Set up user handler.
     require_once MYBB_ROOT . "inc/datahandlers/user.php";
     $userhandler = new UserDataHandler('insert');
     // Set the data for the new user.
     $new_user = array("uid" => $mybb->input['uid'], "username" => $mybb->input['username'], "password" => $mybb->input['password'], "password2" => $mybb->input['confirm_password'], "email" => $mybb->input['email'], "email2" => $mybb->input['email'], "usergroup" => $mybb->input['usergroup'], "additionalgroups" => $additionalgroups, "displaygroup" => $mybb->input['displaygroup'], "profile_fields" => $mybb->input['profile_fields'], "profile_fields_editable" => true);
     // Set the data of the user in the datahandler.
     $userhandler->set_data($new_user);
     $errors = '';
     // Validate the user and get any errors that might have occurred.
     if (!$userhandler->validate_user()) {
         $errors = $userhandler->get_friendly_errors();
     } else {
         $user_info = $userhandler->insert_user();
         $plugins->run_hooks("admin_user_users_add_commit");
         // Log admin action
         log_admin_action($user_info['uid'], $user_info['username']);
         flash_message($lang->success_user_created, 'success');
         admin_redirect("index.php?module=user-users&action=edit&uid={$user_info['uid']}");
     }
 }
 // Fetch custom profile fields - only need required profile fields here
 $query = $db->simple_select("profilefields", "*", "required=1", array('order_by' => 'disporder'));
 while ($profile_field = $db->fetch_array($query)) {
     $profile_fields['required'][] = $profile_field;
 }
 $page->add_breadcrumb_item($lang->create_user);
 $page->output_header($lang->create_user);
 $form = new Form("index.php?module=user-users&action=add", "post");
示例#2
0
 /**
  * Register procedure
  * Refers to: /member.php
  *
  * @param array $info Contains user information of the User to be registered
  * @return array|string If registration fails, we return an array containing the error message, 
  * 						If registration is successful, we return the string, which notifies the user of what will be the next action
  */
 function register($info = array())
 {
     // Load the language phrases we need for the registration
     $this->lang->load('member');
     /**
      * $info contains the given user information for the registration
      * We need to make sure that every possible key is given, so we do not generate ugly E_NOIICE errors
      */
     $possible_info_keys = array('username', 'password', 'password2', 'email', 'email2', 'referrer', 'timezone', 'language', 'profile_fields', 'allownotices', 'hideemail', 'subscriptionmethod', 'receivepms', 'pmnotice', 'emailpmnotify', 'invisible', 'dstcorrection');
     // Iterate the possible info keys to create the array entry in $info if it does not exist
     foreach ($possible_info_keys as $possible_info_key) {
         if (!isset($info[$possible_info_key])) {
             $info[$possible_info_key] = '';
         }
     }
     // Run whatever hook specified at the beginning of the registration
     $this->plugins->run_hooks('member_do_register_start');
     // If register type is random password, we generate one
     if ($this->mybb->settings['regtype'] == "randompass") {
         $info['password'] = random_str();
         $info['password2'] = $info['password'];
     }
     if ($this->mybb->settings['regtype'] == "verify" || $this->mybb->settings['regtype'] == "admin" || $info['coppa'] == 1) {
         $usergroup = 5;
     } else {
         $usergroup = 2;
     }
     // Set up user handler.
     require_once MYBB_ROOT . "inc/datahandlers/user.php";
     $userhandler = new UserDataHandler("insert");
     // Set the data for the new user.
     $user = array("username" => $info['username'], "password" => $info['password'], "password2" => $info['password2'], "email" => $info['email'], "email2" => $info['email2'], "usergroup" => $usergroup, "referrer" => $info['referrername'], "timezone" => $info['timezone'], "language" => $info['language'], "profile_fields" => $info['profile_fields'], "regip" => $this->mybb->session->ipaddress, "longregip" => ip2long($this->mybb->session->ipaddress), "coppa_user" => intval($this->mybb->cookies['coppauser']));
     if (isset($info['regcheck1']) && isset($info['regcheck2'])) {
         $user['regcheck1'] = $info['regcheck1'];
         $user['regcheck2'] = $info['regcheck2'];
     }
     // Do we have a saved COPPA DOB?
     if ($this->mybb->cookies['coppadob']) {
         list($dob_day, $dob_month, $dob_year) = explode("-", $this->mybb->cookies['coppadob']);
         $user['birthday'] = array("day" => $dob_day, "month" => $dob_month, "year" => $dob_year);
     }
     // Generate the options array of the user
     $user['options'] = array("allownotices" => $info['allownotices'], "hideemail" => $info['hideemail'], "subscriptionmethod" => $info['subscriptionmethod'], "receivepms" => $info['receivepms'], "pmnotice" => $info['pmnotice'], "emailpmnotify" => $info['emailpmnotify'], "invisible" => $info['invisible'], "dstcorrection" => $info['dstcorrection']);
     // Assign data to the data handler
     $userhandler->set_data($user);
     // If the validation of the user failed, we return nice (friendly) errors
     if (!$userhandler->validate_user()) {
         $errors = $userhandler->get_friendly_errors();
         return $errors;
     }
     // Create the User in the database
     $user_info = $userhandler->insert_user();
     // We need to set a cookie, if we don't want a random password (and it is no COPPA user), so he is instantly logged in
     if ($this->mybb->settings['regtype'] != "randompass" && !$this->mybb->cookies['coppauser']) {
         // Log them in
         my_setcookie("mybbuser", $user_info['uid'] . "_" . $user_info['loginkey'], null, true);
     }
     /**
      * Coppa User
      * Nothing special, just return that the coppa user will be redirected
      */
     if ($this->mybb->cookies['coppauser']) {
         $this->lang->redirect_registered_coppa_activate = $this->lang->sprintf($this->lang->redirect_registered_coppa_activate, $this->mybb->settings['bbname'], $user_info['username']);
         my_unsetcookie("coppauser");
         my_unsetcookie("coppadob");
         // Run whatever hook is defined at the end of a registration
         $this->plugins->run_hooks("member_do_register_end");
         return $this->lang->redirect_registered_coppa_activate;
     } else {
         if ($this->mybb->settings['regtype'] == "verify") {
             // Generate and save the activation code in the database
             $activationcode = random_str();
             $now = TIME_NOW;
             $activationarray = array("uid" => $user_info['uid'], "dateline" => TIME_NOW, "code" => $activationcode, "type" => "r");
             $this->db->insert_query("awaitingactivation", $activationarray);
             // Generate and send the email
             $emailsubject = $this->lang->sprintf($this->lang->emailsubject_activateaccount, $this->mybb->settings['bbname']);
             $emailmessage = $this->lang->sprintf($this->lang->email_activateaccount, $user_info['username'], $this->mybb->settings['bbname'], $this->mybb->settings['bburl'], $user_info['uid'], $activationcode);
             my_mail($user_info['email'], $emailsubject, $emailmessage);
             // Build the message to return
             $this->lang->redirect_registered_activation = $this->lang->sprintf($this->lang->redirect_registered_activation, $this->mybb->settings['bbname'], $user_info['username']);
             // Run whatever hook is defined at the end of a registration
             $this->plugins->run_hooks("member_do_register_end");
             return $this->lang->redirect_registered_activation;
         } else {
             if ($this->mybb->settings['regtype'] == "randompass") {
                 // Generate and send the email
                 $emailsubject = $this->lang->sprintf($this->lang->emailsubject_randompassword, $this->mybb->settings['bbname']);
                 $emailmessage = $this->lang->sprintf($this->lang->email_randompassword, $user['username'], $this->mybb->settings['bbname'], $user_info['username'], $user_info['password']);
                 my_mail($user_info['email'], $emailsubject, $emailmessage);
                 // Run whatever hook is defined at the end of a registration
                 $this->plugins->run_hooks("member_do_register_end");
                 return $this->lang->redirect_registered_passwordsent;
             } else {
                 if ($this->mybb->settings['regtype'] == "admin") {
                     // Build the message to return
                     $this->lang->redirect_registered_admin_activate = $this->lang->sprintf($this->lang->redirect_registered_admin_activate, $this->mybb->settings['bbname'], $user_info['username']);
                     // Run whatever hook is defined at the end of a registration
                     $this->plugins->run_hooks("member_do_register_end");
                     return $this->lang->redirect_registered_admin_activate;
                 } else {
                     // Build the message to return
                     $this->lang->redirect_registered = $this->lang->sprintf($this->lang->redirect_registered, $this->mybb->settings['bbname'], $user_info['username']);
                     // Run whatever hook is defined at the end of a registration
                     $this->plugins->run_hooks('member_do_register_end');
                     return $this->lang->redirect_registered;
                 }
             }
         }
     }
 }
示例#3
0
function sign_in_func()
{
    global $db, $lang, $theme, $plugins, $mybb, $session, $settings, $cache, $time, $mybbgroups, $mobiquo_config, $user, $register;
    // Load global language phrases
    $lang->load("member");
    $parser = new postParser();
    $token = trim($_POST['token']);
    $code = trim($_POST['code']);
    $username = $mybb->input['username'];
    $password = $mybb->input['password'];
    $post_email = $mybb->input['email'];
    $status = '';
    if (!empty($token) && !empty($code)) {
        $result = tt_register_verify($token, $code);
        if ($result->result && !empty($result->email)) {
            $email = $result->email;
            if (!empty($post_email) && $post_email != $email) {
                $status = 3;
            } else {
                if ($user = tt_get_user_by_email($email)) {
                    if (!empty($username) && strtolower($username) != strtolower($user['username'])) {
                        $status = 3;
                    } else {
                        $register = 0;
                        return tt_login_success();
                    }
                } else {
                    if (!empty($username) && !empty($email)) {
                        $profile = $result->profile;
                        if ($mybb->settings['disableregs'] == 1) {
                            error($lang->registrations_disabled);
                        }
                        // Set up user handler.
                        require_once MYBB_ROOT . "inc/datahandlers/user.php";
                        $userhandler = new UserDataHandler("insert");
                        $birthday_arr = explode('-', $profile->birthday);
                        $bday = array("day" => $birthday_arr[2], "month" => $birthday_arr[1], "year" => $birthday_arr[0]);
                        $user_field = array('fid3' => ucfirst($profile->gender), 'fid1' => $profile->location, 'fid2' => $profile->description);
                        if ($mybb->settings['regtype'] == "admin") {
                            $usergroup = 5;
                        } else {
                            $usergroup = isset($mybb->settings['tapatalk_register_group']) ? $mybb->settings['tapatalk_register_group'] : 2;
                        }
                        // Set the data for the new user.
                        $user = array("username" => $mybb->input['username'], "password" => $mybb->input['password'], "password2" => $mybb->input['password'], "email" => $email, "email2" => $email, "usergroup" => $usergroup, "referrer" => '', "timezone" => $mybb->settings['timezoneoffset'], "language" => '', "regip" => $session->ipaddress, "longregip" => my_ip2long($session->ipaddress), "coppa_user" => 0, "birthday" => $bday, "website" => $profile->link, "user_fields" => $user_field, "signature" => $profile->signature, "option" => array(), "regdate" => TIME_NOW, "lastvisit" => TIME_NOW);
                        if (!empty($profile->avatar_url)) {
                            $updated_avatar = tt_update_avatar_url($profile->avatar_url);
                        }
                        $userhandler->set_data($user);
                        $userhandler->verify_birthday();
                        $userhandler->verify_options();
                        if ($userhandler->verify_username_exists()) {
                            $status = 1;
                        } else {
                            if (!$userhandler->verify_password() || !$userhandler->verify_username()) {
                                $errors = $userhandler->get_friendly_errors();
                                error($errors[0]);
                            } else {
                                $userhandler->set_validated(true);
                                $user = $userhandler->insert_user();
                                if (!empty($updated_avatar)) {
                                    $db->update_query("users", $updated_avatar, "uid='" . $user['uid'] . "'");
                                }
                                $register = 1;
                                return tt_login_success();
                            }
                        }
                    } else {
                        $status = 2;
                    }
                }
            }
        } else {
            if (!$result->result) {
                if (!empty($result->result_text)) {
                    error($result->result_text);
                } else {
                    error("Tapatalk ID verify faile!");
                }
            }
        }
        if (!empty($status)) {
            $response = new xmlrpcval(array('result' => new xmlrpcval(0, 'boolean'), 'result_text' => new xmlrpcval('', 'base64'), 'status' => new xmlrpcval($status, 'string')), 'struct');
            return new xmlrpcresp($response);
        }
    } else {
        error("Invlaid params!");
    }
}
 /**
  * Registers an user with Facebook data
  */
 public function register($user)
 {
     if (!$user) {
         return false;
     }
     global $mybb, $session, $plugins, $lang;
     require_once MYBB_ROOT . "inc/datahandlers/user.php";
     $userhandler = new UserDataHandler("insert");
     $plength = 8;
     if ($mybb->settings['minpasswordlength']) {
         $plength = (int) $mybb->settings['minpasswordlength'];
     }
     $password = random_str($plength);
     $new_user = array("username" => $user['name'], "password" => $password, "password2" => $password, "email" => $user['email'], "email2" => $user['email'], "usergroup" => (int) $mybb->settings['myfbconnect_usergroup'], "regip" => $session->ipaddress, "longregip" => my_ip2long($session->ipaddress), "options" => array("hideemail" => 1));
     /* Registration might fail for custom profile fields required at registration... workaround = IN_ADMINCP defined.
     		Placed straight before the registration process to avoid conflicts with third party plugins messying around with
     		templates (I'm looking at you, PHPTPL) */
     define("IN_ADMINCP", 1);
     $userhandler->set_data($new_user);
     if ($userhandler->validate_user()) {
         $user_info = $userhandler->insert_user();
         $plugins->run_hooks("member_do_register_end");
         // Deliver a welcome PM
         if ($mybb->settings['myfbconnect_passwordpm']) {
             require_once MYBB_ROOT . "inc/datahandlers/pm.php";
             $pmhandler = new PMDataHandler();
             $pmhandler->admin_override = true;
             // Make sure admins haven't done something bad
             $fromid = (int) $mybb->settings['myfbconnect_passwordpm_fromid'];
             if (!$mybb->settings['myfbconnect_passwordpm_fromid'] or !user_exists($mybb->settings['myfbconnect_passwordpm_fromid'])) {
                 $fromid = 0;
             }
             $message = $mybb->settings['myfbconnect_passwordpm_message'];
             $subject = $mybb->settings['myfbconnect_passwordpm_subject'];
             $thingsToReplace = array("{user}" => $user_info['username'], "{password}" => $password);
             // Replace what needs to be replaced
             foreach ($thingsToReplace as $find => $replace) {
                 $message = str_replace($find, $replace, $message);
             }
             $pm = array("subject" => $subject, "message" => $message, "fromid" => $fromid, "toid" => array($user_info['uid']));
             // Some defaults :)
             $pm['options'] = array("signature" => 1);
             $pmhandler->set_data($pm);
             // Now let the PM handler do all the hard work
             if ($pmhandler->validate_pm()) {
                 $pmhandler->insert_pm();
             } else {
                 error($lang->sprintf($lang->myfbconnect_error_report, $pmhandler->get_friendly_errors()));
             }
         }
         // Post a message on the user's wall
         if ($mybb->settings['myfbconnect_postonwall']) {
             $this->post_on_wall($mybb->settings['myfbconnect_postonwall_message']);
         }
         // Finally return our new user data
         return $user_info;
     } else {
         return array('error' => $userhandler->get_friendly_errors());
     }
     return true;
 }
/**
 *
 * Redirect Output - steam_output_to_misc
 * - - - - - - - - - - - - - - -
 * @desc This function is holds the actions issued by the Steam Login plugin.
 * @since 1.0
 * @version 1.6
 *
 */
function steam_output_to_misc()
{
    global $mybb, $db, $session;
    // The standard action to redirect the user to Steam community.
    if ($mybb->input['action'] == 'steam_login') {
        steam_redirect();
    }
    // close if($mybb->input['action'] == 'steam_login')
    if ($mybb->input['action'] == 'steam_return') {
        $get_key = $db->fetch_array($db->simple_select("settings", "name, value", "name = 'steamlogin_api_key'"));
        $check_update_username = $db->fetch_array($db->simple_select("settings", "name, value", "name = 'steamlogin_update_username'"));
        $check_update_avatar = $db->fetch_array($db->simple_select("settings", "name, value", "name = 'steamlogin_update_avatar'"));
        $check_avatar_size = $db->fetch_array($db->simple_select("settings", "name, value", "name = 'steamlogin_avatar_size'"));
        $check_required_field = $db->fetch_array($db->simple_select("settings", "name, value", "name = 'steamlogin_required_field'"));
        if ($get_key['value'] == null) {
            die("<strong>Not Configured</strong> The Steam Login plugin hasn't been configured correctly. Please ensure an API key is set in the Configuration settings.");
        } else {
            require_once MYBB_ROOT . 'inc/class_steam.php';
            require_once MYBB_ROOT . 'inc/class_lightopenid.php';
            require_once MYBB_ROOT . 'inc/functions.php';
            require_once MYBB_ROOT . 'inc/class_session.php';
            $steam = new steam();
            $steam_open_id = new LightOpenID();
            $steam_open_id->validate();
            $return_explode = explode('/', $steam_open_id->identity);
            $steamid = end($return_explode);
            $steam_info = $steam->get_user_info($steamid);
            // Check the status.
            if ($steam_info['status'] == 'success') {
                $steamid = $steam_info['steamid'];
                $personaname = $steam_info['personaname'];
                $profileurl = $steam_info['profileurl'];
                $avatar = $steam_info['avatars']['medium'];
                // Check the avatar size set in the database.
                if ($check_avatar_size['value'] == '0') {
                    $avatar = $steam_info['avatars']['small'];
                }
                if ($check_avatar_size['value'] == '2') {
                    $avatar = $steam_info['avatars']['large'];
                }
                $personaname = strip_tags($personaname);
                //This is so people can not use tags that display.
                $personaname = $db->escape_string($personaname);
                // Perform a check to see if the user already exists in the database.
                $user_check = $db->num_rows($db->simple_select("users", "*", "loginname = '{$steamid}'"));
                if ($user_check == 0) {
                    $password = random_str(8);
                    $email = $steamid . '@steamcommunity.com';
                    $default_usergroup = 2;
                    // On a standard MyBB installation this is the group: Registered
                    require_once MYBB_ROOT . "inc/datahandlers/user.php";
                    $userhandler = new UserDataHandler("insert");
                    $new_user_data = array("username" => $personaname, "password" => $password, "password2" => $password, "email" => $email, "email2" => $email, "avatar" => $avatar, "usergroup" => $default_usergroup, "displaygroup" => $default_usergroup, "website" => $profileurl, "regip" => $session->ipaddress, "longregip" => my_ip2long($session->ipaddress), "loginname" => $steamid);
                    if ($check_required_field['value'] != "" and is_numeric($check_required_field['value'])) {
                        // Check the field exists.
                        $field_exists = $db->num_rows($db->simple_select("profilefields", "*", "fid = '" . $check_required_field['value'] . "'"));
                        if ($field_exists > 0) {
                            $new_user_data['profile_fields']['fid' . $check_required_field['value']] = $steamid;
                        }
                    }
                    $userhandler->set_data($new_user_data);
                    if ($userhandler->validate_user()) {
                        $user_info = $userhandler->insert_user();
                    }
                    // close if ($userhandler->validate_user())
                } else {
                    // close if($user_check == 0)
                    $update = array();
                    // Init our update array.
                    // Do our checks for both username and avatar.
                    if ($check_update_username['value'] == 1) {
                        $update['username'] = $personaname;
                    }
                    if ($check_update_avatar['value'] == 1) {
                        $update['avatar'] = $avatar;
                    }
                    // Run our update query if the array isn't empty.
                    if (!empty($update)) {
                        $db->update_query('users', $update, "loginname = '{$steamid}'");
                    }
                }
                // close else
                $user = $db->fetch_array($db->simple_select("users", "*", "loginname = '{$steamid}'"));
                // Login the user.
                my_setcookie("mybbuser", $user['uid'] . "_" . $user['loginkey'], true, true);
                my_setcookie("sid", $session->sid, -1, true);
                redirect("index.php", 'Your account has been authenticated and you have been logged in.<br/> Powered By <a href="http://www.steampowered.com" target="_blank">Steam</a>', 'Login via Steam');
            }
            // close if($steam_info['status'] == 'success')
        }
        // close else
    }
    // close if($mybb->input['action'] == 'steam_login')
}