WeBWorK Main Forum

Change login name to First_name and Last_name?

Change login name to First_name and Last_name?

by Steven Xiao -
Number of replies: 4
For many years, we have been using student IDs as the login name in webwork. For instructors, we just assigned some unique login name ( typically their email account name.) It had been working fine. Every time when a user logs into the webwork system, the user login name would be displayed on the top-right corner, right before the "Log Out" button. (See the red mark on the attached picture. It showed that when admin logged in, it showed as "Logged in as admin").

Recently, we switched to Shibboleth authentication. Since the authentication server is university wide. All the students, Professors and Staff are on that same server. So we will have to switch to a unique ID for the people inside our university. (They call that peopleID in our Shibboleth system. And we can not use student ID or Employee ID any more since they are not unique, may overlap.) The problem with peopleID is that no one actually uses that ID except that they are used as the unique identifier inside the university wide systems. In other words, the end user does not actually know that ID (even their own peopleID). So that ID does not make too much sense to the end users.

Right now for our webwork system, after a user authenticated through the Shibboleth system, the webwork would show as "Logged in as 232123141231" where the long weird number is his peopleID in our university which looks really strange to the user since he may have never seen that number before.

I am thinking that it would make more sense to show the user's full name ( first_name + last_name ) there instead of the peopleID.

I searched around for some time. It seems to me that in the file
/opt/webwork/webwork2/lib/WeBWorK/ContentGenerator.pm
I found this piece of code

my $userID = $r->param("user");
...
print $r->maketext("Logged in as [_1]. ", HTML::Entities::encode_entities($userID)) . CGI::a({href=>$logoutURL}, $r->maketext("Log Out"));

which I think maybe relevant.

My guess is that maybe I can change the $userID to something like $userFullName then I am done.

For user login name, it seems that it got it from my $userID = $r->param("user");. But I did not see how I can get the first_name and the last_name of a logged in user.

Can someone help here? Am I in the right direction? Or can we customize the user interface, say, from localOverride.conf or some other configuration files?

Thanks,

Steven



Attachment webworkDisplayedLoginName.jpg
In reply to Steven Xiao

Re: Change login name to First_name and Last_name?

by Alex Jordan -
I know this is skirting your question, but can you use email prefix instead of this peopleID? There is some guarantee of uniqueness there. For instance, I'm alex.jordan, from alex.jordan@pcc.edu, but there may be students with ID alex.jordan1, or alex.jordan15. They are used to the numbers at the end of their IDs for other purposes, so it's not a big deal to go there with WeBWorK too.


In reply to Alex Jordan

Re: Change login name to First_name and Last_name?

by Steven Xiao -
Thanks for the fast reply, Alex.

Yes, the email prefix is a better solution. At least it is better than the weird peopleID.

The reasons why we are using the peopleID are:
1) The team who maintain the Shibsoleth server told us so and they said that all other university wide systems are using that one.
2) Right now, for students emails, they are on @go.wustl.edu while for employees they are on @email.wustl.edu. They are in the process to merge those two addresses. Not sure what would happen to the email prefixes.

Interesting enough, I dug a little bit more this morning and it seems to me that I got what I wanted.

What I did was: change the /opt/webwork/webwork2/lib/WeBWorK/ContentGenerator.pm a little bit: (The pink parts are either added or modified).

