Updated Login to use lnapp, and minor update to Invoice
This commit is contained in:
@@ -34,7 +34,7 @@ class Company {
|
||||
}
|
||||
|
||||
public function admin() {
|
||||
return $this->so->account->name();
|
||||
return $this->so->account;
|
||||
}
|
||||
|
||||
public function address($ln='<br/>') {
|
||||
|
@@ -11,6 +11,8 @@
|
||||
* @also [logout]
|
||||
*/
|
||||
class Controller_Login extends lnApp_Controller_Login {
|
||||
protected $login_attribute = 'username';
|
||||
|
||||
/**
|
||||
* Enable site registration
|
||||
*
|
||||
@@ -23,70 +25,5 @@ class Controller_Login extends lnApp_Controller_Login {
|
||||
|
||||
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
|
||||
if ($this->request->post()) {
|
||||
// If the username is correct, create a method token
|
||||
if ($this->request->post('username') AND ($ao=ORM::factory('Account',array('username'=>$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
|
||||
// @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,
|
||||
'USER_NAME'=>$mmto->account->namesub(),
|
||||
);
|
||||
$et->send();
|
||||
|
||||
// Log the password reset
|
||||
$ao->log('Password reset token sent');
|
||||
}
|
||||
|
||||
// Redirect to our password reset, the Auth will validate the token.
|
||||
} elseif ($this->request->query('token')) {
|
||||
HTTP::redirect(URL::link('user','account/resetpassword?token='.$this->request->query('token')));
|
||||
}
|
||||
|
||||
// Show our token screen even if the email was invalid.
|
||||
if ($this->request->post('username'))
|
||||
$output = View::factory('pages/login_reset_sent');
|
||||
|
||||
else
|
||||
HTTP::redirect('login');
|
||||
|
||||
} else {
|
||||
$output = View::factory('pages/login_reset');
|
||||
}
|
||||
|
||||
Style::factory()
|
||||
->type('file')
|
||||
->data('media/theme/baseadmin/css/pages/login.css');
|
||||
|
||||
$this->template->content = $output;
|
||||
$this->template->shownavbar = FALSE;
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
@@ -127,6 +127,18 @@ class Model_Account extends lnApp_Model_Account {
|
||||
return $sk.sprintf('%s %s',$this->last_name,$this->first_name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate a token for non-login authorised functinos
|
||||
*/
|
||||
public function token($token_expire,$module,$method,$uses) {
|
||||
return ORM::factory('Module_Method_Token')
|
||||
->method(array($module,$method))
|
||||
->account($this)
|
||||
->uses($uses)
|
||||
->expire(time()+$token_expire*60)
|
||||
->generate();
|
||||
}
|
||||
|
||||
/**
|
||||
* Search for accounts matching a term
|
||||
*/
|
||||
|
Reference in New Issue
Block a user