Ignore:
Timestamp:
02/20/12 16:27:19 (13 years ago)
Author:
hendrikvanantwerpen
Message:
  • [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:
1 edited

Legend:

Unmodified
Added
Removed
  • Dev/branches/rest-dojo-ui/server/classes/Auth.php

    r256 r274  
    55class Auth {
    66
    7     public static function login($username, $password) {
    8         $user_results = User::get(array("name" => $username));
    9         if (!empty($user_results)) {
    10             $user = $user_results[0];
    11             if (sha1($password) == $user->password) {
    12                 return $user;
    13             }
     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.");
    1411        }
    15         return false;
     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;
    1628    }
    1729
    1830    public static function restore($session) {
    1931        $user_results = User::get(array("uid" => $session));
    20         if (!empty($user_results)) {
    21             return $user_results[0];
     32        if (empty($user_results)) {
     33            throw new Exception("Session with id $session not found.");
    2234        }
    23         return false;
     35        return $user_results[0];
    2436    }
    2537   
Note: See TracChangeset for help on using the changeset viewer.