This repository has been archived on 2024-04-08. You can view files and clone it, but cannot push or open issues or pull requests.
lnapp/classes/lnApp/Controller/Login.php

74 lines
2.0 KiB
PHP
Raw Normal View History

2013-04-22 05:50:28 +00:00
<?php defined('SYSPATH') or die('No direct access allowed.');
/**
* This class provides login capability
*
* @package lnApp
2013-10-08 23:24:11 +00:00
* @category Controllers
2013-04-22 05:50:28 +00:00
* @author Deon George
* @copyright (c) 2009-2013 Deon George
* @license http://dev.leenooks.net/license.html
* @also [logout]
*/
class lnApp_Controller_Login extends Controller_TemplateDefault {
protected $auth_required = FALSE;
public function action_index() {
2013-04-25 00:22:36 +00:00
$output = '';
2014-09-08 13:42:05 +00:00
if (! array_key_exists('auth',Kohana::modules()))
throw HTTP_Exception::factory(501,'Auth not enabled.');
2013-04-22 05:50:28 +00:00
// If user already signed-in
2013-04-25 00:22:36 +00:00
if (Auth::instance()->logged_in())
2013-04-22 05:50:28 +00:00
HTTP::redirect(URL::link('user','welcome/index'));
// If there is a post and $_POST is not empty
if ($_POST) {
// If the post data validates using the rules setup in the user model
if (Auth::instance()->login($_POST['username'],$_POST['password'])) {
// Redirect to the user account
if ($redir = Session::instance()->get('afterlogin')) {
Session::instance()->delete('afterlogin');
HTTP::redirect($redir);
} else
HTTP::redirect(URL::link('user','welcome/index'));
} else {
2013-04-25 00:22:36 +00:00
SystemMessage::factory()
->title(_('Invalid username or password'))
2014-09-08 13:42:05 +00:00
->type('danger')
2013-04-25 00:22:36 +00:00
->body(_('The username or password was invalid.'));
2013-04-22 05:50:28 +00:00
}
}
if (array_key_exists('oauth',Kohana::modules()))
$oauthlogin = is_null($x=Session::instance()->get_once('login-no-oauth',NULL)) ? TRUE : ! $x;
else
$oauthlogin = FALSE;
2013-05-23 05:42:56 +00:00
$output .= View::factory('pages/login')
->set('oauth',$oauthlogin);
2013-04-25 00:22:36 +00:00
2013-05-23 05:42:56 +00:00
Style::factory()
->type('file')
->data('media/css/auth-buttons.css');
if ($oauthlogin)
foreach (ORM::factory('Oauth')->list_active() as $oo)
$output .= $oo->plugin()->html();
2013-04-25 00:22:36 +00:00
$this->template->content = $output;
$this->template->shownavbar = FALSE;
2013-04-22 05:50:28 +00:00
}
public function action_noaccess() {
2013-04-25 00:22:36 +00:00
SystemMessage::factory()
->title(_('No access to requested resource'))
2014-09-08 13:42:05 +00:00
->type('danger')
2013-04-25 00:22:36 +00:00
->body(_('You do not have access to the requested resource, please contact your administrator.'));
2013-04-22 05:50:28 +00:00
}
}
?>