--- loncom/interface/createaccount.pm 2017/07/26 19:45:45 1.73
+++ loncom/interface/createaccount.pm 2025/02/18 17:45:11 1.90
@@ -4,7 +4,7 @@
# kerberos, or SSO) or an e-mail address. Requests to use an e-mail address as
# username may be processed automatically, or may be queued for approval.
#
-# $Id: createaccount.pm,v 1.73 2017/07/26 19:45:45 raeburn Exp $
+# $Id: createaccount.pm,v 1.90 2025/02/18 17:45:11 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -94,17 +94,24 @@ sub handler {
my $lonhost = $r->dir_config('lonHostID');
my $include = $r->dir_config('lonIncludes');
my $start_page;
+ my $args = {};
+ (undef,undef,undef,my $clientmathml,my $clientunicode) =
+ &Apache::loncommon::decode_user_agent();
+ if ($clientunicode && !$clientmathml) {
+ $args->{'browser.unicode'} = 1;
+ }
my $handle = &Apache::lonnet::check_for_valid_session($r);
if (($handle ne '') && ($handle !~ /^publicuser_\d+$/)) {
$start_page =
- &Apache::loncommon::start_page('Already logged in');
+ &Apache::loncommon::start_page('Already logged in',undef,$args);
my $end_page =
&Apache::loncommon::end_page();
- $r->print($start_page."\n".'
'.&mt('You are already logged in').'
'.
+ $r->print($start_page."\n".''.$end_page);
return OK;
}
@@ -139,7 +146,7 @@ sub handler {
&print_footer($r);
return OK;
} else {
- $start_page = &Apache::loncommon::start_page($title,$js);
+ $start_page = &Apache::loncommon::start_page($title,$js,$args);
&print_header($r,$start_page,$courseid);
$r->print($output);
&print_footer($r);
@@ -150,30 +157,32 @@ sub handler {
my %domconfig =
&Apache::lonnet::get_dom('configuration',['usercreation'],$domain);
my ($cancreate,$statustocreate,$statusforemail,$emailusername,
- $verification,$emaildomain,$types,$usertypes,$othertitle) =
+ $emailoptions,$verification,$emaildomain,$types,$usertypes,$othertitle) =
&get_creation_controls($domain,$domconfig{'usercreation'});
- my ($additems,$pagetitle);
+ my ($pagetitle,$need_affiliation);
if (ref($cancreate) eq 'ARRAY') {
unless (($env{'form.token'}) || ($sso_username ne '') || ($env{'form.phase'}) ||
($env{'form.create_with_email'})) {
if ((grep(/^email$/,@{$cancreate})) && (ref($statusforemail) eq 'ARRAY')) {
my $usertype = &get_usertype($domain);
- if (($usertype ne '') && (grep(/^\Q$usertype\E$/,@{$statusforemail}))) {
- $js .= &username_js();
- } elsif (($usertype eq '') || (!grep(/^\Q$usertype\E$/,@{$statusforemail}))) {
+ if ((($usertype eq '') || (!grep(/^\Q$usertype\E$/,@{$statusforemail}))) &&
+ (@{$statusforemail} > 0)) {
$js .= &setelements_js($statusforemail,$types,$usertypes,$othertitle);
- $additems = {'add_entries' => { 'onload' => "setElements();"} };
- if (@{$cancreate} == 1) {
+ $args->{'add_entries'} = { 'onload' => "setElements();"};
+ if ((@{$cancreate} == 1) && (@{$statusforemail} > 0)) {
$pagetitle = 'Select affiliation';
}
+ $need_affiliation = 1;
+ } else {
+ $js .= &username_js();
}
}
}
}
- $start_page = &Apache::loncommon::start_page($title,$js,$additems);
+ $start_page = &Apache::loncommon::start_page($title,$js,$args);
if (@{$cancreate} == 0) {
&print_header($r,$start_page,$courseid,$pagetitle);
- my $output = ''.&mt('Account creation unavailable').'
'.
+ my $output = ''.&mt('Account creation unavailable').'
'.
''.
&mt('Creation of a new user account using an institutional log-in ID or e-mail verification is not permitted for: [_1].',$domdesc).
'
';
@@ -187,7 +196,7 @@ sub handler {
my ($msg,$sso_logout);
$sso_logout = &sso_logout_frag($r,$domain);
if (grep(/^sso$/,@{$cancreate})) {
- $msg = ''.&mt('Account creation').'
'.
+ $msg = ''.&mt('Account creation').'
'.
&mt("Although your username and password were authenticated by your institution's Single Sign On system, you do not currently have a LON-CAPA account at this institution.").'
';
my $shibenv;
if (($r->dir_config('lonOtherAuthen') eq 'yes') &&
@@ -221,7 +230,7 @@ sub handler {
$lonhost,$contact_email,$contact_name,
$sso_logout,$statustocreate,$shibenv);
} else {
- $msg = ''.&mt('Account creation unavailable').'
'.
+ $msg = ''.&mt('Account creation unavailable').'
'.
''.&mt("Although your username and password were authenticated by your institution's Single Sign On system, you do not currently have a LON-CAPA account at this institution, and you are not permitted to create one.").'
'.&mt('Please contact the [_1] ([_2]) for assistance.',$contact_name,$contact_email).'
'.
$sso_logout;
}
@@ -255,18 +264,32 @@ sub handler {
return OK;
}
}
- my ($usernameset,$condition);
+ my ($usernameset,$condition,$excluded,$hascustom);
if ((grep(/^email$/,@{$cancreate})) && (($env{'form.create_with_email'}) ||
((!$token) && ($env{'form.phase'} eq '')))) {
my $usertype = &get_usertype($domain);
+ if ($usertype eq '') {
+ $usertype = 'default';
+ }
if (ref($verification) eq 'HASH') {
- if ($verification->{$usertype} eq 'other') {
- $usernameset = 1;
+ if ($verification->{$usertype} =~ /^(free|first)$/) {
+ $usernameset = $verification->{$usertype};
+ }
+ }
+ if (ref($emailoptions) eq 'HASH') {
+ if ($emailoptions->{$usertype} =~ /^(inst|noninst)$/) {
+ my $chosen = $1;
if (ref($emaildomain) eq 'HASH') {
- if ($emaildomain->{$usertype} ne '') {
- $condition = $emaildomain->{$usertype};
+ if (ref($emaildomain->{$usertype}) eq 'HASH') {
+ if ($chosen eq 'inst') {
+ $condition = $emaildomain->{$usertype}->{$chosen};
+ } else {
+ $excluded = $emaildomain->{$usertype}->{$chosen};
+ }
}
}
+ } elsif ($emailoptions->{$usertype} eq 'custom') {
+ $hascustom = 1;
}
}
}
@@ -301,16 +324,20 @@ sub handler {
} elsif ($env{'form.create_with_email'}) {
&print_header($r,$start_page,$courseid);
my $usertype = &get_usertype($domain);
+ if ($usertype eq '') {
+ $usertype = 'default';
+ }
$output = &process_email_request($env{'form.uname'},$domain,$domdesc,
$contact_name,$contact_email,$cancreate,
$lonhost,$domconfig{'usercreation'},
$emailusername,$courseid,$usertype,
- $usernameset,$condition);
+ $usernameset,$condition,$excluded,$hascustom);
} elsif (!$token) {
&print_header($r,$start_page,$courseid,$pagetitle);
my $now=time;
- if ((grep(/^login$/,@{$cancreate})) && (!grep(/^email$/,@{$cancreate}))) {
- if (open(my $jsh,"<$include/londes.js")) {
+ if ((grep(/^login$/,@{$cancreate})) &&
+ ((!grep(/^email$/,@{$cancreate})) || ($need_affiliation))) {
+ if (open(my $jsh,"<","$include/londes.js")) {
while(my $line = <$jsh>) {
$r->print($line);
}
@@ -319,13 +346,13 @@ sub handler {
}
}
if (grep(/^email$/,@{$cancreate})) {
- $r->print(&javascript_validmail());
+ $r->print(&javascript_validmail($condition));
}
my $usertype = &get_usertype($domain);
$output = &print_username_form($r,$domain,$domdesc,$cancreate,$now,$lonhost,
$include,$courseid,$emailusername,
$statusforemail,$usernameset,$condition,
- $usertype,$types,$usertypes,$othertitle);
+ $excluded,$usertype,$types,$usertypes,$othertitle);
}
$r->print($output);
&print_footer($r);
@@ -409,7 +436,7 @@ sub selfenroll_crumbs {
}
sub javascript_setforms {
- my ($now,$emailusername,$captcha,$usertype,$recaptchaversion,$usernameset,$condition) = @_;
+ my ($now,$emailusername,$captcha,$usertype,$recaptchaversion,$usernameset,$condition,$excluded) = @_;
my ($setuserinfo,@required,$requiredchk);
if (ref($emailusername) eq 'HASH') {
if (ref($emailusername->{$usertype}) eq 'HASH') {
@@ -419,7 +446,9 @@ sub javascript_setforms {
}
$setuserinfo .= ' server.elements.'.$key.'.value=client.elements.'.$key.'.value;'."\n";
}
- $setuserinfo .= ' server.elements.type.value=client.elements.type.value;'."\n";
+ if ($usertype ne '') {
+ $setuserinfo .= ' server.elements.type.value=client.elements.type.value;'."\n";
+ }
}
if ($captcha eq 'original') {
$setuserinfo .= ' server.elements.code.value=client.elements.code.value;'."\n".
@@ -431,7 +460,7 @@ sub javascript_setforms {
' server.elements.recaptcha_response_field.value=client.elements.recaptcha_response_field.value;'."\n";
}
}
- if ($usernameset) {
+ if ($usernameset eq 'free') {
$setuserinfo .=
' server.elements.username.value=client.elements.username.value;'."\n";
}
@@ -478,10 +507,8 @@ $requiredchk
uextkey=client.elements.uextkey.value;
lextkey=client.elements.lextkey.value;
initkeys();
-
server.elements.upass.value
= getCrypted(client.elements.upass$now.value);
-
client.elements.uname.value='';
client.elements.upass$now.value='';
if (context == 'email') {
@@ -504,10 +531,12 @@ ENDSCRIPT
}
sub javascript_checkpass {
- my ($now,$context) = @_;
+ my ($now,$context,$domain) = @_;
my $nopass = &mt('You must enter a password.');
my $mismatchpass = &mt('The passwords you entered did not match.')."\n".
&mt('Please try again.');
+ my ($numrules,$intargjs) =
+ &Apache::loncommon::passwd_validation_js('upass',$domain);
&js_escape(\$nopass);
&js_escape(\$mismatchpass);
my $js = <<"ENDSCRIPT";
@@ -524,6 +553,10 @@ sub javascript_checkpass {
return false;
}
if (upass == upasscheck) {
+ var numrules = $numrules;
+ if (numrules > 0) {
+$intargjs
+ }
client.elements.upasscheck$now.value='';
if (validate_email(client)) {
send(one,two,'$context');
@@ -543,9 +576,11 @@ ENDSCRIPT
}
sub javascript_validmail {
+ my ($condition) = @_;
my %js_lt = &Apache::lonlocal::texthash (
email => 'The e-mail address you entered',
notv => 'is not a valid e-mail address',
+ avae => 'A valid e-mail address is not formed when the value you entered is combined with the required domain',
);
my $output = "\n".'