Exemple #1
0
  	/**
  	 * Create the user.  The user cannot be created if the user is
  	 * banned or the user name or email already exists.  The optional
  	 * $p_userId parameter is there for the cases where Phorum is run
  	 * inside of another master application and you want to use the
  	 * master application user ID for the Phorum ID.
  	 *
  	 * @param string $p_username
	 * @param string $p_password
  	 * @param string $p_email
  	 * @param int $p_userId
  	 * @param bool $p_encryptedPassword
  	 * @return boolean
  	 */
  	public function create($p_username, $p_password, $p_email, $p_userId = null,
  	                       $p_encryptedPassword = false)
  	{
		$userdata = array();

	   	if (Phorum_user::UserNameExists($p_username)) {
	   		return false;
	   	}

	   	if (Phorum_user::EmailExists($p_email)) {
	   		return false;
	   	}

		if (Phorum_user::IsBanned($p_username, $p_email)) {
			return false;
		}

		if (!is_null($p_userId) && is_numeric($p_userId)) {
			$tmpUser = new Phorum_user($p_userId);
//			$userdata['user_id'] = $p_userId;
			$userdata['fk_campsite_user_id'] = $p_userId;
			if ($tmpUser->exists()) {
				unset($userdata['user_id']);
			}
		}

		$userdata['username'] = $p_username;
		$userdata['password'] = $p_encryptedPassword ? $p_password : sha1($p_password);
		$userdata['email'] = $p_email;
		$userdata['date_added'] = time();
		$userdata['date_last_active'] = time();
		$userdata['hide_email'] = true;
		$userdata['active'] = PHORUM_USER_ACTIVE;

		// Create the user
		$this->m_data['user_id'] = phorum_db_user_add( $userdata );

		// Refresh the object from the database.
		$this->fetch();

		return true;
	} // fn create
Exemple #2
0
$f_interview_id = Input::Get('f_interview_id', 'int', 0, true);

if (!Input::IsValid()) {
    camp_html_display_error(getGS('Invalid input: $1', Input::GetErrorString()), $_SERVER['REQUEST_URI']);
    exit;
}

$Interview = new Interview($f_interview_id);

// new usernames may exist
foreach(array('guest') as $type) {
    if ($_REQUEST['f_'.$type.'_user_id'] == '__new__') {
        require_once($GLOBALS['g_campsiteDir']. "/$ADMIN_DIR/users/users_common.php");
    
        if (User::UserNameExists($_REQUEST['f_'.$type.'_new_user_login']) || Phorum_user::UserNameExists($_REQUEST['f_'.$type.'_new_user_login'])) {
            $errorMsg = getGS('User name $1 already exists, please choose a different login name.', $_REQUEST['f_'.$type.'_new_user_login']);
            camp_html_add_msg($errorMsg);
            $error = true;
        }
    }    
};

