Commit cd5f1e1c authored by niclone's avatar niclone

[NEW] Allow users to register via intertiki on a slave

parent 59715d24
......@@ -80,4 +80,4 @@ class NotificationLib extends TikiLib
}
}
$notificationlib = new NotificationLib;
$GLOBALS['notificationlib'] = new NotificationLib;
This diff is collapsed.
......@@ -39,7 +39,9 @@ $map = array(
"intertiki.logout" => array("function"=>"logout"),
"intertiki.cookiecheck" => array("function"=>"cookie_check"),
"intertiki.version" => array("function"=>"get_version"),
'intertiki.getUserInfo' => array('function' => 'get_user_info')
'intertiki.getUserInfo' => array('function' => 'get_user_info'),
'intertiki.getRegistrationPrefs' => array('function' => 'get_registration_prefs'),
'intertiki.registerUser' => array('function' => 'register_user')
);
$s = new XML_RPC_Server($map);
......@@ -94,7 +96,7 @@ function validate($params) {
}
function set_user_info($params) {
global $userlib, $prefs;
global $tikilib, $userlib, $prefs;
if ($prefs['feature_userPreferences'] != 'y') {
return new XML_RPC_Response(new XML_RPC_Value(1, 'boolean'));
}
......@@ -111,7 +113,7 @@ function set_user_info($params) {
}
function logout($params) {
global $userlib,$logslib,$prefs;
global $tikilib, $userlib,$logslib,$prefs;
$key = $params->getParam(0); $key = $key->scalarval();
$login = $params->getParam(1); $login = $login->scalarval();
if (!isset($prefs['known_hosts'][$key]) or $prefs['known_hosts'][$key]['ip'] != $tikilib->get_ip_address()) {
......@@ -129,7 +131,7 @@ function logout($params) {
}
function cookie_check($params) {
global $userlib,$prefs;
global $tikilib, $userlib,$prefs;
$key = $params->getParam(0); $key = $key->scalarval();
$hash = $params->getParam(1); $hash = $hash->scalarval();
if (!isset($prefs['known_hosts'][$key]) or $prefs['known_hosts'][$key]['ip'] != $tikilib->get_ip_address()) {
......@@ -153,7 +155,7 @@ function get_version($params) {
}
function get_user_info($params) {
global $prefs, $userlib;
global $tikilib, $prefs, $userlib;
$key = $params->getParam(0); $key = $key->scalarval();
if (!isset($prefs['known_hosts'][$key]) or $prefs['known_hosts'][$key]['ip'] != $tikilib->get_ip_address()) {
$msg = tra('Invalid server key');
......@@ -177,3 +179,44 @@ function get_user_info($params) {
$ret['email'] = new XML_RPC_Value($email, "string");
return new XML_RPC_Response(new XML_RPC_Value($ret, "struct"));
}
function get_registration_prefs($params) {
global $tikilib, $prefs, $registrationlib, $logslib;
$key = $params->getParam(0); $key = $key->scalarval();
if (!isset($prefs['known_hosts'][$key]) or $prefs['known_hosts'][$key]['ip'] != $tikilib->get_ip_address()) {
$msg = tra('Invalid server key');
if ($prefs['intertiki_errfile']) logit($prefs['intertiki_errfile'],$msg,$key,INTERTIKI_BADKEY,$prefs['known_hosts'][$key]['name']);
$logslib->add_log('intertiki',$msg.' from '.$prefs['known_hosts'][$key]['name'],$login);
return new XML_RPC_Response(0, 101, $msg);
}
if (!isset($prefs['known_hosts'][$key]['allowusersregister']) || ($prefs['known_hosts'][$key]['allowusersregister'] != 'y'))
return new XML_RPC_Response(0, 101, "Users are not allowed to register via intertiki on this master.");
require_once 'lib/registration/registrationlib.php';
return new XML_RPC_Response(XML_RPC_encode($registrationlib->merged_prefs));
}
function register_user($params) {
global $tikilib, $prefs, $registrationlib, $logslib;
$key = $params->getParam(0); $key = $key->scalarval();
if (!isset($prefs['known_hosts'][$key]) or $prefs['known_hosts'][$key]['ip'] != $tikilib->get_ip_address()) {
$msg = tra('Invalid server key');
if ($prefs['intertiki_errfile']) logit($prefs['intertiki_errfile'],$msg,$key,INTERTIKI_BADKEY,$prefs['known_hosts'][$key]['name']);
$logslib->add_log('intertiki',$msg.' from '.$prefs['known_hosts'][$key]['name'],$login);
return new XML_RPC_Response(0, 101, $msg);
}
if (!isset($prefs['known_hosts'][$key]['allowusersregister']) || ($prefs['known_hosts'][$key]['allowusersregister'] != 'y'))
return new XML_RPC_Response(0, 101, "Users are not allowed to register via intertiki on this master.");
require_once 'lib/registration/registrationlib.php';
$result=$registrationlib->register_new_user_from_intertiki(XML_RPC_decode($params->getParam(1)));
return new XML_RPC_Response(XML_RPC_encode($result));
}
......@@ -95,7 +95,7 @@
<form action="tiki-register.php" method="post" name="RegForm">
<table class="form">
{include file="register-form.tpl"}
{if $prefs.feature_antibot eq 'y'}{include file='antibot.tpl' td_style='formcolor'}{/if}
{if $merged_prefs.feature_antibot eq 'y'}{include file='antibot.tpl' td_style='formcolor'}{/if}
<tr>
<td class="formcolor">&nbsp;</td>
<td class="formcolor"><input type="submit" name="register" value="{tr}Register{/tr}" /></td>
......
......@@ -7,10 +7,12 @@
require_once ('tiki-setup.php');
require_once ('lib/registration/registrationlib.php');
if (is_a($registrationlib->merged_prefs, "RegistrationError")) register_error($registrationlib->merged_prefs->msg);
$smarty->assign_by_ref('merged_prefs', $registrationlib->merged_prefs);
$smarty->assign('headtitle', tra('Register'));
// Permission: needs p_register and not to be a slave
if ($prefs['allowRegister'] != 'y' || ($prefs['feature_intertiki'] == 'y' && !empty($prefs['feature_intertiki_mymaster']))) {
if ($prefs['allowRegister'] != 'y') {
header("location: index.php");
die;
}
......@@ -27,32 +29,19 @@ if (!$https_mode && $prefs['https_login'] == 'required') {
header('Location: ' . $base_url_https . 'tiki-register.php');
die;
}
// novalidation is set to yes if a user confirms his email is correct after tiki fails to validate it
if (!isset($_REQUEST['novalidation'])) {
$novalidation = '';
} else {
$novalidation = $_REQUEST['novalidation'];
}
//get custom fields
$customfields = $registrationlib->get_customfields();
$smarty->assign_by_ref('customfields', $customfields);
$listgroups = $userlib->get_groups(0, -1, 'groupName_asc', '', '', 'n');
$nbChoiceGroups = 0;
$mandatoryChoiceGroups = true;
foreach($listgroups['data'] as $gr) {
if ($gr['registrationChoice'] == 'y') {
++$nbChoiceGroups;
$theChoiceGroup = $gr['groupName'];
if ($gr['groupName'] == 'Registered') $mandatoryChoiceGroups = false;
}
}
if ($nbChoiceGroups) {
$smarty->assign('listgroups', $listgroups['data']);
if ($nbChoiceGroups == 1) {
$smarty->assign_by_ref('theChoiceGroup', $theChoiceGroup);
}
//groups choice
if (count($registrationlib->merged_prefs['choosable_groups'])) {
$smarty->assign('listgroups', $registrationlib->merged_prefs['choosable_groups']);
if (count($registrationlib->merged_prefs['choosable_groups']) == 1) {
$smarty->assign_by_ref('theChoiceGroup', $registrationlib->merged_prefs['choosable_groups'][0]['groupName']);
}
}
$email_valid='y';
if (isset($_REQUEST['register'])) {
check_ticket('register');
$cookie_name = $prefs['session_cookie_name'];
......@@ -62,9 +51,8 @@ if (isset($_REQUEST['register'])) {
$smarty->assign('errortype', 'no_redirect_login');
$email_valid='y';
$result=$registrationlib->register_new_user($_REQUEST);
if (is_a($result, 'RegistrationError')) {
if (is_a($result,"RegistrationError")) {
if ($result->field == 'email' && $result->field == 'email_not_valid') // i'm not sure why email is a special case..
$email_valid='n';
else
......@@ -76,15 +64,15 @@ if (isset($_REQUEST['register'])) {
}
if ($prefs['userTracker'] == 'y') {
if ($registrationlib->merged_prefs['userTracker'] == 'y') {
$re = $userlib->get_group_info(isset($_REQUEST['chosenGroup']) ? $_REQUEST['chosenGroup'] : 'Registered');
if (!empty($re['usersTrackerId']) && !empty($re['registrationUsersFieldIds'])) {
include_once ('lib/wiki-plugins/wikiplugin_tracker.php');
if ($prefs["user_register_prettytracker"] == 'y' && !empty($prefs["user_register_prettytracker_tpl"])) {
if (substr($prefs["user_register_prettytracker_tpl"], -4) == ".tpl") {
$userTrackerData = wikiplugin_tracker('', array('trackerId' => $re['usersTrackerId'], 'fields' => $re['registrationUsersFieldIds'], 'showdesc' => 'y', 'showmandatory' => 'y', 'embedded' => 'n', 'action' => tra('Register'), 'registration' => 'y', 'tpl' => $prefs["user_register_prettytracker_tpl"]));
if ($registrationlib->merged_prefs["user_register_prettytracker"] == 'y' && !empty($registrationlib->merged_prefs["user_register_prettytracker_tpl"])) {
if (substr($registrationlib->merged_prefs["user_register_prettytracker_tpl"], -4) == ".tpl") {
$userTrackerData = wikiplugin_tracker('', array('trackerId' => $re['usersTrackerId'], 'fields' => $re['registrationUsersFieldIds'], 'showdesc' => 'y', 'showmandatory' => 'y', 'embedded' => 'n', 'action' => tra('Register'), 'registration' => 'y', 'tpl' => $registrationlib->merged_prefs["user_register_prettytracker_tpl"]));
} else {
$userTrackerData = wikiplugin_tracker('', array('trackerId' => $re['usersTrackerId'], 'fields' => $re['registrationUsersFieldIds'], 'showdesc' => 'y', 'showmandatory' => 'y', 'embedded' => 'n', 'action' => tra('Register'), 'registration' => 'y', 'wiki' => $prefs["user_register_prettytracker_tpl"]));
$userTrackerData = wikiplugin_tracker('', array('trackerId' => $re['usersTrackerId'], 'fields' => $re['registrationUsersFieldIds'], 'showdesc' => 'y', 'showmandatory' => 'y', 'embedded' => 'n', 'action' => tra('Register'), 'registration' => 'y', 'wiki' => $registrationlib->merged_prefs["user_register_prettytracker_tpl"]));
}
} else {
$userTrackerData = wikiplugin_tracker('', array('trackerId' => $re['usersTrackerId'], 'fields' => $re['registrationUsersFieldIds'], 'showdesc' => 'y', 'showmandatory' => 'y', 'embedded' => 'n', 'action' => tra('Register'), 'registration' => 'y'));
......@@ -96,10 +84,10 @@ if ($prefs['userTracker'] == 'y') {
$smarty->assign('email_valid', $email_valid);
ask_ticket('register');
$_VALID = tra("Please enter a valid %s. No spaces, more than %d characters and contain %s");
$smarty->assign('_PROMPT_UNAME', sprintf($_VALID, tra("username"), $prefs['min_username_length'], "0-9,a-z,A-Z"));
$smarty->assign('_PROMPT_PASS', sprintf($_VALID, tra("password"), $prefs['min_pass_length'], "0-9,a-z,A-Z"));
$smarty->assign('min_username_length', $prefs['min_username_length']);
$smarty->assign('min_pass_length', $prefs['min_pass_length']);
$smarty->assign('_PROMPT_UNAME', sprintf($_VALID, tra("username"), $registrationlib->merged_prefs['min_username_length'], "0-9,a-z,A-Z"));
$smarty->assign('_PROMPT_PASS', sprintf($_VALID, tra("password"), $registrationlib->merged_prefs['min_pass_length'], "0-9,a-z,A-Z"));
$smarty->assign('min_username_length', $registrationlib->merged_prefs['min_username_length']);
$smarty->assign('min_pass_length', $registrationlib->merged_prefs['min_pass_length']);
// disallow robots to index page:
$smarty->assign('metatag_robots', 'NOINDEX, NOFOLLOW');
// xajax
......@@ -151,6 +139,7 @@ function chkRegEmail($mail) {
function register_error($msg) {
global $smarty;
$smarty->assign('msg', $msg);
$smarty->assign('errortype', 0);
$smarty->display("error.tpl");
die;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment