From 7b17223904214024018f626715926fa729941d3c Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Wed, 4 Mar 2015 18:43:06 +0100 Subject: Fourth Commit --- inc/crypto.inc.php | 29 +++++++++++++++++++++++++++++ inc/user.inc.php | 43 +++++++++++++++++++++++++++++++++++++++---- 2 files changed, 68 insertions(+), 4 deletions(-) create mode 100644 inc/crypto.inc.php (limited to 'inc') diff --git a/inc/crypto.inc.php b/inc/crypto.inc.php new file mode 100644 index 0000000..56f5073 --- /dev/null +++ b/inc/crypto.inc.php @@ -0,0 +1,29 @@ + Session::getUid())); - return self::$user !== false; + self::$user = Database::queryFirst('SELECT userid, shibid, login, organizationid AS organization, firstname, lastname, email FROM user WHERE userid = :uid LIMIT 1', array('uid' => Session::getUid())); + self::$isInDb = self::$user !== false; + return self::$isInDb; } // Try bwIDM etc. if (!$hasSession) { @@ -190,12 +198,35 @@ class User } } + public static function updatePassword($pass) + { + if (!self::isLoggedIn() || self::$isShib || !self::$isInDb) + return false; + $pw = Crypto::hash6($pass); + $ret = Database::exec('UPDATE user SET password = :pass WHERE userid = :user LIMIT 1', array( + 'pass' => $pw, + 'user' => self::getId() + )); + return $ret == 1; + } + + + public static function updateMail($mail) + { + if (!self::isLoggedIn() || self::$isShib || !self::$isInDb) + return false; + $ret = Database::exec('UPDATE user SET email = :mail WHERE userid = :user LIMIT 1', array( + 'mail' => $mail, + 'user' => self::getId() + )); + return $ret == 1 || $mail === self::get('email'); + } public static function login($user, $pass) { $ret = Database::queryFirst('SELECT userid, password FROM user WHERE login = :user LIMIT 1', array(':user' => $user)); if ($ret === false) return false; - if (!Crypto::verify($pass, $ret['passwd'])) + if (!Crypto::verify($pass, $ret['password'])) return false; Session::create(); Session::setUid($ret['userid']); @@ -212,7 +243,11 @@ class User @setcookie($name, '', time() - 8640000, null, null, !empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off', true); } Session::delete(); - Header('Location: ?do=Logout&noredirect=yes'); + if (self::$isShib) { + Header('Location: ?do=Logout&noredirect=yes'); + } else { + Header('Location: ?do=Main'); + } exit(0); } -- cgit v1.2.3-55-g7522