Login/Activation tested
This commit is contained in:
14
classes/lnApp/Controller/Account.php
Normal file
14
classes/lnApp/Controller/Account.php
Normal file
@@ -0,0 +1,14 @@
|
||||
<?php defined('SYSPATH') or die('No direct access allowed.');
|
||||
|
||||
/**
|
||||
* This class provides account management
|
||||
*
|
||||
* @package lnApp
|
||||
* @category Controllers
|
||||
* @author Deon George
|
||||
* @copyright (c) 2014 Deon George
|
||||
* @license http://dev.leenooks.net/license.html
|
||||
*/
|
||||
abstract class lnApp_Controller_Account extends Controller_TemplateDefault {
|
||||
}
|
||||
?>
|
@@ -25,21 +25,15 @@ class lnApp_Controller_Login extends Controller_TemplateDefault {
|
||||
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();
|
||||
$ao->verified = TRUE;
|
||||
$ao->save();
|
||||
|
||||
SystemMessage::factory()
|
||||
->title(_('Account Activated'))
|
||||
->type('info')
|
||||
->body(_('Your account has been activated.'));
|
||||
|
||||
HTTP::redirect('welcome');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -82,6 +76,7 @@ class lnApp_Controller_Login extends Controller_TemplateDefault {
|
||||
|
||||
// Log the password reset
|
||||
$ao->log('Activation code sent');
|
||||
|
||||
Session::instance()->set('activate',$ao);
|
||||
}
|
||||
}
|
||||
@@ -167,10 +162,33 @@ class lnApp_Controller_Login extends Controller_TemplateDefault {
|
||||
$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());
|
||||
$ao->reload()->values($this->request->post());
|
||||
|
||||
if ($ao->loaded())
|
||||
HTTP::redirect('login');
|
||||
if ($ao->loaded()) {
|
||||
$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 = 'Please activate your account for '.$co->name();
|
||||
$email->deliver();
|
||||
|
||||
SystemMessage::factory()
|
||||
->title(_('Account Registered'))
|
||||
->type('info')
|
||||
->body(_('Please check your email for more instructions!'));
|
||||
|
||||
Session::instance()->set('activate',$ao);
|
||||
HTTP::redirect('login/activate/'.$ao->id);
|
||||
}
|
||||
|
||||
Block::factory()
|
||||
->type('form-horizontal')
|
||||
@@ -184,33 +202,26 @@ class lnApp_Controller_Login extends Controller_TemplateDefault {
|
||||
*/
|
||||
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');
|
||||
$token_expire = 15*60;
|
||||
|
||||
// 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);
|
||||
$token = $ao->token($token_expire,'account','user:resetpassword',2);
|
||||
|
||||
if ($token) {
|
||||
$co = Company::instance();
|
||||
|
||||
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',$token)
|
||||
->set('TOKEN_EXPIRE_MIN',$token_expire)
|
||||
->set('USER_NAME',$mmto->account->name());
|
||||
->set('USER_NAME',$ao->name());
|
||||
|
||||
$email->to = array('email'=>array($mmto->account->email=>$mmto->account->name()));
|
||||
$email->to = array('email'=>array($ao->email=>$ao->name()));
|
||||
$email->from = array('email'=>array($co->admin()->email=>$co->admin()->name()));
|
||||
$email->subject = 'Login Reset Token for '.$co->name();
|
||||
$email->deliver();
|
||||
|
@@ -68,6 +68,8 @@ abstract class lnApp_Controller_TemplateDefault extends Kohana_Controller_Templa
|
||||
* @uses meta
|
||||
*/
|
||||
public function before() {
|
||||
$this->ao = Auth::instance()->get_user();
|
||||
|
||||
// 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.'));
|
||||
|
72
classes/lnApp/Controller/User/Account.php
Normal file
72
classes/lnApp/Controller/User/Account.php
Normal file
@@ -0,0 +1,72 @@
|
||||
<?php defined('SYSPATH') or die('No direct access allowed.');
|
||||
|
||||
/**
|
||||
* This class provides User Account Update functions
|
||||
*
|
||||
* @package lnApp
|
||||
* @category Controllers/User
|
||||
* @author Deon George
|
||||
* @copyright (c) 2009-2013 Deon George
|
||||
* @license http://dev.leenooks.net/license.html
|
||||
*/
|
||||
abstract class lnApp_Controller_User_Account extends Controller_Account {
|
||||
protected $secure_actions = array(
|
||||
'edit'=>TRUE,
|
||||
'resetpassword'=>TRUE,
|
||||
);
|
||||
|
||||
/**
|
||||
* Enable User to Edit their Account Details
|
||||
*/
|
||||
public function action_edit() {
|
||||
if ($_POST AND $this->ao->values($_POST)->changed() AND (! $this->save($this->ao)))
|
||||
$this->ao->reload();
|
||||
|
||||
Block::factory()
|
||||
->title(sprintf('Account: %s',$this->ao->accnum()))
|
||||
->title_icon('fa-wrench')
|
||||
->type('form-horizontal')
|
||||
->body(View::factory('account/user/edit')->set('o',$this->ao));
|
||||
}
|
||||
|
||||
public function action_resetpassword() {
|
||||
if ($this->request->post()) {
|
||||
$validation = Validation::factory($this->request->post())
|
||||
->rule('password','not_empty')
|
||||
->rule('password','min_length',array(':value',6))
|
||||
->rule('password_confirm','matches',array(':validation',':field','password'));
|
||||
|
||||
// Store our new values
|
||||
$this->ao->values($this->request->post());
|
||||
|
||||
if (! $validation->check())
|
||||
SystemMessage::factory()
|
||||
->title(_('Record NOT updated'))
|
||||
->type('error')
|
||||
->body(_('Your password didnt pass validation.'));
|
||||
|
||||
// Run validation and save
|
||||
elseif ($this->ao->changed())
|
||||
if ($this->ao->save()) {
|
||||
SystemMessage::factory()
|
||||
->title('Record updated')
|
||||
->type('success')
|
||||
->body(_('Your account record has been updated.'));
|
||||
|
||||
// Log the password reset
|
||||
$this->ao->log('Password reset');
|
||||
|
||||
}
|
||||
|
||||
HTTP::redirect('login');
|
||||
}
|
||||
|
||||
Block::factory()
|
||||
->title(sprintf('Password Reset: %s',$this->ao->accnum()))
|
||||
->title_icon('fa-cog')
|
||||
->id('reset')
|
||||
->type('form-horizontal')
|
||||
->body(View::factory('account/user/resetpassword')->set('o',$this->ao));
|
||||
}
|
||||
}
|
||||
?>
|
Reference in New Issue
Block a user