Ignore:
Timestamp:
02/24/12 10:03:02 (13 years ago)
Author:
jkraaijeveld
Message:

Merge from rest-dojo-ui 272-282

File:
1 edited

Legend:

Unmodified
Added
Removed
  • Dev/branches/jos-branch/server/classes/Auth.php

    r256 r285  
    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.