<?php defined('SYSPATH') OR die('No direct access allowed.');
/**
* Default Kohana controller. This controller should NOT be used in production.
* It is for demonstration purposes only!
*
* @package Core
* @author Kohana Team
* @copyright (c) 2007-2008 Kohana Team
* @license http://kohanaphp.com/license.html
*/
class User_Controller extends Template_Controller {
// Disable this controller when Kohana is set to production mode.
// See http://docs.kohanaphp.com/installation/deployment for more details.
const ALLOW_PRODUCTION = FALSE;
// Set the name of the template to use
public $template = 'template';
public function login() {
$this->template->title = 'Logowanie :: photowall.me';
//Check if already logged in
if (Auth::instance()->logged_in('login')) {
url::redirect('index');
} else if (Auth::instance()->logged_in()) {
url::redirect('accessdenied'); //User hasn't confirmed account yet
}
//Initialize template and form fields
$this->template->content = new View('user/login');
$this->template->content->username = '';
$view->template->content->password = '';
//Attempt login if form was submitted
if ($post = $this->input->post()) {
if (ORM::factory('user')->login($post)) {
url::redirect('panel/projects');
} else {
die(print_r($post->errors()));
$this->template->content->username = $post['username']; //Redisplay username (but not password) when form is redisplayed.
$view->template->content->message = in_array('required', $post->errors()) ? 'Username and password are required.' : 'Invalid username and/or password.';
}
}
//Display login form
#$view->render(TRUE);
}
}