This repository has been archived on 2024-04-08. You can view files and clone it, but cannot push or open issues or pull requests.
lnauth/classes/lnAuth/Model/Account.php
2016-08-25 23:23:25 +10:00

69 lines
1.8 KiB
PHP

<?php defined('SYSPATH') or die('No direct access allowed.');
/**
* This Model manages both the accounts that users use to login to the system, as well as the account where services are owned.
*
* @package lnAuth
* @category Models
* @author Deon George
* @copyright (c) 2014 Deon George
* @license http://dev.leenooks.net/license.html
*/
abstract class lnAuth_Model_Account extends lnApp_Model_Account {
// Relationships
protected $_has_many = array(
'user_tokens'=>array('model'=>'user_token'),
'email_log'=>array('far_key'=>'id'),
'group'=>array('through'=>'account_group'),
);
public function rules() {
return Arr::merge(parent::rules(),array(
'id'=>array(
array('ORM::get_next_id',array(':model',':field')),
),
'site_id'=>array(
array('ORM::set_site_id',array(':model',':field')),
),
));
}
public function activated() {
return $this->has_any('group',ORM::factory('Group',array('name'=>'Registered Users'))->list_childgrps(TRUE));
}
/**
* This function will extract the available methods for this account
* This is used both for menu options and method security
*/
public function methods() {
static $result = array();
// @todo We may want to optimise this with some session caching.
if ($result)
return $result;
foreach ($this->groups() as $go)
foreach ($go->module_method->find_all() as $mmo)
if (empty($result[$mmo->id]))
$result[$mmo->id] = $mmo;
Sort::MAsort($result,array('module->name','menu_display'));
return $result;
}
/**
* Return a token valid for this user
*/
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();
}
}
?>