Last change
on this file since 303 was
303,
checked in by hendrikvanantwerpen, 13 years ago
|
[Server] Refactored model classes with some meta-programming. Specific classes only define their fields and inherit from class RdfObject?. Changes to handle the new model objects correctly.
[Client] Added rft/store module for uniform resource access. Removed dependencies on 'uid' field name. Added support for references without loading full object nor exposing uri.
[Client] Added reset() to QuestionWidget?.
[RDFAPI] Fixed PHP warning.
|
File size:
1.2 KB
|
Rev | Line | |
---|
[256] | 1 | <?php |
---|
| 2 | |
---|
| 3 | require_once 'master.php'; |
---|
| 4 | |
---|
| 5 | class Auth { |
---|
| 6 | |
---|
[274] | 7 | public static function register($email, $password) { |
---|
| 8 | $user_results = User::get(array("email" => $email)); |
---|
[303] | 9 | if (!empty($user_results)) { |
---|
[274] | 10 | throw new Exception("User with email $email already exists."); |
---|
[256] | 11 | } |
---|
[274] | 12 | $salt = rand(); |
---|
[303] | 13 | $user = new User(null, array( |
---|
| 14 | 'email' => $email, |
---|
| 15 | 'passwordHash' => sha1($password . $salt), |
---|
| 16 | 'passwordSalt' => $salt)); |
---|
[274] | 17 | $user->save(); |
---|
| 18 | return $user; |
---|
[256] | 19 | } |
---|
[303] | 20 | |
---|
[274] | 21 | public static function login($email, $password) { |
---|
| 22 | $user_results = User::get(array("email" => $email)); |
---|
| 23 | if (empty($user_results)) { |
---|
| 24 | throw new Exception("User with email $email not found."); |
---|
| 25 | } |
---|
| 26 | $user = $user_results[0]; |
---|
[303] | 27 | if (sha1($password . $user->passwordSalt) != $user->passwordHash) { |
---|
[274] | 28 | throw new Exception("Wrong password."); |
---|
| 29 | } |
---|
| 30 | return $user; |
---|
| 31 | } |
---|
[256] | 32 | |
---|
| 33 | public static function restore($session) { |
---|
| 34 | $user_results = User::get(array("uid" => $session)); |
---|
[274] | 35 | if (empty($user_results)) { |
---|
| 36 | throw new Exception("Session with id $session not found."); |
---|
[256] | 37 | } |
---|
[274] | 38 | return $user_results[0]; |
---|
[256] | 39 | } |
---|
[303] | 40 | |
---|
[256] | 41 | } |
---|
| 42 | |
---|
| 43 | ?> |
---|
Note: See
TracBrowser
for help on using the repository browser.