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

69 lines
1.8 KiB
PHP
Raw Permalink Normal View History

2014-09-29 05:15:49 +00:00
<?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
*/
2014-09-29 07:30:54 +00:00
abstract class lnAuth_Model_Account extends lnApp_Model_Account {
2014-09-29 05:15:49 +00:00
// 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;
2015-09-29 05:53:19 +00:00
Sort::MAsort($result,array('module->name','menu_display'));
2014-09-29 05:15:49 +00:00
return $result;
}
/**
2014-09-29 07:30:54 +00:00
* Return a token valid for this user
2014-09-29 05:15:49 +00:00
*/
2014-09-29 07:30:54 +00:00
public function token($token_expire,$module,$method,$uses) {
return ORM::factory('Module_Method_Token')
->method(array($module,$method))
->account($this)
->uses($uses)
2016-08-25 13:23:25 +00:00
->expire(time()+$token_expire*60)
2014-09-29 07:30:54 +00:00
->generate();
2014-09-29 05:15:49 +00:00
}
}
?>