Пример #1
0
/**
 * A common function which is used to save the userdata from the post-data.
 * @param panel - The panel for which to save data.
 * @return array - An array containing $error and $okmsg.
 */
function phorum_controlcenter_user_save($panel)
{
    $PHORUM = $GLOBALS['PHORUM'];
    $error = "";
    $okmsg = "";

    // Setup the default userdata fields that may be changed
    // from the control panel interface.
    $userdata = array(
        'signature'       => NULL,
        'hide_email'      => NULL,
        'hide_activity'   => NULL,
        'password'        => NULL,
        'tz_offset'       => NULL,
        'is_dst'          => NULL,
        'user_language'   => NULL,
        'threaded_list'   => NULL,
        'threaded_read'   => NULL,
        'email_notify'    => NULL,
        'show_signature'  => NULL,
        'pm_email_notify' => NULL,
        'email'           => NULL,
        'email_temp'      => NULL,
        'user_template'   => NULL,
        'moderation_email'=> NULL,
    );
    // Add custom profile fields as acceptable fields.
    foreach ($PHORUM["PROFILE_FIELDS"] as $field) {
        $userdata[$field["name"]] = NULL;
    }
    // Update userdata with $_POST information.
    foreach ($_POST as $key => $val) {
       if (array_key_exists($key, $userdata)) {
           $userdata[$key] = $val;
       }
    }
    // Remove unused profile fields.
    foreach ($userdata as $key => $val) {
        if (is_null($val)) {
            unset($userdata[$key]);
        }
    }

    // Set static userdata.
    $userdata["user_id"] = $PHORUM["user"]["user_id"];
    $userdata["fk_campsite_user_id"] = $PHORUM["user"]["fk_campsite_user_id"];

    // Run a hook, so module writers can update and check the userdata.
    $userdata = phorum_hook("cc_save_user", $userdata);

    // Set $error, in case the before_register hook did set an error.
    if (isset($userdata['error'])) {
        $error=$userdata['error'];
        unset($userdata['error']);
    // Try to update the userdata in the database.
    } elseif (!phorum_user_save($userdata)) {
        // Updating the user failed.
        $error = $PHORUM["DATA"]["LANG"]["ErrUserAddUpdate"];
    } else {
	// Sync the campsite user
	require_once('../../admin-files/localizer/Localizer.php');
	require_once('../../classes/User.php');
	$campsiteUser = new User($userdata["fk_campsite_user_id"]);
	if ($campsiteUser->exists()) {
		if (array_key_exists('password', $userdata)) {
			$campsiteUser->setPassword($userdata["password"]);
		} elseif (array_key_exists('email', $userdata)) {
			$campsiteUser->setProperty('EMail', $userdata["email"]);
		}
	}

        // Updating the user was successful.
        $okmsg = $PHORUM["DATA"]["LANG"]["ProfileUpdatedOk"];

        // Let the userdata be reloaded.
        phorum_user_set_current_user($userdata["user_id"]);

        // If a new password was set, let's create a new session.
        if (isset($userdata["password"]) && !empty($userdata["password"])) {
            phorum_user_create_session();
        }

        // Copy data from the updated user back into the template data.
        // Leave PANEL and forum_id alone (these are injected into the
        // userdata in the template from this script).
        foreach ($GLOBALS["PHORUM"]["DATA"]["PROFILE"] as $key => $val) {
            if ($key == "PANEL" || $key == "forum_id") continue;
            if (isset($GLOBALS["PHORUM"]["user"][$key])) {
                $GLOBALS["PHORUM"]["DATA"]["PROFILE"][$key] = $GLOBALS["PHORUM"]["user"][$key];
            } else {
                $GLOBALS["PHORUM"]["DATA"]["PROFILE"][$key] = "";
            }
        }
    }

    return array($error, $okmsg);
}
Пример #2
0
function phorum_user_check_login( $username, $password )
{
    $ret = false;
    $temp_check = false;

    $user_id = phorum_db_user_check_pass( $username, sha1( $password ) );
    // regular password failed, try the temp password
    if ( $user_id == 0 ) {
        $user_id = phorum_db_user_check_pass( $username, sha1( $password ), true );
        $temp_check = true;
    }

    if ( $user_id > 0 ) {
        // if this was a temp password, set the normal pass to the temp password
        // do this before we get the user so the data is up to date.
        // leave the temp password alone as setting to empty is bad.
        if ( $temp_check ) {
            $tmp_user["user_id"] = $user_id;
            $tmp_user["password"] = $password;
            phorum_user_save( $tmp_user );
        }

        $ret = phorum_user_set_current_user( $user_id );
    }

    return $ret;
}