⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 registerform.pm

📁 一个论文管理系统
💻 PM
字号:
# $Id: RegisterForm.pm,v 1.19 2005/11/01 23:23:18 martin Exp $## Copyright 2005 Nature Publishing Group# This program is free software; you can redistribute it and/or# modify it under the terms of the GNU General Public License# as published by the Free Software Foundation; either version 2# of the License, or (at your option) any later version.## The Bibliotech::Component::RegisterForm class provides a registration form.package Bibliotech::Component::RegisterForm;use strict;use base 'Bibliotech::Component';use URI::Heuristic qw(uf_uristr);sub last_updated_basis {  ('NOW');  # not an oft-used page, just always load exactly correct registration details}sub html_content {  my ($self, $class, $verbose, $main) = @_;  my $bibliotech = $self->bibliotech;  my $cgi = $bibliotech->cgi;  my $user = $bibliotech->user;  my $user_id = defined $user ? $user->user_id : undef;  $bibliotech->last_modified_no_cache;  # tell AOL etc to always reload  # parameter cleaning - need this to keep utf-8 output from messing up on a reload  foreach (qw/username password password2 firstname lastname email openurl_resolver openurl_name/) {    my $value = $self->cleanparam($cgi->param($_));    $cgi->param($_ => $value) if $value;  }  my $validationmsg;  my $button = $cgi->param('button');  if ($button =~ /^(Register|Update)$/) {    my $o;    eval {      die "You cannot update if you are not logged in.\n" if $button eq 'Update' and !defined($user);      my $username = $cgi->param('username');      my $password = $cgi->param('password');      my $password2 = $cgi->param('password2');      my $firstname = $cgi->param('firstname');      my $lastname = $cgi->param('lastname');      my $email = $cgi->param('email');      my $openurl_resolver = $cgi->param('openurl_resolver');      $openurl_resolver = undef if $openurl_resolver eq 'http://';      my $openurl_name = $cgi->param('openurl_name');      $self->validate_username($username) if $button eq 'Register';      $self->validate_password($password, $password2);      $self->validate_firstname($firstname);      $self->validate_lastname($lastname);      $self->validate_email($email);      $self->validate_openurl($openurl_resolver, $openurl_name, sub { $cgi->param(openurl_resolver => $_[0]); });      if ($button eq 'Register') {	$bibliotech->new_user($username, $password, $firstname, $lastname, $email, $openurl_resolver, $openurl_name);	$o = $cgi->p('Thank you! Please check your email for a verification link.');      }      else {	$bibliotech->update_user($user_id, $password, $firstname, $lastname, $email, $openurl_resolver, $openurl_name);	$o = $cgi->p('Thank you! Your account has been updated.');      }    };    if ($@) {      die $@ if $@ =~ /at .* line \d+/;      $validationmsg = $@;    }    else {      return Bibliotech::Page::HTML_Content->simple($o);    }  }  if ($user and !$validationmsg) {    my %user = $bibliotech->load_user($user->user_id);    $cgi->param($_ => $user{$_}) foreach (keys %user);    $cgi->param(password2 => $user{password});  }  my $o = $cgi->h1(!$user ? 'Register' : 'Edit registration details');  unless ($user) {    $o .= $cgi->p({-class => 'welcome'}, 'Welcome to Connotea, a free online reference management service for scientists.');    $o .= $cgi->p({-class => 'welcome'}, 'After signing up for an account, only your username will be publically viewable; all other information will be kept private and will not be passed on to third parties without your permission.');      $o .= $cgi->p({-class => 'welcome'}, 'As part of the registration process we will send you an email containing a link that you\'ll need to click in order to verify your account, so please use a valid email address.  We will only use that address to contact you about your account.');      }  else {    $o .= $cgi->p({class => 'welcome'}, 'Here are your current account details. Edit any item and click \'Update\' to save the changes.');  }  $o .= $cgi->div({class => 'errormsg'}, $validationmsg) if $validationmsg;  $o .= $cgi->br;  $o .= $cgi->start_form(-method => 'POST', -action => $bibliotech->location.'register', -name => 'register');  if ($user) {    $o .= $cgi->p({-class => 'welcome'}, 'Details for '.$cgi->strong($cgi->param('username')).':'.$cgi->hidden('username'));  }  else {    $o .= $cgi->span({-class => 'label'}, 'Username:');    $o .= $cgi->br;    $o .= $cgi->textfield(-id => 'usernamebox', -class => 'textctl', -name => 'username', -size => 20, -maxlength => 40);  }  $o .= $cgi->br;  $o .= $cgi->span({-class => 'label'}, 'Password:');  $o .= $cgi->br;  $o .= $cgi->password_field(-id => 'passwordbox', -class => 'textctl', -name => 'password', -size => 20, -maxlength => 40);  $o .= $cgi->br;  $o .= $cgi->span({-class => 'label'}, 'Confirm Password:');  $o .= $cgi->br;  $o .= $cgi->password_field(-id => 'passwordbox2', -class => 'textctl', -name => 'password2', -size => 20, -maxlength => 40);  $o .= $cgi->br;  $o .= $cgi->span({-class => 'label'}, 'First name:');  $o .= $cgi->br;  $o .= $cgi->textfield(-id => 'firstnamebox', -class => 'textctl', -name => 'firstname', -size => 20, -maxlength => 40);  $o .= $cgi->br;  $o .= $cgi->span({-class => 'label'}, 'Last name:');  $o .= $cgi->br;  $o .= $cgi->textfield(-id => 'lastnamebox', -class => 'textctl', -name => 'lastname', -size => 20, -maxlength => 40);  $o .= $cgi->br;  $o .= $cgi->span({-class => 'label'}, 'Email address:');  $o .= $cgi->br;  $o .= $cgi->textfield(-id => 'emailbox', -class => 'textctl', -name => 'email', -size => 20, -maxlength => 255);  $o .= $cgi->br;  $o .= $cgi->br;  #don't use cgi as some browsers don't like a self closing a tag, and spill style information over.  $o .= '<a name="openurldetails"></a>';  $o .= $cgi->p({-class => 'welcome'}, 'If you have access to an OpenURL resolver, please enter its location here.  Connotea will then generate OpenURL links for the items in your library wherever possible.  '.$cgi->a({-href => "guide#openurl"}, $cgi->img({-src => 'help_button.gif', -title => 'What is this?', -alt => '?', -class => "helpicon"} )));  $o .= $cgi->br;  $o .= $cgi->span({-class => 'label'}, 'OpenURL resolver location:');  $o .= $cgi->br;  $o .= $cgi->textfield(-id => 'openurl_resolverbox', -class => 'textctl', -name => 'openurl_resolver', -default => 'http://', -size => 20, -maxlength => 255);  $o .= $cgi->br;  $o .= $cgi->span({-class => 'label'}, 'Label to use for your OpenURL links:');  $o .= $cgi->br;  $o .= $cgi->textfield(-id => 'openurl_namebox', -class => 'textctl', -name => 'openurl_name', -default => 'OpenURL', -size => 20, -maxlength => 20);  $o .= $cgi->br;  $o .= $cgi->br;  $o .= $cgi->submit(-id => 'registerbutton', -class => 'buttonctl', -name => 'button', -value => $user_id ? 'Update' : 'Register');  $o .= $cgi->end_form;  my $javascript_first_empty = $self->firstempty($cgi, 'register', qw/username password password2 firstname lastname email/);  return new Bibliotech::Page::HTML_Content({html_parts => {main => $o},					     javascript_onload => ($main ? $javascript_first_empty : undef)});}sub validate_username {  my ($self, $username) = @_;  $username      or die "You must select a username.\n";  length $username >= 3      or die "Your username must be at least 3 characters long.\n";  length $username <=      40 or die "Your username must be no more than 40 characters long.\n";  $username =~ /^\w+$/      or die "Your username must be composed of alphanumeric characters only (a-z,0-9).\n";  $username !~ /^\d/      or die "Your username may not start with a digit.\n";  return 1;}sub validate_password {  my ($self, $password, $password2) = @_;  $password      or die "You must select a password.\n";  length $password >= 4      or die "Your password must be at least 4 characters long.\n";  length $password <= 40      or die "Your password must be no more than 40 characters long.\n";  $password2      or die "Please re-enter your password in the second text field for verification.\n";  $password eq $password2      or die "The passwords do not match.\n";  return 1;}sub validate_firstname {  my ($self, $firstname) = @_;  $firstname      or die "You must provide your first name.\n";  length $firstname <= 40      or die "Your first name must be no more than 40 characters long.\n";  return 1;}sub validate_lastname {  my ($self, $lastname) = @_;  $lastname      or die "You must provide your last name.\n";  length $lastname <= 40      or die "Your last name must be no more than 40 characters long.\n";  return 1;}sub validate_email {  my ($self, $email) = @_;  $email      or die "You must provide a working email address.\n";  length $email <= 40      or die "Your email address must be no more than 40 characters long.\n";  $email =~ /^.+\@.+$/      or die "Invalid email address format.\n";  return 1;}sub validate_openurl {  my ($self, $uri, $name, $suggestion_callback) = @_;  return 1 if !$uri;  length $uri <= 255      or die "Your OpenURL resolver address must be no more than 255 characters long.\n";  my $uri_obj = new URI ($uri);  unless ($uri_obj->scheme =~ /^https?$/) {    my $suggestion = uf_uristr($uri_obj);    die "Sorry, please use an http or https scheme for your OpenURL resolver address.\n" if !$suggestion or $suggestion eq $uri_obj;    $suggestion_callback->($suggestion) if defined $suggestion_callback;    die "The OpenURL resolver location you have entered doesn't look like a full URL. Perhaps you meant:<br />$suggestion<br />If so, please click Update.  If not, please edit the location, making sure you include http or https.\n";  }  $uri_obj->host      or die "Sorry, your OpenURL resolver address appears to have no host name.\n";  return 1;}1;__END__

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -