2013-10-10 02:44:53 +00:00
|
|
|
<?php defined('SYSPATH') or die('No direct access allowed.');
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This class provides login capability
|
|
|
|
*
|
|
|
|
* @package OSB
|
|
|
|
* @category Controllers
|
|
|
|
* @author Deon George
|
|
|
|
* @copyright (c) 2009-2013 Open Source Billing
|
|
|
|
* @license http://dev.osbill.net/license.html
|
|
|
|
* @also [logout]
|
|
|
|
*/
|
|
|
|
class Controller_Login extends lnApp_Controller_Login {
|
|
|
|
/**
|
|
|
|
* Enable site registration
|
|
|
|
*
|
|
|
|
* @todo Needs to be written
|
|
|
|
*/
|
|
|
|
public function action_register() {
|
|
|
|
// If user already signed-in
|
|
|
|
if (Auth::instance()->logged_in())
|
|
|
|
HTTP::redirect('welcome/index');
|
|
|
|
|
|
|
|
HTTP::redirect('login');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Enable user password reset
|
|
|
|
*/
|
|
|
|
public function action_reset() {
|
|
|
|
// Minutes to keep our token
|
|
|
|
$token_expire = 15;
|
|
|
|
|
|
|
|
// If user already signed-in
|
|
|
|
if (Auth::instance()->logged_in())
|
|
|
|
HTTP::redirect('welcome/index');
|
|
|
|
|
|
|
|
// If the user posted their details to reset their password
|
2016-08-03 06:20:25 +00:00
|
|
|
if ($this->request->post()) {
|
2013-10-10 02:44:53 +00:00
|
|
|
// If the username is correct, create a method token
|
2016-08-03 06:20:25 +00:00
|
|
|
if ($this->request->post('username') AND ($ao=ORM::factory('Account',array('username'=>$this->request->post('username')))) AND $ao->loaded()) {
|
2013-10-10 02:44:53 +00:00
|
|
|
$mmto = ORM::factory('Module_Method_Token')
|
2013-06-05 14:03:55 +00:00
|
|
|
->method(array('account','user:resetpassword'))
|
2013-10-10 02:44:53 +00:00
|
|
|
->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),
|
|
|
|
'SITE_ADMIN'=>Company::instance()->admin(),
|
|
|
|
'SITE_NAME'=>Company::instance()->name(),
|
|
|
|
'TOKEN'=>$mmto->token,
|
|
|
|
'TOKEN_EXPIRE_MIN'=>$token_expire,
|
2016-08-03 04:00:51 +00:00
|
|
|
'USER_NAME'=>$mmto->account->namesub(),
|
2013-10-10 02:44:53 +00:00
|
|
|
);
|
|
|
|
$et->send();
|
|
|
|
|
|
|
|
// Log the password reset
|
|
|
|
$ao->log('Password reset token sent');
|
|
|
|
}
|
|
|
|
|
|
|
|
// Redirect to our password reset, the Auth will validate the token.
|
2016-08-03 06:20:25 +00:00
|
|
|
} elseif ($this->request->query('token')) {
|
|
|
|
HTTP::redirect(URL::link('user','account/resetpassword?token='.$this->request->query('token')));
|
2013-10-10 02:44:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Show our token screen even if the email was invalid.
|
2016-08-03 06:20:25 +00:00
|
|
|
if ($this->request->post('username'))
|
2013-05-16 11:50:30 +00:00
|
|
|
$output = View::factory('pages/login_reset_sent');
|
2013-05-10 10:48:10 +00:00
|
|
|
|
2013-10-10 02:44:53 +00:00
|
|
|
else
|
|
|
|
HTTP::redirect('login');
|
|
|
|
|
|
|
|
} else {
|
2013-05-16 11:50:30 +00:00
|
|
|
$output = View::factory('pages/login_reset');
|
2013-10-10 02:44:53 +00:00
|
|
|
}
|
2013-04-26 01:42:09 +00:00
|
|
|
|
2013-05-10 10:48:10 +00:00
|
|
|
Style::factory()
|
|
|
|
->type('file')
|
|
|
|
->data('media/theme/baseadmin/css/pages/login.css');
|
|
|
|
|
2013-05-16 11:50:30 +00:00
|
|
|
$this->template->content = $output;
|
2013-04-26 01:42:09 +00:00
|
|
|
$this->template->shownavbar = FALSE;
|
2013-10-10 02:44:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
?>
|