Changeset 3183 for trunk/modules

Show
Ignore:
Timestamp:
07/21/2008 11:16:54 PM (4 months ago)
Author:
Shadowhand
Message:

Fixing #499, thanks Stalwart.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/modules/auth/controllers/auth_demo.php

    r2593 r3183  
    1616        const ALLOW_PRODUCTION = FALSE; 
    1717 
    18         public function __construct() 
    19         { 
    20                 parent::__construct(); 
    21  
    22                 // Load auth library 
    23                 $this->auth = new Auth; 
    24         } 
    25  
    2618        public function index() 
    2719        { 
     
    3426                $form = new Forge(NULL, 'Create User'); 
    3527 
    36                 $form->input('email')->label(TRUE)->rules('required|length[4,32]'); 
     28                $form->input('email')->label(TRUE)->rules('required|length[4,32]|valid_email'); 
    3729                $form->input('username')->label(TRUE)->rules('required|length[4,32]'); 
    3830                $form->password('password')->label(TRUE)->rules('required|length[5,40]'); 
     
    4234                { 
    4335                        // Create new user 
    44                         $user = new User_Model; 
     36                        $user = ORM::factory('user'); 
    4537 
    46                         if ( ! $user->username_exists($this->input->post('username'))) 
     38                        if ( ! $user->username_exists($form->username->value)) 
    4739                        { 
    4840                                foreach ($form->as_array() as $key => $val) 
     
    5244                                } 
    5345 
    54                                 if ($user->save() AND $user->add_role('login')) 
     46                                if ($user->save() AND $user->add('role', 'login')) 
    5547                                { 
     48                                        Auth::instance()->login($user, $form->password->value); 
     49 
    5650                                        // Redirect to the login page 
    5751                                        url::redirect('auth_demo/login'); 
     
    6660        public function login() 
    6761        { 
    68                 if ($this->auth->logged_in()) 
     62                if (Auth::instance()->logged_in()) 
    6963                { 
    7064                        $form = new Forge('auth_demo/logout', 'Log Out'); 
     
    8680 
    8781                                // Attempt a login 
    88                                 if ($this->auth->login($user, $form->password->value)) 
     82                                if (Auth::instance()->login($user, $form->password->value)) 
    8983                                { 
    9084                                        echo '<h4>Login Success!</h4>'; 
     
    106100        public function logout() 
    107101        { 
    108                 // Load auth and log out 
    109                 $this->auth->logout(TRUE); 
     102                // Force a complete logout 
     103                Auth::instance()->logout(TRUE); 
    110104 
    111105                // Redirect back to the login page