Created
December 1, 2009 15:10
-
-
Save aguimaraes/246346 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 defined('SYSPATH') OR die('No direct access allowed.'); | |
class Users_Controller extends Template_Controller { | |
/** | |
* See if method needs to have a template. | |
* If user is not logged in he is redirected to the login method. | |
* | |
* @return void | |
*/ | |
public function __construct() { | |
$this->auth = Auth::instance(); | |
$this->session = Session::instance(); | |
if ( URI::$method == 'login' ) { | |
$this->auto_render = FALSE; | |
$this->template = FALSE; | |
} | |
parent::__construct(); | |
// if have no user in the database, free access to add | |
if ( ORM::factory( 'user' )->count_all() === 0 AND URI::$method == 'add' ) { | |
$this->add(); | |
} | |
if ( ! $this->auth->logged_in() AND URI::$method != 'login' ) { | |
url::redirect( 'users/login' ); | |
} | |
} | |
public function index() { | |
} | |
public function add() { | |
} | |
/** | |
* User login | |
* | |
* @return void | |
*/ | |
public function login() { | |
if ( $this->auth->logged_in() ) { | |
url::redirect( '/'); | |
} elseif ( $this->input->post() ) { | |
$username = $this->input->post( 'username' ); | |
$password = $this->input->post( 'password' ); | |
$remember = (bool) $this->input->post( 'remember' ); | |
if ( ! empty( $username ) ) { | |
if ( $this->auth->login( $username, $password, $remember ) ) { | |
url::redirect( '/' ); | |
} else { | |
$this->session->set( 'field_values', $this->input->post() ); | |
$this->session->set( 'error_msg', 'Usuário e/ou Senha inválido(s).' ); | |
} | |
} else { | |
$this->session->set( 'field_values', $this->input->post() ); | |
} | |
} | |
$view = new View( 'form/login' ); | |
$view->render( TRUE ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment