00001 <?php
00002
00011 class SSigmaxiAuthModule extends SObject {
00012
00013 private $userName;
00014 private $firstName;
00015 private $lastName;
00016 private $email;
00017 private $userId;
00018 private $role;
00019
00027 public function __construct() {
00028 parent::__construct();
00029 }
00030
00040 public function authenticate($username, $password) {
00041 # Attempt to connect to the SigmaXi database (assuming somebody
00042 # has put the database connection info into the defaults).
00043 $DBI = new DBI( SConfig::getOption('sigmaxi.db_user'),
00044 SConfig::getOption('sigmaxi.db_pass'),
00045 SConfig::getOption('sigmaxi.db_name'),
00046 SConfig::getOption('sigmaxi.db_host'));
00047
00048 # Report any errors connecting, exit
00049 if (count($DBI->getError()) > 0) {
00050 $this->setPrettyError('authenticate', 'Could not connect to SigmaXi database.');
00051 return null;
00052 }
00053
00054 # Query for the specified user.
00055 $query = "SELECT user.UserId, user.UserName, user.FirstName, " .
00056 "user.LastName, user.Email, user.AccountType FROM user WHERE " .
00057 "user.UserName LIKE '" . SWATFunctions::safeSql($username) . "' AND " .
00058 "user.Password = '" . SWATFunctions::safeSql($password) . "' AND " .
00059 "user.active = 'Y';";
00060
00061 $result = $DBI->query($query);
00062
00063 # Report any query errors
00064 if (count($DBI->getError()) > 0) {
00065 $this->setPrettyError('authenticate', $DBI->getError());
00066 return null;
00067 }
00068
00069 # Reject user's credentials if not found in the DB
00070 if (count($result) == 0) return (false);
00071
00072 # Otherwise, set our values from the CSERD DB
00073 $this->userId = ("");
00074 $this->userName = ($result[0]['UserName']);
00075 $this->firstName = ($result[0]['FirstName']);
00076 $this->lastName = ($result[0]['LastName']);
00077 $this->email = ($result[0]['Email']);
00078 $this->role = ("other");
00079
00080 return(true);
00081 }
00082
00090 public function getRole() {
00091 return $this->role;
00092 }
00093
00101 public function getPermissions() {
00102 return false;
00103 }
00104
00112 public function getUID() {
00113 return $this->uid;
00114 }
00115
00123 public function getFirstName() {
00124 return $this->firstName;
00125 }
00126
00134 public function getLastName() {
00135 return $this->lastName;
00136 }
00137
00145 public function getEmail() {
00146 return $this->email;
00147 }
00148
00157 protected function setUID($uid) {
00158 $this->uid = $uid;
00159 }
00160
00169 protected function setUserName($username) {
00170 $this->userName = $username;
00171 }
00172
00181 protected function setEmail($email) {
00182 $this->email = $email;
00183 }
00184
00192 public function __sleep() {
00193 return array_keys(get_object_vars($this));
00194 }
00195
00203 public function __wakeup() {
00204 return array_keys(get_object_vars($this));
00205 }
00206
00207 }
00208
00209 ?>