Updated to work with KH 3.1
This commit is contained in:
@@ -12,34 +12,30 @@
|
||||
* @also [logout]
|
||||
*/
|
||||
class Controller_lnApp_Login extends Controller_TemplateDefault {
|
||||
protected $auth_required = FALSE;
|
||||
|
||||
public function action_index() {
|
||||
// If user already signed-in
|
||||
if (Auth::instance()->logged_in()!= 0) {
|
||||
// Redirect to the user account
|
||||
Request::instance()->redirect('welcome/index');
|
||||
Request::current()->redirect('welcome/index');
|
||||
}
|
||||
|
||||
// If there is a post and $_POST is not empty
|
||||
if ($_POST) {
|
||||
// Store our details in a session key
|
||||
Session::instance()->set('username',$_POST['username']);
|
||||
Session::instance()->set(Kohana::config('auth.session_key'),$_POST['username']);
|
||||
Session::instance()->set('password',$_POST['password']);
|
||||
|
||||
// Instantiate a new user
|
||||
$user = ORM::factory('account');
|
||||
|
||||
// Check Auth
|
||||
$status = $user->login($_POST);
|
||||
|
||||
// If the post data validates using the rules setup in the user model
|
||||
if ($status) {
|
||||
if (Auth::instance()->login($_POST['username'],$_POST['password'])) {
|
||||
// Redirect to the user account
|
||||
if ($redir = Session::instance()->get('afterlogin')) {
|
||||
Session::instance()->delete('afterlogin');
|
||||
Request::instance()->redirect($redir);
|
||||
Request::current()->redirect($redir);
|
||||
|
||||
} else
|
||||
Request::instance()->redirect('welcome/index');
|
||||
Request::current()->redirect('welcome/index');
|
||||
|
||||
} else {
|
||||
SystemMessage::add(array(
|
||||
@@ -56,9 +52,6 @@ class Controller_lnApp_Login extends Controller_TemplateDefault {
|
||||
'style'=>array('css/login.css'=>'screen'),
|
||||
));
|
||||
|
||||
$this->template->control = HTML::anchor($this->request->uri(),'Login',array('id'=>'ajxbody'));
|
||||
$this->template->content = Block::factory();
|
||||
|
||||
Script::add(array('type'=>'stdin','data'=>'
|
||||
$(document).ready(function() {
|
||||
$("#ajxbody").click(function() {$("#ajBODY").load("'.$this->request->uri().'/"); return false;});
|
||||
@@ -70,7 +63,7 @@ class Controller_lnApp_Login extends Controller_TemplateDefault {
|
||||
// If user already signed-in
|
||||
if (Auth::instance()->logged_in()!= 0) {
|
||||
// Redirect to the user account
|
||||
Request::instance()->redirect('welcome/index');
|
||||
Request::current()->redirect('welcome/index');
|
||||
}
|
||||
|
||||
// Instantiate a new user
|
||||
@@ -82,7 +75,7 @@ class Controller_lnApp_Login extends Controller_TemplateDefault {
|
||||
$status = $account->values($_POST)->check();
|
||||
|
||||
if (! $status) {
|
||||
foreach ($account->validate()->errors() as $f=>$r) {
|
||||
foreach ($account->validation()->errors('form/register') as $f => $r) {
|
||||
// $r[0] has our reason for validation failure
|
||||
switch ($r[0]) {
|
||||
// Generic validation reason
|
||||
@@ -90,7 +83,7 @@ class Controller_lnApp_Login extends Controller_TemplateDefault {
|
||||
SystemMessage::add(array(
|
||||
'title'=>_('Validation failed'),
|
||||
'type'=>'error',
|
||||
'body'=>sprintf(_('The defaults on your submission were not valid for field %s (%s).'),$f,$r[0])
|
||||
'body'=>sprintf(_('The defaults on your submission were not valid for field %s (%s).'),$f,$r)
|
||||
));
|
||||
}
|
||||
}
|
||||
@@ -116,12 +109,9 @@ class Controller_lnApp_Login extends Controller_TemplateDefault {
|
||||
'title'=>_('Register'),
|
||||
'body'=>View::factory('bregister')
|
||||
->set('account',$account)
|
||||
->set('errors',$account->validate()->errors()),
|
||||
'style'=>array('css/bregister.css'=>'screen'),
|
||||
->set('errors',$account->validation()->errors('form/register')),
|
||||
));
|
||||
|
||||
$this->template->control = HTML::anchor($this->request->uri(),'Register',array('id'=>'ajxbody'));
|
||||
$this->template->content = Block::factory();
|
||||
$this->template->left = HTML::anchor('login','Login').'...';
|
||||
}
|
||||
|
||||
@@ -132,7 +122,7 @@ class Controller_lnApp_Login extends Controller_TemplateDefault {
|
||||
// If user already signed-in
|
||||
if (Auth::instance()->logged_in()!= 0) {
|
||||
// Redirect to the user account
|
||||
Request::instance()->redirect('welcome/index');
|
||||
Request::current()->redirect('welcome/index');
|
||||
}
|
||||
|
||||
// If the user posted their details to reset their password
|
||||
@@ -176,7 +166,7 @@ class Controller_lnApp_Login extends Controller_TemplateDefault {
|
||||
|
||||
// Redirect to our password reset, the Auth will validate the token.
|
||||
} elseif (! empty($_REQUEST['token'])) {
|
||||
Request::instance()->redirect(sprintf('user/account/resetpassword?token=%s',$_REQUEST['token']));
|
||||
Request::current()->redirect(sprintf('user/account/resetpassword?token=%s',$_REQUEST['token']));
|
||||
}
|
||||
|
||||
// Show our token screen even if the email was invalid.
|
||||
@@ -187,7 +177,7 @@ class Controller_lnApp_Login extends Controller_TemplateDefault {
|
||||
'style'=>array('css/login.css'=>'screen'),
|
||||
));
|
||||
else
|
||||
Request::instance()->redirect('login');
|
||||
Request::current()->redirect('login');
|
||||
|
||||
} else {
|
||||
Block::add(array(
|
||||
@@ -196,13 +186,9 @@ class Controller_lnApp_Login extends Controller_TemplateDefault {
|
||||
'style'=>array('css/login.css'=>'screen'),
|
||||
));
|
||||
}
|
||||
|
||||
$this->template->content = Block::factory();
|
||||
}
|
||||
|
||||
public function action_noaccess() {
|
||||
$this->template->content = ' ';
|
||||
|
||||
SystemMessage::add(array(
|
||||
'title'=>_('No access to requested resource'),
|
||||
'type'=>'error',
|
||||
|
Reference in New Issue
Block a user