Last change
on this file since 274 was
274,
checked in by hendrikvanantwerpen, 13 years ago
|
- [Client] Moved pages in subtree of rft/, allowing controllers next to them.
- [Client] Created questions page, gives overview and allows adding.
- [Client] Page controllers inherit from _Page, because the previous mechanism w
asn't working.
- [Client] Added new user registration.
- [Server] Changed user passwords to passwordHash/passwordSalt combination.
- [Server] Added simple object marshalling and unmarshalling to preserve types.
- [Server] Added ResearchToolObjectInterface? with static create() method. Implemented for all model classes.
|
File size:
1.1 KB
|
Line | |
---|
1 | <?php |
---|
2 | |
---|
3 | require_once 'master.php'; |
---|
4 | |
---|
5 | class Auth { |
---|
6 | |
---|
7 | public static function register($email, $password) { |
---|
8 | $user_results = User::get(array("email" => $email)); |
---|
9 | if ( !empty($user_results) ) { |
---|
10 | throw new Exception("User with email $email already exists."); |
---|
11 | } |
---|
12 | $salt = rand(); |
---|
13 | $user = new User(null,$email,sha1($password.$salt),$salt); |
---|
14 | $user->save(); |
---|
15 | return $user; |
---|
16 | } |
---|
17 | |
---|
18 | public static function login($email, $password) { |
---|
19 | $user_results = User::get(array("email" => $email)); |
---|
20 | if (empty($user_results)) { |
---|
21 | throw new Exception("User with email $email not found."); |
---|
22 | } |
---|
23 | $user = $user_results[0]; |
---|
24 | if (sha1($password.$user->passwordSalt) != $user->passwordHash) { |
---|
25 | throw new Exception("Wrong password."); |
---|
26 | } |
---|
27 | return $user; |
---|
28 | } |
---|
29 | |
---|
30 | public static function restore($session) { |
---|
31 | $user_results = User::get(array("uid" => $session)); |
---|
32 | if (empty($user_results)) { |
---|
33 | throw new Exception("Session with id $session not found."); |
---|
34 | } |
---|
35 | return $user_results[0]; |
---|
36 | } |
---|
37 | |
---|
38 | } |
---|
39 | |
---|
40 | ?> |
---|
Note: See
TracBrowser
for help on using the repository browser.