if (!$error && $Interview->store()) {
    ?>
    <script language="javascript">
        window.opener.location.reload();
        window.close();
    </script>
    <?php
    exit();
    /**
     * Performs the action; returns true on success, false on error.
     *
     * @param $p_context - the current context object
     * @return bool
     */
    public function takeAction(CampContext &$p_context)
    {
        $p_context->default_url->reset_parameter('f_'.$this->m_name);
        $p_context->url->reset_parameter('f_'.$this->m_name);

        if (PEAR::isError($this->m_error)) {
            return false;
        }

        $metaUser = $p_context->user;
        if (!$metaUser->defined) {
            $this->m_properties['type'] = 'add';
            if (!MetaAction::ValidateInput($this->m_properties, 'name', 1,
            $this->m_error, 'The user name was not filled in.', ACTION_EDIT_USER_ERR_NO_NAME)) {
                return false;
            }
            if (!MetaAction::ValidateInput($this->m_properties, 'uname', 1,
            $this->m_error, 'The user login name was not filled in.',
            ACTION_EDIT_USER_ERR_NO_USER_NAME)) {
                return false;
            }
            if (!MetaAction::ValidateInput($this->m_properties, 'password', 6,
            $this->m_error, 'The user password was not filled in or was too short.',
            ACTION_EDIT_USER_ERR_NO_PASSWORD)) {
                return false;
            }
            if (!MetaAction::ValidateInput($this->m_properties, 'passwordagain', 6,
            $this->m_error, 'The password confirmation was not filled in or was too short.',
            ACTION_EDIT_USER_ERR_NO_PASSWORD_CONFIRMATION)) {
                return false;
            }
            if (!MetaAction::ValidateInput($this->m_properties, 'email', 8,
            $this->m_error, 'The user email was not filled in or was invalid.',
            ACTION_EDIT_USER_ERR_NO_EMAIL)) {
                return false;
            }

            if (SystemPref::Get('PLUGIN_RECAPTCHA_SUBSCRIPTIONS_ENABLED') == 'Y') {
                $captcha = Captcha::factory('ReCAPTCHA');
                if (!$captcha->validate()) {
                    $this->m_error = new PEAR_Error('The code you entered is not the same as the one shown.',
                        ACTION_SUBMIT_COMMENT_ERR_INVALID_CAPTCHA_CODE);
                    return false;
                }
            }
        } else {
            $this->m_properties['type'] = 'edit';
            if (isset($this->m_properties['password'])) {
                if (!MetaAction::ValidateInput($this->m_properties, 'password', 6,
                $this->m_error, 'The user password was not filled in or was too short.',
                ACTION_EDIT_USER_ERR_NO_PASSWORD)) {
                    return false;
                }
                if (!MetaAction::ValidateInput($this->m_properties, 'passwordagain', 6,
                $this->m_error, 'The password confirmation was not filled in or was too short.',
                ACTION_EDIT_USER_ERR_NO_PASSWORD_CONFIRMATION)) {
                    return false;
                }
            }
        }

        if (isset($this->m_properties['password'])
        && $this->m_properties['password'] != $this->m_properties['passwordagain']) {
            $this->m_error = new PEAR_Error("The password and password confirmation do not match.",
            ACTION_EDIT_USER_ERR_PASSWORD_MISMATCH);
            return false;
        }

        if (!$metaUser->defined) {
            if (User::UserNameExists($this->m_properties['uname'])
            || Phorum_user::UserNameExists($this->m_properties['uname'])) {
                $this->m_error = new PEAR_Error("The login name already exists, please choose a different one.",
                ACTION_EDIT_USER_ERR_DUPLICATE_USER_NAME);
                return false;
            }
            if (User::EmailExists($this->m_properties['email'])) {
                $this->m_error = new PEAR_Error("Another user is registered with this e-mail address, please choose a different one.",
                ACTION_EDIT_USER_ERR_DUPLICATE_EMAIL);
                return false;
            }
            $user = new User();
            $phorumUser = new Phorum_user();
            if (!$user->create($this->m_data)
            || !$phorumUser->create($this->m_properties['uname'], $this->m_properties['password'], $this->m_properties['email'], $user->getUserId())) {
                $user->delete();
                $phorumUser->delete();
                $this->m_error = new PEAR_Error("There was an internal error creating the account (code 1).",
                ACTION_EDIT_USER_ERR_INTERNAL);
                return false;
            }
            setcookie("LoginUserId", $user->getUserId(), null, '/');
            $user->initLoginKey();
            setcookie("LoginUserKey", $user->getKeyId(), null, '/');
            $p_context->user = new MetaUser($user->getUserId());
        } else {
            $user = new User($metaUser->identifier);
            if (!$user->exists()) {
                $this->m_error = new PEAR_Error("There was an internal error updating the account (code 2).",
                ACTION_EDIT_USER_ERR_INTERNAL);
                return false;
            }
            $phorumUser = Phorum_user::GetByUserName($user->getUserName());
            if (is_null($phorumUser)) {
                $phorumUser = new Phorum_user();
                if (!$phorumUser->create($user->getUserName(), $user->getPassword(), $user->getEmail(), $user->getUserId(), true)) {
                    $this->m_error = new PEAR_Error("There was an internal error updating the account (code 3).",
                    ACTION_EDIT_USER_ERR_INTERNAL);
                    return false;
                }
            }
            foreach ($this->m_properties as $property=>$value) {
                if (!isset(MetaActionEdit_User::$m_fields[$property]['db_field'])) {
                    continue;
                }
                $dbProperty = MetaActionEdit_User::$m_fields[$property]['db_field'];
                if ($property != 'password' && $property != 'passwordagain') {
                    $user->setProperty($dbProperty, $value, false);
                    if ($property == 'email') {
                        $phorumUser->setProperty('email', $value, false);
                    }
                } elseif ($property == 'password') {
                    $user->setPassword($this->m_properties['password'], false);
                    $phorumUser->setPassword($this->m_properties['password'], false);
                }
            }
            if (!$user->commit() || !$phorumUser->commit()) {
                $this->m_error = new PEAR_Error("There was an internal error updating the account (code 4).",
                ACTION_EDIT_USER_ERR_INTERNAL);
                return false;
            }
        }

        foreach ($this->m_properties as $property=>$value) {
            $p_context->default_url->reset_parameter('f_user_'.$property);
            $p_context->url->reset_parameter('f_user_'.$property);
        }

        $this->m_error = ACTION_OK;
        return true;
    }
Exemple #4
0
    public function store($p_user_id = null)
    {
        require_once 'HTML/QuickForm.php';

        $mask = self::getFormMask($p_owner, $p_admin);
        $form = new html_QuickForm('interview', 'post', $p_target, null, null, true);
        FormProcessor::parseArr2Form($form, $mask);

        if ($form->validate() && SecurityToken::isValid()) {
            $data = $form->getSubmitValues();

            $image_id = $this->getProperty('fk_image_id');

            if ($data['f_image_delete'] && $image_id) {
                $Image = new Image($this->getProperty('fk_image_id'));
                $Image->delete();
                $image_id = null;
            } else {
                $file = $form->getElementValue('f_image');
                if (strlen($file['name'])) {
                    $attributes = array(
                        'Description' => strlen($data['f_image_description']) ? $data['f_image_description'] : $file['name'],
                    );
                    $Image = Image::OnImageUpload($file, $attributes, $p_user_id, !empty($image_id) ? $image_id : null);
                    if (is_a($Image, 'Image')) {
                        $image_id = $Image->getProperty('Id');
                    } else {
                        return false;
                    }
                }
            }

            // may have to create new user account for guest
            foreach (array('guest') as $type) {
                if ($data['f_'.$type.'_user_id'] == '__new__') {
                    global $ADMIN_DIR;
                    require_once($GLOBALS['g_campsiteDir']. "/$ADMIN_DIR/users/users_common.php");

                    $passwd = substr(sha1(rand()), 0, 10);

                    $fieldValues = array(
                        'UName' => $data['f_'.$type.'_new_user_login'],
                        'Name'  => $data['f_'.$type.'_new_user_login'].' (interview guest)',
                        'EMail' => $data['f_'.$type.'_new_user_email'],
                        'passwd' => $passwd,
                        'Reader' => 'N'
                    );
                    // create user
                    $editUser = new User();
                    $phorumUser = new Phorum_user();

                    if ($phorumUser->UserNameExists($fieldValues['UName']) || User::UserNameExists($fieldValues['UName'])) {
                        return false;
                    }

                    if (!$editUser->create($fieldValues)) {
                        return false;
                    }

                	$editUser->setUserType('Staff');
                	$editUser->setPermission('plugin_interview_'.$type, true);

                	$phorumUser->create($fieldValues['UName'], $passwd, $fieldValues['EMail'], $editUser->getUserId());

                    $userid[$type] = $editUser->getUserId();
                } else {
                     $userid[$type] = $data['f_'.$type.'_user_id'];
                }
            }

            if ($this->exists()) {
                // edit existing interview
                $this->setProperty('fk_language_id', $data['f_language_id']);
                $this->setProperty('title', $data['f_title']);
                $this->setProperty('fk_image_id', $image_id);
                $this->setProperty('description_short', $data['f_description_short']);
                $this->setProperty('description', $data['f_description']);
                $this->setProperty('interview_begin', $data['f_interview_begin']);
                $this->setProperty('interview_end', $data['f_interview_end']);
                $this->setProperty('questions_begin', $data['f_questions_begin']);
                $this->setProperty('questions_end', $data['f_questions_end']);
                $this->setProperty('questions_limit', $data['f_questions_limit']);
                $this->setProperty('status', $data['f_status']);
                $this->setProperty('fk_moderator_user_id', $data['f_moderator_user_id']);
                $this->setProperty('fk_guest_user_id', $userid['guest']);

                if (strlen($passwd)) {
                    $this->setProperty('invitation_password', $passwd);
                }

                return true;

            } else {
                // create new interview
                $created = $this->create(
                    $data['f_language_id'],
                    $data['f_moderator_user_id'],
                    $userid['guest'],
                    $data['f_title'],
                    $image_id,
                    $data['f_description_short'],
                    $data['f_description'],
                    $data['f_interview_begin'],
                    $data['f_interview_end'],
                    $data['f_questions_begin'],
                    $data['f_questions_end'],
                    $data['f_questions_limit'],
                    $data['f_status']
                );

                if (strlen($passwd)) {
                    $this->setProperty('invitation_password', $passwd);
                }

                return $created;
            }
        }
        return false;
    }
Exemple #5
0
    camp_html_goto_page($backLink);
}

// read password
$password = Input::Get('password', 'string', '');
$passwordConf = Input::Get('passwordConf', 'string', '');
if (strlen($password) < 6 || $password != $passwordConf) {
	$errorMsg = getGS('The password must be at least 6 characters long and both passwords should match.');
	camp_html_add_msg($errorMsg);
	camp_html_goto_page($backLink);
}
$fieldValues['passwd'] = $password;

// create user
$editUser = new User();
$phorumUser = new Phorum_user();
if (!$phorumUser->UserNameExists($fieldValues['UName']) &&
        $editUser->create($fieldValues)) {
    if ($uType == 'Staff') {
        $editUser->setUserType($Type);
    }
    $phorumUser->create($fieldValues['UName'], $password, $fieldValues['EMail'], $editUser->getUserId());
    camp_html_add_msg(getGS('User account $1 was created successfully.', $editUser->getUserName()), "ok");
    camp_html_goto_page("/$ADMIN/users/edit.php?User="******"&$typeParam");
} else {
    camp_html_add_msg(getGS('The user account could not be created.'));
    camp_html_goto_page($backLink);
}

?>