**************************************START HERE************************************
sub loginstatus {
my ($self) = @_;
my $r = $self->r;
my $authen = $r->authen;
my $urlpath = $r->urlpath;
# Steven Xiao
# May 6, 2015
#
my $db = $r->db;

#This will contain any extra parameters which are needed to make
# the page function properly. This will normally be empty.
my $extraStopActingParams = $r->{extraStopActingParams};

if ($authen and $authen->was_verified) {
my $courseID = $urlpath->arg("courseID");
my $userID = $r->param("user");
# Steven Xiao
# May 6, 2015
my $UserRecord = $db->getUser($userID);
my $userName = $UserRecord->first_name . " " . $UserRecord->last_name;


my $eUserID = $r->param("effectiveUser");

$extraStopActingParams->{effectiveUser} = $userID;
my $stopActingURL = $self->systemLink($urlpath, # current path
params=>$extraStopActingParams);
my $logoutURL = $self->systemLink($urlpath->newFromModule(__PACKAGE__ . "::Logout", $r, courseID => $courseID));

if ($eUserID eq $userID) {
# print $r->maketext("Logged in as [_1]. ", HTML::Entities::encode_entities($userID)) . CGI::a({href=>$logoutURL}, $r->maketext("Log Out"));
print $r->maketext("Logged in as [_1]. ", HTML::Entities::encode_entities($userName)) . CGI::a({href=>$logoutURL}, $r->maketext("Log Out"));
} else {
print $r->maketext("Logged in as [_1]. ", HTML::Entities::encode_entities($userID)) . CGI::a({href=>$logoutURL}, $r->maketext("Log Out"));
print CGI::br();
print $r->maketext("Acting as [_1]. ", HTML::Entities::encode_entities($eUserID)) . CGI::a({href=>$stopActingURL}, $r->maketext("Stop Acting"));
}
} else {
print $r->maketext("Not logged in.");
}

return "";
}
***************************END HERE***************************************

Can anyone confirm that there would not be any side effects of this change?

Thanks,

Steven
In reply to Steven Xiao

Re: Change login name to First_name and Last_name?

by Steven Xiao -
It seems that I post too fast:
It seems that there should be at least a couple of more changes:

**************************************START HERE************************************
sub loginstatus {
my ($self) = @_;
my $r = $self->r;
my $authen = $r->authen;
my $urlpath = $r->urlpath;
# Steven Xiao
# May 6, 2015
#
my $db = $r->db;

#This will contain any extra parameters which are needed to make
# the page function properly. This will normally be empty.
my $extraStopActingParams = $r->{extraStopActingParams};

if ($authen and $authen->was_verified) {
my $courseID = $urlpath->arg("courseID");
my $userID = $r->param("user");
# Steven Xiao
# May 6, 2015
my $UserRecord = $db->getUser($userID);
my $userName = $UserRecord->first_name . " " . $UserRecord->last_name;


my $eUserID = $r->param("effectiveUser");

my $eUserRecord = $db->getUser($eUserID);
my $euserName = $eUserRecord->first_name . " " . $eUserRecord->last_name;

$extraStopActingParams->{effectiveUser} = $userID;
my $stopActingURL = $self->systemLink($urlpath, # current path
params=>$extraStopActingParams);
my $logoutURL = $self->systemLink($urlpath->newFromModule(__PACKAGE__ . "::Logout", $r, courseID => $courseID));

if ($eUserID eq $userID) {
# print $r->maketext("Logged in as [_1]. ", HTML::Entities::encode_entities($userID)) . CGI::a({href=>$logoutURL}, $r->maketext("Log Out"));
print $r->maketext("Logged in as [_1]. ", HTML::Entities::encode_entities($userName)) . CGI::a({href=>$logoutURL}, $r->maketext("Log Out"));
} else {
print $r->maketext("Logged in as [_1]. ", HTML::Entities::encode_entities($userName)) . CGI::a({href=>$logoutURL}, $r->maketext("Log Out"));
print CGI::br();
print $r->maketext("Acting as [_1]. ", HTML::Entities::encode_entities($euserName)) . CGI::a({href=>$stopActingURL}, $r->maketext("Stop Acting"));
}
} else {
print $r->maketext("Not logged in.");
}

return "";
}
***************************END HERE***************************************


Not sure if more changes are needed.
In reply to Steven Xiao

Re: Change login name to First_name and Last_name?

by Michael Gage -
This looks fine if it does what you want.

The difference between effectiveUser and user is this:

effectiveUser is the person that the homework problem was created for 

the user is the person currently viewing the problem.  Usually the user would be the same as the user, however if an instructor "acts as" a student and views the student's question then the user would be the instructor while the effectiveUser is still the student.