X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=planetlab%2Fpersons%2Fregister.php;h=db2b44f3fe7b9365284407c8c8455c7e2a98888a;hb=0c1ecf9af4db5be0942850b8a08cc53595dcb86e;hp=16ca4facf013cd5a2b9dbc8dddfa0366e809fd68;hpb=ca9e63ad300735e10ae9d0bd9a8b0ad2feed276a;p=plewww.git diff --git a/planetlab/persons/register.php b/planetlab/persons/register.php index 16ca4fa..db2b44f 100644 --- a/planetlab/persons/register.php +++ b/planetlab/persons/register.php @@ -1,4 +1,3 @@ - 'First name', 'required' => TRUE, +global $person_form; + +$person_form = array(); +$person_form['first_name'] = array('title' => 'First name', 'required' => TRUE, 'maxlength' => 60, 'size' => 15); -$form['last_name'] = array('title' => 'Last name', 'required' => TRUE, +$person_form['last_name'] = array('title' => 'Last name', 'required' => TRUE, 'maxlength' => 60, 'size' => 15); -$form['title'] = array('title' => 'Title', 'required' => FALSE, +$person_form['title'] = array('title' => 'Title', 'required' => FALSE, 'maxlength' => 60, 'size' => 5); -$form['phone'] = array('title' => 'Telephone', 'required' => FALSE, +$person_form['phone'] = array('title' => 'Telephone', 'required' => FALSE, 'maxlength' => 60, 'size' => 20); -$form['email'] = array('title' => 'E-mail', 'required' => TRUE, +$person_form['email'] = array('title' => 'E-mail', 'required' => TRUE, 'maxlength' => 60, 'size' => 30); -$form['password'] = array('title' => 'Password', 'required' => TRUE, +$person_form['password'] = array('title' => 'Password', 'required' => TRUE, 'maxlength' => 60, 'size' => 20); -$form['site_ids'] = array('title' => 'Site', 'required' => TRUE); -$form['roles'] = array('title' => 'Additional Roles', 'required' => FALSE); +$person_form['site_ids'] = array('title' => 'Site', 'required' => TRUE); +if (0) + $person_form['roles'] = array('title' => 'Additional Roles', 'required' => FALSE); //////////////////// additional messages -$form['email']['comment'] = <<< EOF +$person_form['email']['comment'] = <<< EOF Your E-mail address must be able to receive e-mail and will be used as your $PLC_NAME username EOF; -$form['site_ids']['comment'] = <<< EOF -Select the site where you belong -EOF; -$form['roles']['comment'] = <<< EOF +// dirty hack feb 2018; if this file can be found, +// its contents is used instead of the hard-wired message +// it is searched along php's include path, so it should be +// allright to save it as /etc/planetlab/php/person-registration.txt +// of course html tags like and
are OK +global $message_filename; +$message_filename = "person-registration.txt"; + +try { + $person_form['site_ids']['comment'] = file_get_contents($message_filename, TRUE); +} catch (Exception $e) { + $person_form['site_ids']['comment'] = "Select the site where you belong"; +} + +if (0) + $person_form['roles']['comment'] = <<< EOF Do not select the Principal Investigator or Technical Contact roles unless you have spoken with the current PI of your site, and you intend to assume either or both of these roles.
Use Command-Clic to unselect or for multiple selection EOF; -//////////////////// +//////////////////// parse form values and store in $person global $person; $person = array(); -foreach ($form as $name => $item) { +foreach ($person_form as $name => $item) { if (!empty($_REQUEST[$name])) { $person[$name] = $_REQUEST[$name]; } @@ -86,41 +105,69 @@ if (!empty($person['site_ids'])) { create_function('$site_id', 'return intval($site_id) > 0;')); } -if (!empty($person)) { +//////////////////// minimal checking +function check_form ($person) { + global $person_form; + global $adm; + // Look for missing/blank entries $missing = array(); - foreach ($form as $name => $item) { + foreach ($person_form as $name => $item) { if ($item['required'] && empty($person[$name])) { $missing[] = $item['title']; } } + + // missing fields if (!empty($missing)) { - $error = ""; + $warnings=array(); + foreach ($missing as $field) $warnings []= "$field field is required."; + print html_div(plc_itemize($warnings),"messages error"); + return FALSE; } - if (empty($error)) { - // N.B.: site_ids and roles are ignored by AddPerson() - $person_id = $adm->AddPerson($person); - $error = $adm->error(); + // check that the email address is not already used on this peer + $email=$person['email']; + $already = $adm->GetPersons ( array('email'=>$person['email'],'peer_id'=>NULL) ); + if ( ! empty ($already) ) { + print html_div(plc_itemize(array("Email $email already used !")),"messages error"); + return FALSE; } - if (empty($error)) { + return TRUE; +} + +//////////////////// perform api calls +function register_person ($person) { + + global $adm; + + $errors = errors_init (); + + // jan-2013 with improvements in plcapi-5.1-6 about managing persons and tags, + // AddPerson has gone more picky and we need to remove some fields + // that no longer are silently ignored by AddPerson + $site_ids=$person['site_ids']; + unset ($person['site_ids']); + $roles=$person['roles']; + unset ($person['roles']); + + $person_id = $adm->AddPerson($person); + $errors = errors_record ($adm,$errors); + + if (empty($errors)) { $adm->begin(); // Add person to requested sites - foreach ($person['site_ids'] as $site_id) { + foreach ($site_ids as $site_id) { $adm->AddPersonToSite($person_id, intval($site_id)); $adm->SetPersonPrimarySite($person_id, intval($site_id)); } - // Add requested roles. Always add the user role. + // Add requested roles. Always add the user role. $adm->AddRoleToPerson('user', $person_id); - if (!empty($person['roles'])) { - foreach ($person['roles'] as $role) { + if (!empty($roles)) { + foreach ($roles as $role) { $adm->AddRoleToPerson($role, $person_id); } } @@ -135,18 +182,22 @@ if (!empty($person)) { $person['person_id'] = $person_id; $adm->commit(); - $error = $adm->error(); + $errors = errors_record ($adm,$errors); } - if (!empty($error)) { - print '
' . $error . '
'; + if (!empty($errors)) { + errors_display($errors); } else { - print '
Your registration request has been received. An e-mail has been sent to '; - print $person['email']; - print ' with further instructions.
'; + $email=$person['email']; + $text="Your registration request has been received. An e-mail has been sent to $email with further instructions."; + print html_div($text,"messages status"); } } +//////////////////// +if (!empty($person) && check_form ($person)) + register_person($person); + $PLC_NAME = htmlspecialchars(PLC_NAME); // E-mail address verified, go ahead and notify the PI (and possibly @@ -155,42 +206,43 @@ $PLC_NAME = htmlspecialchars(PLC_NAME); if (!empty($_REQUEST['id']) && !empty($_REQUEST['key'])) { $person_id = intval($_REQUEST['id']); if ($adm->VerifyPerson($person_id, $_REQUEST['key']) != 1) { - print '
' . $adm->error() . '.
'; + plc_error($adm->error()); } else { $persons = $adm->GetPersons(array($person_id)); $person = $persons[0]; // Remove the password field from the form so that it is not // highlighted as missing. - unset($form['password']); + unset($person_form['password']); - print '
'; - print 'Your e-mail address has been verified. '; - print 'The PI(s) at your site have been notified of your account registration '; + $messages = array(); + $messages []= 'Your e-mail address has been verified. '; + $messages []= 'The PI(s) at your site have been notified of your account registration '; - if (in_array('pi', $person['roles'])) { - $support = PLC_MAIL_SUPPORT_ADDRESS; - print " and should contact $PLC_NAME Support <$support>. "; - print " $PLC_NAME Support will enable your account if authorized by your PI(s)."; + if (! in_array('pi', $person['roles'])) { + $messages []= 'They are responsible for enabling your account.'; } else { - print ' and are responsible for enabling your account.'; + $support = PLC_MAIL_SUPPORT_ADDRESS; + $messages []= "They should contact $PLC_NAME Support <$support>. "; + $messages []= "$PLC_NAME Support will enable your account once authorized by your PI(s)."; } - print '
'; + plc_itemize($messages,"messages status"); } } -$self = $_SERVER['PHP_SELF']; -if (!empty($_SERVER['QUERY_STRING'])) { - $self .= "?" . $_SERVER['QUERY_STRING']; -} - $adm->begin(); // All defined sites // cannot register with foreign site -$adm->GetSites(array('is_public' => TRUE, 'peer_id' => NULL,'-SORT'=>'name'), - array('site_id', 'name','enabled','peer_id')); +// we also hide sites that are created by sfa +// as well as the ones that have a disabled_registration tag set +$adm->GetSites(array('is_public' => TRUE, 'peer_id' => NULL, + 'sfa_created' => NULL, + 'disabled_registration' => NULL, + '-SORT'=>'name'), + array('site_id', 'name', 'enabled', 'peer_id', + 'sfa_created', 'disabled_registration')); // All defined roles $adm->GetRoles(); @@ -211,14 +263,14 @@ function site_option($site) { $selected = ""; } - $option = "