From 05411893eee11af861e93000f4064d9a6ea23455 Mon Sep 17 00:00:00 2001 From: Thierry Parmentelat Date: Fri, 18 Sep 2009 11:15:38 +0000 Subject: [PATCH] registration pages reviewed and nicer - check for existing email --- planetlab/css/plc_style.css | 22 ++- planetlab/includes/plc_functions.php | 41 +++--- planetlab/persons/register.php | 196 ++++++++++++++------------- planetlab/sites/join_request.php | 41 +++--- planetlab/sites/register.php | 25 +++- planetlab/sites/site_form.php | 25 ++-- planetlab/sites/switch_site.php | 73 ---------- planetlab/sites/test.php | 39 ------ 8 files changed, 196 insertions(+), 266 deletions(-) delete mode 100644 planetlab/sites/switch_site.php delete mode 100644 planetlab/sites/test.php diff --git a/planetlab/css/plc_style.css b/planetlab/css/plc_style.css index 1edabeb..7897556 100644 --- a/planetlab/css/plc_style.css +++ b/planetlab/css/plc_style.css @@ -26,11 +26,11 @@ body { } .plc-warning { - padding: 4px; + padding: 4px; background: #ffa223; } .plc-error { - background: red; + background: red; font-weight: bold; } @@ -104,3 +104,21 @@ div#add_slice_in_site { #add_slice_choose_site { margin:20px ; } + +/* registrations */ +div.site-register { + background-color: #c8c7de; + padding: 5px; + margin: 10px; +} +/* site registration */ +div.site-pending { + background-color: #eadbc8; + padding: 5px; + margin: 10px; +} +div.person-register { + background-color: #e3d1cb; + padding: 5px; + margin: 10px; +} diff --git a/planetlab/includes/plc_functions.php b/planetlab/includes/plc_functions.php index facf215..c72c598 100644 --- a/planetlab/includes/plc_functions.php +++ b/planetlab/includes/plc_functions.php @@ -345,11 +345,34 @@ function plc_itemize ($messages, $class="") { } ////////// +function truncate ($text,$numb,$etc = "...") { + if (strlen($text) > $numb) { + $text = substr($text, 0, $numb); + $text = $text.$etc; + } + return $text; +} +function html_div ($text,$class="") { + $html=" " . $text . ""; } +function plc_error_html ($text) { return html_div ($text,'plc-error'); } function plc_error ($text) { print plc_error_html ("Error " . $text); } -function plc_errors ($errors) { +function errors_init() { return array();} +function errors_record ($adm, $errors) { + if ($adm->error()) { + $tmp=$adm->error(); + $errors []= $tmp; + } + return $errors; +} + +function errors_display ($errors) { if ($errors) { print( "
" ); print( "

The following errors occured:

" ); @@ -372,20 +395,6 @@ function plc_debug ($message,$object) { print ""; } -function truncate ($text,$numb,$etc = "...") { - if (strlen($text) > $numb) { - $text = substr($text, 0, $numb); - $text = $text.$etc; - } - return $text; -} -function html_div ($text,$class="") { - $html="$text"); diff --git a/planetlab/persons/register.php b/planetlab/persons/register.php index c1840be..6232f77 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); +$person_form['site_ids'] = array('title' => 'Site', 'required' => TRUE); if (0) -$form['roles'] = array('title' => 'Additional Roles', 'required' => FALSE); + $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 +$person_form['site_ids']['comment'] = <<< EOF Select the site where you belong EOF; if (0) -$form['roles']['comment'] = <<< EOF + $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]; } @@ -88,29 +94,50 @@ 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 = "
    "; - foreach ($missing as $field) { - $error .= "
  • $field field is required.
  • "; - } - $error .= "
"; + $warnings=array(); + foreach ($missing as $field) $warnings []= "$field field is required."; + print html_div(plc_itemize($warnings),"messages error"); + return FALSE; + } + + // 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)) { - // N.B.: site_ids and roles are ignored by AddPerson() - $person_id = $adm->AddPerson($person); - $error = $adm->error(); - } + return TRUE; +} + +//////////////////// perform api calls +function register_person ($person) { + + global $adm; + + $errors = errors_init (); - if (empty($error)) { + // N.B.: site_ids and roles are ignored by AddPerson() + $person_id = $adm->AddPerson($person); + $errors = errors_record ($adm,$errors); + + if (empty($errors)) { $adm->begin(); // Add person to requested sites @@ -137,18 +164,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 @@ -157,36 +188,31 @@ $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 @@ -213,7 +239,7 @@ function site_option($site) { $selected = ""; } - $option = "
"; +$details -> end(); +$nifty->end(); +print ""; include 'plc_footer.php'; diff --git a/planetlab/sites/site_form.php b/planetlab/sites/site_form.php index bc54821..e77d781 100644 --- a/planetlab/sites/site_form.php +++ b/planetlab/sites/site_form.php @@ -180,16 +180,16 @@ function form_check_required ($form, $input) { // if $outline_missing is set, missing required fields are outlined // fields typed as 'password' are displayed differently // expected to be embedded in a table with 2 columns -function form_render_table2 ($form, $input, $outline_missing) { +function form_render_details ($details, $site_form, $input, $outline_missing) { - foreach ($form as $fullname => $item) { + foreach ($site_form as $fullname => $item) { list($objname,$field) = split(":",$fullname); // render the comment field if ( ! empty($item['comment'])) { - $comment=$item['comment']; - print " $comment "; + $details->space(); + $details->tr ($item['comment'] . ":"); } // compute line attributes @@ -201,10 +201,7 @@ function form_render_table2 ($form, $input, $outline_missing) { } // Label part - print ""; - print << \n -EOF; + $left_part = ""; // input part if ($item['type'] == 'boolean') { @@ -221,25 +218,23 @@ EOF; $checkedyes = ""; $checkedno = "checked='checked'"; } - print <<< EOF - + $right_part = << Yes No -\n EOF; } else { $type = ($item['type'] == 'password') ? "password" : "text"; $value = !empty($input[$objname][$field]) ? $input[$objname][$field] : ""; $maxlength = $item['maxlength']; $size = $item['size']; - print << \n +class="form-text $class" /> EOF; } - print "\n"; + $details->th_td($left_part,$right_part); } } diff --git a/planetlab/sites/switch_site.php b/planetlab/sites/switch_site.php deleted file mode 100644 index b1678ba..0000000 --- a/planetlab/sites/switch_site.php +++ /dev/null @@ -1,73 +0,0 @@ -person; -$_roles= $_person['role_ids']; - - -// if no site id redirect -if( !$_GET['id'] ) - plc_redirect(l_sites()); - -// get site_id -$site_id= $_GET['id']; - -// if submitted -if( $_POST['submitted'] ) { - $new_site= $_POST['new_site']; - - // no primary site anymore.......... - -} - - -// Print header -require_once 'plc_drupal.php'; -drupal_set_title('Sites'); -include 'plc_header.php'; - - -// if admin list all sites, else list just persons sites -if( in_array( '10', $_roles ) ) - $site_info= $api->GetSites( NULL, array( "site_id", "name" ) ); -else - $site_info= $api->GetSites( $_person['site_ids'], array( "site_id", "name" ) ); - - -// start form -echo "\n"; -echo "

Switch Site

\n"; -echo "Change active site to: \n"; -echo "

\n"; -echo "

This will change your Primary Site.\n"; -echo "

\n"; - -echo "

Back to Site\n"; - -echo "\n"; - - - -// Print footer -include 'plc_footer.php'; - -?> diff --git a/planetlab/sites/test.php b/planetlab/sites/test.php deleted file mode 100644 index 87bd436..0000000 --- a/planetlab/sites/test.php +++ /dev/null @@ -1,39 +0,0 @@ -GetSites( array( "name" => $input ), array("name") ); - if (count($sites)) { - foreach ( $sites as $site ) { - $aResults[] = $site['name']; - } - } -} - -header("Content-Type: text/xml"); - -echo " -"; -for ($i=0;$i".$aResults[$i].""; - -echo " - -"; - -?> -- 2.43.0