Updated bootstrap and many other items
This commit is contained in:
@@ -13,6 +13,93 @@
|
||||
class lnApp_Controller_Login extends Controller_TemplateDefault {
|
||||
protected $auth_required = FALSE;
|
||||
|
||||
/**
|
||||
* Activate an account so that it can login and use the site
|
||||
*/
|
||||
public function action_activate() {
|
||||
if ($this->request->post()) {
|
||||
$ao = ORM::factory('Account',array('id'=>$this->request->param('id'),'email'=>$this->request->post('email')));
|
||||
|
||||
if ($ao->loaded()) {
|
||||
if ($ao->activated())
|
||||
HTTP::redirect('login');
|
||||
|
||||
elseif ($ao->activate_code() == $this->request->post('code')) {
|
||||
$go = ORM::factory('Group',array('name'=>'Registered Users'));
|
||||
|
||||
$ago = ORM::factory('Account_Group',array('account_id'=>$ao,'group_id'=>$go));
|
||||
|
||||
if (! $ago->loaded()) {
|
||||
$ago->account_id=$ao;
|
||||
$ago->group_id=$go;
|
||||
}
|
||||
$ago->active = TRUE;
|
||||
$ago->save();
|
||||
|
||||
SystemMessage::factory()
|
||||
->title(_('Account Activated'))
|
||||
->type('info')
|
||||
->body(_('Your account has been activated.'));
|
||||
}
|
||||
}
|
||||
|
||||
} elseif (! $this->request->param('id'))
|
||||
HTTP::redirect('login/activate_resend');
|
||||
|
||||
Block::factory()
|
||||
->title('Activate account')
|
||||
->title_icon('fa-wrench')
|
||||
->type('form-horizontal')
|
||||
->body(View::factory('login/activate')->set('o',Session::instance()->get_once('activate')));
|
||||
}
|
||||
|
||||
/**
|
||||
* Send the account activation code to the email address, validating the email address
|
||||
*/
|
||||
public function action_activate_resend() {
|
||||
if ($this->request->post('email')) {
|
||||
$ao = ORM::factory('Account',array('email'=>$this->request->post('email')));
|
||||
|
||||
if ($ao->loaded()) {
|
||||
if ($ao->activated())
|
||||
HTTP::redirect('login');
|
||||
else {
|
||||
$co = Company::instance();
|
||||
|
||||
// Send our email with the token
|
||||
$email = Email::factory('login_activate')
|
||||
->set('SITE',URL::base(TRUE,TRUE))
|
||||
->set('SITE_ADMIN',$co->admin()->name())
|
||||
->set('CODE',$ao->activate_code())
|
||||
->set('EMAIL',$ao->email)
|
||||
->set('ID',$ao->id)
|
||||
->set('USER_NAME',$ao->name());
|
||||
|
||||
$email->to = array('email'=>array($ao->email=>$ao->name()));
|
||||
$email->from = array('email'=>array($co->admin()->email=>$co->admin()->name()));
|
||||
$email->subject = 'Activation Code for '.$co->name();
|
||||
$email->deliver();
|
||||
|
||||
// Log the password reset
|
||||
$ao->log('Activation code sent');
|
||||
Session::instance()->set('activate',$ao);
|
||||
}
|
||||
}
|
||||
|
||||
HTTP::redirect('login/activate/'.$ao->id);
|
||||
|
||||
} else {
|
||||
Block::factory()
|
||||
->title('Activate account')
|
||||
->title_icon('fa-wrench')
|
||||
->type('form-horizontal')
|
||||
->body(View::factory('login/activate_resend'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Login to the site
|
||||
*/
|
||||
public function action_index() {
|
||||
$output = '';
|
||||
|
||||
@@ -24,9 +111,9 @@ class lnApp_Controller_Login extends Controller_TemplateDefault {
|
||||
HTTP::redirect(URL::link('user','welcome/index'));
|
||||
|
||||
// If there is a post and $_POST is not empty
|
||||
if ($_POST) {
|
||||
if ($this->request->post()) {
|
||||
// If the post data validates using the rules setup in the user model
|
||||
if (Auth::instance()->login($_POST['username'],$_POST['password'])) {
|
||||
if (Auth::instance()->login($this->request->post('username'),$this->request->post('password'))) {
|
||||
// Redirect to the user account
|
||||
if ($redir = Session::instance()->get('afterlogin')) {
|
||||
Session::instance()->delete('afterlogin');
|
||||
@@ -48,7 +135,7 @@ class lnApp_Controller_Login extends Controller_TemplateDefault {
|
||||
else
|
||||
$oauthlogin = FALSE;
|
||||
|
||||
$output .= View::factory('pages/login')
|
||||
$output .= View::factory('login')
|
||||
->set('oauth',$oauthlogin);
|
||||
|
||||
Style::factory()
|
||||
@@ -63,11 +150,92 @@ class lnApp_Controller_Login extends Controller_TemplateDefault {
|
||||
$this->template->shownavbar = FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method redirect when authenticated user doesnt have access to the url
|
||||
*/
|
||||
public function action_noaccess() {
|
||||
SystemMessage::factory()
|
||||
->title(_('No access to requested resource'))
|
||||
->type('danger')
|
||||
->body(_('You do not have access to the requested resource, please contact your administrator.'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Register for an account on the site
|
||||
*/
|
||||
public function action_register() {
|
||||
$ao = ORM::factory('Account',$this->request->param('id'));
|
||||
|
||||
if ($this->request->post() AND $ao->values($this->request->post())->changed() AND (! $this->save($ao)))
|
||||
$ao->reload()->values($this->request->post());
|
||||
|
||||
if ($ao->loaded())
|
||||
HTTP::redirect('login');
|
||||
|
||||
Block::factory()
|
||||
->type('form-horizontal')
|
||||
->title('Register Account')
|
||||
->title_icon('fa-edit')
|
||||
->body(View::factory('account/user/edit')->set('o',$ao));
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable user password reset
|
||||
*/
|
||||
public function action_reset() {
|
||||
// Minutes to keep our token
|
||||
$token_expire = 15;
|
||||
$co = Company::instance();
|
||||
|
||||
// If user already signed-in
|
||||
if (Auth::instance()->logged_in())
|
||||
HTTP::redirect('welcome/index');
|
||||
|
||||
// If the user posted their details to reset their password
|
||||
if ($this->request->post()) {
|
||||
// If the username is correct, create a method token
|
||||
if ($ao=ORM::factory('Account',array('email'=>$this->request->post('username'))) AND $ao->loaded()) {
|
||||
$mmto = ORM::factory('Module_Method_Token')
|
||||
->method(array('account','user:resetpassword'))
|
||||
->account($ao)
|
||||
->uses(2)
|
||||
->expire(time()+$token_expire*60);
|
||||
|
||||
if ($mmto->generate()) {
|
||||
// Send our email with the token
|
||||
$email = Email::factory('login_reset')
|
||||
->set('SITE',URL::base(TRUE,TRUE))
|
||||
->set('SITE_ADMIN',$co->admin()->name())
|
||||
->set('TOKEN',$mmto->token)
|
||||
->set('TOKEN_EXPIRE_MIN',$token_expire)
|
||||
->set('USER_NAME',$mmto->account->name());
|
||||
|
||||
$email->to = array('email'=>array($mmto->account->email=>$mmto->account->name()));
|
||||
$email->from = array('email'=>array($co->admin()->email=>$co->admin()->name()));
|
||||
$email->subject = 'Login Reset Token for '.$co->name();
|
||||
$email->deliver();
|
||||
|
||||
// Log the password reset
|
||||
$ao->log('Password reset token sent');
|
||||
}
|
||||
|
||||
// Redirect to our password reset, the Auth will validate the token.
|
||||
} elseif ($this->request->post('token')) {
|
||||
HTTP::redirect(URL::link('user','account/resetpassword?token='.$this->request->post('token')));
|
||||
}
|
||||
|
||||
// Show our token screen even if the email was invalid.
|
||||
if ($this->request->post('username'))
|
||||
$output = View::factory('login/reset_sent');
|
||||
else
|
||||
HTTP::redirect('login');
|
||||
|
||||
} else {
|
||||
$output = View::factory('login/reset');
|
||||
}
|
||||
|
||||
$this->template->content = $output;
|
||||
$this->template->shownavbar = FALSE;
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
@@ -56,13 +56,7 @@ abstract class lnApp_Controller_TemplateDefault extends Kohana_Controller_Templa
|
||||
* @return boolean
|
||||
*/
|
||||
protected function _auth_required() {
|
||||
// If our global configurable is disabled, then continue
|
||||
if (! Kohana::$config->load('config')->method_security)
|
||||
return FALSE;
|
||||
|
||||
return (($this->auth_required !== FALSE && Auth::instance()->logged_in(NULL,get_class($this).'|'.__METHOD__) === FALSE) ||
|
||||
(is_array($this->secure_actions) && array_key_exists($this->request->action(),$this->secure_actions) &&
|
||||
! Auth::instance()->logged_in($this->secure_actions[$this->request->action()],get_class($this).'|'.__METHOD__)));
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -72,16 +66,6 @@ abstract class lnApp_Controller_TemplateDefault extends Kohana_Controller_Templa
|
||||
* @uses meta
|
||||
*/
|
||||
public function before() {
|
||||
if ($this->auth_required) {
|
||||
if (! count($this->secure_actions) OR (! isset($this->secure_actions[Request::current()->action()])))
|
||||
throw HTTP_Exception::factory(403,'Class has no security defined :class, or no security configured for :method',array(':class'=>get_class($this),':method'=>Request::current()->action()));
|
||||
|
||||
$this->ao = Auth::instance()->get_user();
|
||||
|
||||
if (! is_null($this->ao) AND (is_string($this->ao) OR ! $this->ao->loaded()))
|
||||
throw HTTP_Exception::factory(501,'Account doesnt exist :account ?',array(':account'=>(is_string($this->ao) OR is_null($this->ao)) ? $this->ao : Auth::instance()->get_user()->id));
|
||||
}
|
||||
|
||||
// Actions that start with ajax, should only be ajax
|
||||
if (! Kohana::$config->load('debug')->ajax AND preg_match('/^ajax/',Request::current()->action()) AND ! Request::current()->is_ajax())
|
||||
throw HTTP_Exception::factory(412,_('Unable to fulfil request.'));
|
||||
@@ -94,6 +78,9 @@ abstract class lnApp_Controller_TemplateDefault extends Kohana_Controller_Templa
|
||||
return;
|
||||
}
|
||||
|
||||
if ($this->ao AND $this->ao->loaded() AND ! $this->ao->activated() AND ($this->request->controller() != 'Account' OR $this->request->action() != 'activate'))
|
||||
HTTP::redirect('login/activate');
|
||||
|
||||
// Check user auth and role
|
||||
if ($this->_auth_required()) {
|
||||
if (PHP_SAPI === 'cli')
|
||||
@@ -187,30 +174,18 @@ abstract class lnApp_Controller_TemplateDefault extends Kohana_Controller_Templa
|
||||
$this->check_cache(sha1($this->response->body()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate a view path to help View::factory() calls
|
||||
*
|
||||
* The purpose of this method is to ensure that we have a consistant
|
||||
* layout for our view files, including those that are needed by
|
||||
* plugins
|
||||
*
|
||||
* @param string Plugin Name (optional)
|
||||
* @deprecated
|
||||
*/
|
||||
public function viewpath($plugin='') {
|
||||
$request = Request::current();
|
||||
protected function save(Model $o) {
|
||||
try {
|
||||
return $o->save();
|
||||
|
||||
$path = $request->controller();
|
||||
} catch (ORM_Validation_Exception $e) {
|
||||
SystemMessage::factory()
|
||||
->title('Record NOT updated')
|
||||
->type('danger')
|
||||
->body(join('<br/>',array_values($e->errors('models'))));
|
||||
|
||||
if ($request->directory())
|
||||
$path .= ($path ? '/' : '').$request->directory();
|
||||
|
||||
if ($plugin)
|
||||
$path .= ($path ? '/' : '').$plugin;
|
||||
|
||||
$path .= ($path ? '/' : '').$request->action();
|
||||
|
||||
return strtolower($path);
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
Reference in New Issue
Block a user