Created
April 4, 2013 17:15
-
-
Save anonymous/5312225 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Controller_Users extends Controller_Template { | |
public function action_login() { | |
if (Auth::check()) { | |
Response::redirect('dashboard'); | |
} | |
if (Input::method() == 'POST') { | |
if (Auth::login(Input::post('username'), Input::post('password'))) { | |
Session::set_flash('success', 'You have logged in!'); | |
Response::redirect('dashboard'); | |
} else { | |
Session::set_flash('error', 'Invalid login credentials please try again !'); | |
} | |
} | |
$this->template->title = 'Login'; | |
$this->template->content = View::forge('users/login'); | |
} | |
public function action_register() { | |
if (Auth::check()) { | |
Response::redirect('dashboard'); | |
} | |
if (Input::method() == 'POST') { | |
$data['username'] = Input::post('username'); | |
$data['email'] = Input::post('email'); | |
try { | |
$create_process = Auth::create_user(Input::post('username'), Input::post('password'), Input::post('email')); | |
if ($create_process) { | |
Session::set_flash('success', 'You have been successfully registered , please login !'); | |
Response::redirect('/login'); | |
} else { | |
Session::set_flash('error', 'Sorry registration failed please try again'); | |
} | |
} catch (Exception $exc) { | |
Session::set_flash('error', $exc->getMessage()); | |
} | |
$this->template->content = View::forge('users/register', $data); | |
} else { | |
$this->template->content = View::forge('users/register'); | |
} | |
$this->template->title = 'Register'; | |
} | |
public function action_logout() { | |
Auth::logout(); | |
Session::set_flash('success', 'You have been successfully logged out'); | |
Response::redirect('/login'); | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment