2010-11-29 22:41:08 +00:00
|
|
|
<?php defined('SYSPATH') or die('No direct access allowed.');
|
2013-03-19 22:35:19 +00:00
|
|
|
|
2012-12-10 21:48:30 +00:00
|
|
|
/**
|
|
|
|
* This class provides login capability
|
|
|
|
*
|
|
|
|
* @package OSB
|
|
|
|
* @category Controllers
|
|
|
|
* @author Deon George
|
2013-03-19 22:35:19 +00:00
|
|
|
* @copyright (c) 2009-2013 Open Source Billing
|
|
|
|
* @license http://dev.osbill.net/license.html
|
2012-12-10 21:48:30 +00:00
|
|
|
* @also [logout]
|
|
|
|
*/
|
|
|
|
class Controller_Login extends lnApp_Controller_Login {
|
2013-01-15 06:07:54 +00:00
|
|
|
/**
|
|
|
|
* Enable site registration
|
|
|
|
*
|
|
|
|
* @todo Needs to be written
|
|
|
|
*/
|
2012-12-10 21:48:30 +00:00
|
|
|
public function action_register() {
|
|
|
|
// If user already signed-in
|
2013-04-18 08:17:33 +00:00
|
|
|
if (Auth::instance()->logged_in())
|
2012-12-10 21:48:30 +00:00
|
|
|
HTTP::redirect('welcome/index');
|
|
|
|
|
2013-01-15 06:07:54 +00:00
|
|
|
HTTP::redirect('login');
|
2012-12-10 21:48:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Enable user password reset
|
|
|
|
*/
|
|
|
|
public function action_reset() {
|
|
|
|
// Minutes to keep our token
|
|
|
|
$token_expire = 15;
|
|
|
|
|
|
|
|
// If user already signed-in
|
2013-04-18 08:17:33 +00:00
|
|
|
if (Auth::instance()->logged_in())
|
2012-12-10 21:48:30 +00:00
|
|
|
HTTP::redirect('welcome/index');
|
|
|
|
|
|
|
|
// If the user posted their details to reset their password
|
|
|
|
if ($_POST) {
|
|
|
|
// If the username is correct, create a method token
|
2012-11-09 23:13:57 +00:00
|
|
|
if (! empty($_POST['username']) AND ($ao=ORM::factory('Account',array('username'=>$_POST['username']))) AND $ao->loaded()) {
|
|
|
|
$mmto = ORM::factory('Module_Method_Token')
|
2012-12-10 21:48:30 +00:00
|
|
|
->method(array('account','user_resetpassword'))
|
|
|
|
->account($ao)
|
|
|
|
->uses(2)
|
|
|
|
->expire(time()+$token_expire*60);
|
|
|
|
|
|
|
|
if ($mmto->generate()) {
|
|
|
|
// Send our email with the token
|
|
|
|
// @todo Need to provide an option if Email_Template is not installed/activited.
|
|
|
|
// @todo Need to provide an option if account_reset_password template doesnt exist.
|
|
|
|
$et = Email_Template::instance('account_reset_password');
|
|
|
|
$et->to = array('account'=>array($mmto->account_id));
|
|
|
|
$et->variables = array(
|
|
|
|
'SITE'=>URL::base(TRUE,TRUE),
|
2013-02-12 11:14:59 +00:00
|
|
|
'SITE_ADMIN'=>Company::instance()->admin(),
|
|
|
|
'SITE_NAME'=>Company::instance()->name(),
|
2012-12-10 21:48:30 +00:00
|
|
|
'TOKEN'=>$mmto->token,
|
|
|
|
'TOKEN_EXPIRE_MIN'=>$token_expire,
|
|
|
|
'USER_NAME'=>sprintf('%s %s',$mmto->account->first_name,$mmto->account->last_name),
|
|
|
|
);
|
|
|
|
$et->send();
|
|
|
|
|
|
|
|
// Log the password reset
|
|
|
|
$ao->log('Password reset token sent');
|
|
|
|
}
|
|
|
|
|
|
|
|
// Redirect to our password reset, the Auth will validate the token.
|
|
|
|
} elseif (! empty($_REQUEST['token'])) {
|
2013-04-18 08:17:33 +00:00
|
|
|
HTTP::redirect(URL::link('user','account/resetpassword?token='.$_REQUEST['token']));
|
2012-12-10 21:48:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Show our token screen even if the email was invalid.
|
|
|
|
if (isset($_POST['username']))
|
|
|
|
Block::add(array(
|
|
|
|
'title'=>_('Reset your password'),
|
|
|
|
'body'=>View::factory('login_reset_sent'),
|
|
|
|
'style'=>array('css/login.css'=>'screen'),
|
|
|
|
));
|
|
|
|
else
|
|
|
|
HTTP::redirect('login');
|
|
|
|
|
|
|
|
} else {
|
|
|
|
Block::add(array(
|
|
|
|
'title'=>_('Reset your password'),
|
|
|
|
'body'=>View::factory('login_reset'),
|
|
|
|
'style'=>array('css/login.css'=>'screen'),
|
|
|
|
));
|
|
|
|
}
|
2013-04-26 01:42:09 +00:00
|
|
|
|
|
|
|
$this->template->shownavbar = FALSE;
|
2012-12-10 21:48:30 +00:00
|
|
|
}
|
|
|
|
}
|
2010-11-29 22:41:08 +00:00
|
|
|
?>
|