Exemple #1
0
	function testUserCreateDelete()
	{
		$user = Phorum_user::GetByUserName('bob');
		if ($user) {
			if (!$user->delete()) {
				$this->fail("Could not delete pre-existing user");
				return;
			}
		}
		$user = new Phorum_user();
		$user->create('bob', '*****@*****.**');
		if (!$user->exists()) {
			$this->fail("Could not create user.");
		}

		if (!$user->delete()) {
			$this->fail("Could not delete user");
		}
	}
    /**
     * Create the first message for an article, which is a blank message
     * with the title of the article as the subject.
     *
     * @param Article $p_article
     * @param int $p_forumId
     * @return mixed
     * 		The comment created (or the one that already exists) on success,
     *  	or false on error.
     */
    private function CreateFirstComment($p_article, $p_forumId)
    {
        // Check if the first post already exists.
        $articleNumber = $p_article->getArticleNumber();
        $languageId = $p_article->getLanguageId();
        $firstPost = ArticleComment::GetCommentThreadId($articleNumber, $languageId);
        if ($firstPost) {
            return new Phorum_message($firstPost);
        }

        // Get article creator
        $user = new User($p_article->getCreatorId());
        if ($user->exists()) {
            $userId = $user->getUserId();
            $userEmail = $user->getEmail();
            $userPasswd = $user->getPassword();
            $userName = $user->getUserName();
            $userRealName = $user->getRealName();

            // Create phorum user if necessary
            $phorumUser = Phorum_user::GetByUserName($userName);
            if (!is_object($phorumUser)) {
                $phorumUser = new Phorum_user();
            }
            if (!$phorumUser->CampUserExists($userId)
            && !$phorumUser->create($userName, $userPasswd, $userEmail, $userId)) {
                return null;
            }
        } else {
            $userId = null;
            $userEmail = '';
            $userRealName = '';
        }

        // Create the comment.
        $title = $p_article->getTitle();
        $commentObj = new Phorum_message();
        if ($commentObj->create($p_forumId, $title, '', 0, 0, $userRealName,
        $userEmail, is_null($userId) ? 0 : $userId)) {
            // Link the message to the current article.
            ArticleComment::Link($articleNumber, $languageId, $commentObj->getMessageId(), true);
            return $commentObj;
        } else {
            return null;
        }
    } // method CreateFirstComment
Exemple #3
0
    /**
     * Sync all campsite and phorum users.
     *
     * @return void
     */
    public static function SyncPhorumUsers()
    {
        require_once($GLOBALS['g_campsiteDir'].'/include/phorum_load.php');
        require_once($GLOBALS['g_campsiteDir'].'/classes/Phorum_user.php');

        $g_ado_db = $GLOBALS['g_ado_db'];
        $queryStr = 'SELECT u.Id, pu.user_id, u.UName, u.Password, u.EMail
                        FROM liveuser_users AS u LEFT JOIN phorum_users AS pu
                            ON u.UName = pu.username
                        WHERE fk_campsite_user_id IS NULL
                            OR fk_campsite_user_id != u.Id';
        $nullUsers = $g_ado_db->GetAll($queryStr);
        if (!is_array($nullUsers) || empty($nullUsers)) { // all synced
            return;
        }

        foreach ($nullUsers as $nullUser) {
            if (empty($nullUser['user_id'])) {
                $phorumUser = new Phorum_user();
                $phorumUser->create($nullUser['UName'], $nullUser['Password'],
                                    $nullUser['EMail'], $nullUser['Id'], true);
            } else {
                $sql = 'UPDATE phorum_users SET fk_campsite_user_id = NULL
                        WHERE fk_campsite_user_id = ' . $nullUser['Id'];
                $g_ado_db->Execute($sql);
                $sql = 'UPDATE phorum_users SET fk_campsite_user_id = ' . $nullUser['Id'] . '
                        WHERE user_id = ' . $nullUser['user_id'];
                $g_ado_db->Execute($sql);
            }
        }
    } // fn SyncPhorumUsers
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;
    }
    /**
     * 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 #6
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);
}

?>