version 1.40.2.4, 2011/09/29 14:12:21
|
version 1.50, 2012/05/17 18:05:42
|
Line 45 use Crypt::DES;
|
Line 45 use Crypt::DES;
|
use LONCAPA qw(:DEFAULT :match); |
use LONCAPA qw(:DEFAULT :match); |
use HTML::Entities; |
use HTML::Entities; |
|
|
|
#TODO this module needs documentation |
|
|
sub handler { |
sub handler { |
my $r = shift; |
my $r = shift; |
&Apache::loncommon::content_type($r,'text/html'); |
&Apache::loncommon::content_type($r,'text/html'); |
Line 65 sub handler {
|
Line 67 sub handler {
|
if ($sso_username ne '' && $sso_domain ne '') { |
if ($sso_username ne '' && $sso_domain ne '') { |
$domain = $sso_domain; |
$domain = $sso_domain; |
} else { |
} else { |
$domain = &Apache::lonnet::default_login_domain(); |
($domain, undef) = Apache::lonnet::is_course($env{'form.courseid'}); |
if (defined($env{'form.courseid'})) { |
$domain ||= &Apache::lonnet::default_login_domain(); |
if (&validate_course($env{'form.courseid'})) { |
|
if ($env{'form.courseid'} =~ /^($match_domain)_($match_courseid)$/) { |
|
$domain = $1; |
|
} |
|
} |
|
} |
|
} |
} |
my $domdesc = &Apache::lonnet::domain($domain,'description'); |
my $domdesc = &Apache::lonnet::domain($domain,'description'); |
my $contact_name = &mt('LON-CAPA helpdesk'); |
my $contact_name = &mt('LON-CAPA helpdesk'); |
Line 98 sub handler {
|
Line 94 sub handler {
|
} |
} |
|
|
my ($js,$courseid,$title); |
my ($js,$courseid,$title); |
if (defined($env{'form.courseid'})) { |
$courseid = Apache::lonnet::is_course($env{'form.courseid'}); |
$courseid = &validate_course($env{'form.courseid'}); |
|
} |
|
if ($courseid ne '') { |
if ($courseid ne '') { |
$js = &catreturn_js(); |
$js = &catreturn_js(); |
$title = 'Self-enroll in a LON-CAPA course'; |
$title = 'Self-enroll in a LON-CAPA course'; |
Line 128 sub handler {
|
Line 122 sub handler {
|
return OK; |
return OK; |
} else { |
} else { |
$start_page = |
$start_page = |
&Apache::loncommon::start_page($title,$js, |
&Apache::loncommon::start_page($title,$js); |
{'no_inline_link' => 1,}); |
|
&print_header($r,$start_page,$courseid); |
&print_header($r,$start_page,$courseid); |
$r->print($output); |
$r->print($output); |
&print_footer($r); |
&print_footer($r); |
Line 137 sub handler {
|
Line 130 sub handler {
|
} |
} |
} |
} |
$start_page = |
$start_page = |
&Apache::loncommon::start_page($title,$js, |
&Apache::loncommon::start_page($title,$js); |
{'no_inline_link' => 1,}); |
|
my %domconfig = |
my %domconfig = |
&Apache::lonnet::get_dom('configuration',['usercreation'],$domain); |
&Apache::lonnet::get_dom('configuration',['usercreation'],$domain); |
my ($cancreate,$statustocreate) = &get_creation_controls($domain,$domconfig{'usercreation'}); |
my ($cancreate,$statustocreate) = &get_creation_controls($domain,$domconfig{'usercreation'}); |
Line 296 sub selfenroll_crumbs {
|
Line 289 sub selfenroll_crumbs {
|
return; |
return; |
} |
} |
|
|
sub validate_course { |
|
my ($courseid) = @_; |
|
my ($cdom,$cnum) = ($courseid =~ /^($match_domain)_($match_courseid)$/); |
|
if (($cdom ne '') && ($cnum ne '')) { |
|
if (&Apache::lonnet::is_course($cdom,$cnum)) { |
|
return ($courseid); |
|
} |
|
} |
|
return; |
|
} |
|
|
|
sub javascript_setforms { |
sub javascript_setforms { |
my ($now) = @_; |
my ($now) = @_; |
my $js = <<ENDSCRIPT; |
my $js = <<ENDSCRIPT; |
Line 411 sub print_username_form {
|
Line 393 sub print_username_form {
|
} else { |
} else { |
$output .= '<br />'; |
$output .= '<br />'; |
} |
} |
$output .= '<form name="createaccount" method="post" onSubmit="return validate_email()" action="/adm/createaccount">'. |
$output .= '<form name="createaccount" method="post" onsubmit="return validate_email()" action="/adm/createaccount">'. |
&Apache::lonhtmlcommon::start_pick_box()."\n". |
&Apache::lonhtmlcommon::start_pick_box()."\n". |
&Apache::lonhtmlcommon::row_title(&mt('E-mail address'), |
&Apache::lonhtmlcommon::row_title(&mt('E-mail address'), |
'LC_pick_box_title')."\n". |
'LC_pick_box_title')."\n". |
Line 465 sub login_box {
|
Line 447 sub login_box {
|
$output = &serverform($logtoken,$lonhost,undef,$courseid,$context); |
$output = &serverform($logtoken,$lonhost,undef,$courseid,$context); |
my $unameform = '<input type="text" name="uname" size="20" value="" />'; |
my $unameform = '<input type="text" name="uname" size="20" value="" />'; |
my $upassform = '<input type="password" name="upass'.$now.'" size="20" />'; |
my $upassform = '<input type="password" name="upass'.$now.'" size="20" />'; |
$output .= '<form name="client" method="post" onsubmit="return(send());">'."\n". |
$output .= '<form name="client" method="post" action="" onsubmit="return(send());">'."\n". |
&Apache::lonhtmlcommon::start_pick_box()."\n". |
&Apache::lonhtmlcommon::start_pick_box()."\n". |
&Apache::lonhtmlcommon::row_title($titles{$context}, |
&Apache::lonhtmlcommon::row_title($titles{$context}, |
'LC_pick_box_title')."\n". |
'LC_pick_box_title')."\n". |
Line 653 sub process_mailtoken {
|
Line 635 sub process_mailtoken {
|
} else { |
} else { |
$msg .= &mt('An error occurred when sending e-mail to [_1] confirming creation of your LON-CAPA account.',$data{'username'}); |
$msg .= &mt('An error occurred when sending e-mail to [_1] confirming creation of your LON-CAPA account.',$data{'username'}); |
} |
} |
my %form = &start_session($r,$data{'username'},$domain, |
&start_session($r, $data{'username'}, $domain, $lonhost, |
$lonhost,$data{'courseid'}, |
$data{'courseid'}, $token); |
$token); |
|
$nostart = 1; |
$nostart = 1; |
$noend = 1; |
$noend = 1; |
} else { |
} else { |
Line 682 sub process_mailtoken {
|
Line 663 sub process_mailtoken {
|
} |
} |
|
|
sub start_session { |
sub start_session { |
my ($r,$username,$domain,$lonhost,$courseid,$token) = @_; |
my ($r, $username, $domain, $lonhost, $courseid, $token) = @_; |
my %form = ( |
|
uname => $username, |
|
udom => $domain, |
|
); |
|
my $firsturl = '/adm/roles'; |
|
if (defined($courseid)) { |
|
$courseid = &validate_course($courseid); |
|
if ($courseid ne '') { |
|
$form{'courseid'} = $courseid; |
|
$firsturl = '/adm/selfenroll?courseid='.$courseid; |
|
} |
|
} |
|
if ($r->dir_config('lonBalancer') eq 'yes') { |
if ($r->dir_config('lonBalancer') eq 'yes') { |
&Apache::lonauth::success($r,$form{'uname'},$form{'udom'}, |
Apache::lonauth::success($r, $username, $domain, $lonhost, |
$lonhost,'noredirect',undef,\%form); |
'noredirect', undef, {}); |
if ($token ne '') { |
|
my $delete = &Apache::lonnet::tmpdel($token); |
Apache::lonnet::tmpdel($token) if $token; |
} |
|
$r->internal_redirect('/adm/switchserver'); |
$r->internal_redirect('/adm/switchserver'); |
} else { |
} else { |
&Apache::lonauth::success($r,$form{'uname'},$form{'udom'}, |
$courseid = Apache::lonnet::is_course($courseid); |
$lonhost,$firsturl,undef,\%form); |
|
|
Apache::lonauth::success($r, $username, $domain, $lonhost, |
|
($courseid ? "/adm/selfenroll?courseid=$courseid" : '/adm/roles'), |
|
undef, {}); |
} |
} |
return %form; |
|
} |
|
|
|
|
return; |
|
} |
|
|
|
# |
|
# The screen that the user gets to create his or her account |
|
# Desired username, desired password, etc |
|
# Stores token to store DES-key and stage during creation session |
|
# |
sub print_dataentry_form { |
sub print_dataentry_form { |
my ($r,$domain,$lonhost,$include,$mailtoken,$now,$username,$start_page) = @_; |
my ($r,$domain,$lonhost,$include,$mailtoken,$now,$username,$start_page) = @_; |
my ($error,$output); |
my ($error,$output); |
Line 751 ENDSERVERFORM
|
Line 729 ENDSERVERFORM
|
my $upasstwo = '<input type="password" name="upasscheck'.$now.'" size="10" />'; |
my $upasstwo = '<input type="password" name="upasscheck'.$now.'" size="10" />'; |
my $submit_text = &mt('Create LON-CAPA account'); |
my $submit_text = &mt('Create LON-CAPA account'); |
$output .= '<h3>'.&mt('Login Data').'</h3>'."\n". |
$output .= '<h3>'.&mt('Login Data').'</h3>'."\n". |
'<form name="client" method="post" '. |
'<form name="client" method="post" action="" '. |
'onsubmit="return checkpass();">'."\n". |
'onsubmit="return checkpass();">'."\n". |
&Apache::lonhtmlcommon::start_pick_box()."\n". |
&Apache::lonhtmlcommon::start_pick_box()."\n". |
&Apache::lonhtmlcommon::row_title(&mt('Username'), |
&Apache::lonhtmlcommon::row_title(&mt('Username'), |
Line 789 ENDSERVERFORM
|
Line 767 ENDSERVERFORM
|
return $output; |
return $output; |
} |
} |
|
|
|
# |
|
# Retrieve rules for generating accounts from domain configuration |
|
# Can the user make a new account or just self-enroll? |
|
|
sub get_creation_controls { |
sub get_creation_controls { |
my ($domain,$usercreation) = @_; |
my ($domain,$usercreation) = @_; |
my (@cancreate,@statustocreate); |
my (@cancreate,@statustocreate); |
Line 828 sub get_creation_controls {
|
Line 810 sub get_creation_controls {
|
|
|
sub create_account { |
sub create_account { |
my ($r,$domain,$lonhost,$username,$domdesc) = @_; |
my ($r,$domain,$lonhost,$username,$domdesc) = @_; |
|
# Get the token info |
my ($retrieved,$output,$upass) = &process_credentials($env{'form.logtoken'}, |
my ($retrieved,$output,$upass) = &process_credentials($env{'form.logtoken'}, |
$env{'form.serverid'}); |
$env{'form.serverid'}); |
|
# $retrieved is 'ok' if things worked |
|
# $output is user error output |
|
# $upass is the decrypted password |
# Error messages |
# Error messages |
my $error = '<span class="LC_error">'.&mt('Error:').' '; |
my $error = '<span class="LC_error">'.&mt('Error:').' '; |
my $end = '</span><br /><br />'; |
my $end = '</span><br /><br />'; |
Line 838 sub create_account {
|
Line 824 sub create_account {
|
&Apache::loncommon::end_page(); |
&Apache::loncommon::end_page(); |
if ($retrieved eq 'ok') { |
if ($retrieved eq 'ok') { |
if ($env{'form.courseid'} ne '') { |
if ($env{'form.courseid'} ne '') { |
|
# See if we are allowed to use this username per domain rules (number of characters, etc) |
my ($result,$userchkmsg) = &check_id($username,$domain,$domdesc); |
my ($result,$userchkmsg) = &check_id($username,$domain,$domdesc); |
if ($result eq 'fail') { |
if ($result eq 'fail') { |
$output = $error.&mt('Invalid ID format').$end. |
$output = $error.&mt('Invalid ID format').$end. |
Line 848 sub create_account {
|
Line 835 sub create_account {
|
} else { |
} else { |
return ('fail',$error.$output.$end.$rtnlink); |
return ('fail',$error.$output.$end.$rtnlink); |
} |
} |
# Call modifyuser |
# Yes! We can do this. Valid token, valid username format |
|
# Create an internally authenticated account with password $upass |
|
# if the account does not exist yet |
|
# Assign student/staff number $env{'form.cid'}, first name, last name, etc |
my $result = |
my $result = |
&Apache::lonnet::modifyuser($domain,$username,$env{'form.cid'}, |
&Apache::lonnet::modifyuser($domain,$username,$env{'form.cid'}, |
'internal',$upass,$env{'form.cfirstname'}, |
'internal',$upass,$env{'form.cfirstname'}, |
$env{'form.cmiddlename'},$env{'form.clastname'}, |
$env{'form.cmiddlename'},$env{'form.clastname'}, |
$env{'form.cgeneration'},undef,undef,$username); |
$env{'form.cgeneration'},undef,undef,$username); |
$output = &mt('Generating user: [_1]',$result); |
$output = &mt('Generating user: [_1]',$result); |
|
# Now that the user exists, we can have a homeserver |
my $uhome = &Apache::lonnet::homeserver($username,$domain); |
my $uhome = &Apache::lonnet::homeserver($username,$domain); |
$output .= '<br />'.&mt('Home server: [_1]',$uhome).' '. |
$output .= '<br />'.&mt('Home server: [_1]',$uhome).' '. |
&Apache::lonnet::hostname($uhome).'<br /><br />'; |
&Apache::lonnet::hostname($uhome).'<br /><br />'; |
Line 864 sub create_account {
|
Line 855 sub create_account {
|
sub username_validation { |
sub username_validation { |
my ($r,$username,$domain,$domdesc,$contact_name,$contact_email,$courseid, |
my ($r,$username,$domain,$domdesc,$contact_name,$contact_email,$courseid, |
$lonhost,$statustocreate) = @_; |
$lonhost,$statustocreate) = @_; |
|
# $username,$domain: for the user who needs to be validated |
|
# $domdesc: full name of the domain (for error messages) |
|
# $contact_name, $contact_email: name and email for user assistance (for error messages in &username_check |
|
# $courseid: ID of the course that the user should be validated for, goes into start_session |
|
# $statustocreate: -> inststatus in username_check ('faculty', 'staff', 'student', ...) |
|
|
my ($retrieved,$output,$upass); |
my ($retrieved,$output,$upass); |
|
|
$username= &LONCAPA::clean_username($username); |
$username= &LONCAPA::clean_username($username); |
Line 878 sub username_validation {
|
Line 875 sub username_validation {
|
if ($uhome ne 'no_host') { |
if ($uhome ne 'no_host') { |
my $result = &Apache::lonnet::authenticate($username,$upass,$domain); |
my $result = &Apache::lonnet::authenticate($username,$upass,$domain); |
if ($result ne 'no_host') { |
if ($result ne 'no_host') { |
my %form = &start_session($r,$username,$domain,$lonhost,$courseid); |
&start_session($r, $username, $domain, $lonhost, $courseid); |
$output = '<br /><br />'.&mt('A LON-CAPA account already exists for username [_1] at this institution ([_2]).','<tt>'.$username.'</tt>',$domdesc).'<br />'.&mt('The password entered was also correct so you have been logged in.'); |
$output = '<br /><br />'.&mt('A LON-CAPA account already exists for username [_1] at this institution ([_2]).','<tt>'.$username.'</tt>',$domdesc).'<br />'.&mt('The password entered was also correct so you have been logged in.'); |
return ('existingaccount',$output); |
return ('existingaccount',$output); |
} else { |
} else { |
Line 1102 sub username_activation {
|
Line 1099 sub username_activation {
|
if ($result eq 'ok') { |
if ($result eq 'ok') { |
my $delete = &Apache::lonnet::tmpdel($env{'form.authtoken'}); |
my $delete = &Apache::lonnet::tmpdel($env{'form.authtoken'}); |
$output = &mt('A LON-CAPA account has been created for username: [_1] in domain: [_2].',$username,$domain); |
$output = &mt('A LON-CAPA account has been created for username: [_1] in domain: [_2].',$username,$domain); |
my %form = &start_session($r,$username,$domain,$lonhost,$courseid); |
&start_session($r, $username, $domain, $lonhost, $courseid); |
my $nostart = 1; |
my $nostart = 1; |
return ('ok',$output,$nostart); |
return ('ok',$output,$nostart); |
} else { |
} else { |
Line 1118 sub username_activation {
|
Line 1115 sub username_activation {
|
sub check_id { |
sub check_id { |
my ($username,$domain,$domdesc) = @_; |
my ($username,$domain,$domdesc) = @_; |
# Check ID format |
# Check ID format |
|
# Is $username in an okay format for $domain |
|
# (right number of characters, special characters, etc - follow domain rules)? |
|
# $domdesc is just used for user error messages |
my (%alerts,%rulematch,%inst_results,%curr_rules,%checkhash); |
my (%alerts,%rulematch,%inst_results,%curr_rules,%checkhash); |
my %checks = ('id' => 1); |
my %checks = ('id' => 1); |
%{$checkhash{$username.':'.$domain}} = ( |
%{$checkhash{$username.':'.$domain}} = ( |
Line 1256 ENDSERVERFORM
|
Line 1256 ENDSERVERFORM
|
} |
} |
|
|
sub process_credentials { |
sub process_credentials { |
|
# |
|
# Fetches the information from the logtoken via tmpget |
|
# Token contains the DES-key and the stage of the process (would only be "createaccount") |
|
# $lonhost in this routine is *not* necessarily the machine that this runs on, |
|
# but $env{'form.serverid'}, the machine that issued the token. |
|
# |
my ($logtoken,$lonhost) = @_; |
my ($logtoken,$lonhost) = @_; |
my $tmpinfo=Apache::lonnet::reply('tmpget:'.$logtoken,$lonhost); |
my $tmpinfo=Apache::lonnet::reply('tmpget:'.$logtoken,$lonhost); |
my ($retrieved,$output,$upass); |
my ($retrieved,$output,$upass); |
Line 1277 sub process_credentials {
|
Line 1283 sub process_credentials {
|
} else { |
} else { |
$output = &mt('Unable to retrieve your log-in information - unexpected context'); |
$output = &mt('Unable to retrieve your log-in information - unexpected context'); |
} |
} |
|
# $retrieved is 'ok' if retrieved okay |
|
# $output is screen output for the user |
|
# $upass is $env{'form.upass'}, decrypted with the DES-key, if stage was 'createaccount' |
|
|
return ($retrieved,$output,$upass); |
return ($retrieved,$output,$upass); |
} |
} |
|
|