Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions CASAuth.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ function casLogin($user, &$result) {

// Get username
$username = casNameLookup(phpCAS::getUser());
$email = casEmailLookup(phpCAS::getUser());

// If we are restricting users AND the user is not in
// the allowed users list, lets block the login
Expand All @@ -127,9 +126,12 @@ function casLogin($user, &$result) {

// Create a new account if the user does not exists
if ($u->getID() == 0 && $CASAuth["CreateAccounts"]) {
//Get email and realname
$realname = casRealNameLookup(phpCAS::getUser());
$email = casEmailLookup(phpCAS::getUser());
// Create the user
$u->addToDatabase();
$u->setRealName($username);
$u->setRealName($realname);
$u->setEmail($email);
// PwdSecret is used to salt the username, which is
// then used to create an md5 hash which becomes the
Expand Down
65 changes: 65 additions & 0 deletions CASAuthSettings.php.template
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,14 @@ function casNameLookup($username) {
return $username;
}

# If you dont like the uid that CAS returns (ie. it returns a number) you can
# modify the routine below to return a customized real name instead.
#
# Default: Returns the username, untouched
function casRealNameLookup($username) {
return $username;
}

# If your users aren't all on the same email domain you can
# modify the routine below to return their email address
#
Expand All @@ -104,3 +112,60 @@ function casEmailLookup($username) {
return $username."@".$CASAuth["EmailDomain"];
}

/*
#Below is a couple of implementations of casRealNameLookup and casEmailLookup
#that will fetch user details in a separate DB based on the CAS username

global $casUserData;
$casUserData=array();

#Queries the DB and caches the result in memory
function casFetchUserData($username) {
global $casUserData;
if(isset($casUserData[$username]))
return $casUserData[$username];
## Please customize connection params to your needs
$dbh = mysqli_connect('host', 'user', 'pass', 'base')
or die("unable to contact CAS user database");
if(!$dbh || $dbh->connect_error)
die("CAS database error : $dbh->connect_errno: $dbh->connect_error");
## Please customize query to your needs keeping aliases
$SQL = 'SELECT x as realname, y as email FROM table WHERE userid=?';
$stmt=$dbh->prepare($SQL)
or die("unable to prepare CAS user database request");
$stmt->bind_param("s", $username);
$stmt->execute()
or die("unable to execute CAS user database request");
$stmt->bind_result($realname,$email);
$stmt->fetch()
or die("unable to fetch assoc CAS user database request");
$data = array(
"realname"=>$realname,
"email"=>$email,
);
$stmt->close();
$dbh->close();
$casUserData[$username] = $data;
return $data;
}

# If you dont like the uid that CAS returns (ie. it returns a number) you can
# modify the routine below to return a customized username instead.
#
# Default: Returns the username, untouched
function casNameLookup($username) {
return $username;
}

# Returns the "realname" field of the query
function casRealNameLookup($username) {
$tmp=casFetchUserData($username);
return $tmp['realname'];
}

# Returns the "email" field of the query
function casEmailLookup($username) {
$tmp=casFetchUserData($username);
return $tmp['email'];
}