aboutsummaryrefslogtreecommitdiffstats
path: root/include/account.php
diff options
context:
space:
mode:
Diffstat (limited to 'include/account.php')
-rw-r--r--include/account.php83
1 files changed, 74 insertions, 9 deletions
diff --git a/include/account.php b/include/account.php
index a31dbba4b..1206223d9 100644
--- a/include/account.php
+++ b/include/account.php
@@ -1,4 +1,4 @@
-<?php
+<?php /** @file */
require_once('include/config.php');
require_once('include/network.php');
@@ -6,6 +6,7 @@ require_once('include/plugin.php');
require_once('include/text.php');
require_once('include/language.php');
require_once('include/datetime.php');
+require_once('include/crypto.php');
function check_account_email($email) {
@@ -26,7 +27,7 @@ function check_account_email($email) {
$r = q("select account_email from account where account_email = '%s' limit 1",
dbesc($email)
);
- if(count($r)) {
+ if($r) {
$result['message'] .= t('Your email address is already registered at this site.');
}
}
@@ -80,14 +81,14 @@ function check_account_invite($invite_code) {
function check_account_admin($arr) {
if(is_site_admin())
return true;
- $admin_mail = trim(get_config('system','admin_email'));
+ $admin_email = trim(get_config('system','admin_email'));
if(strlen($admin_email) && $admin_email === trim($arr['email']))
return true;
return false;
}
function account_total() {
- $r = q("select account_id from account where 1");
+ $r = q("select account_id from account where true");
if(is_array($r))
return count($r);
return false;
@@ -107,8 +108,10 @@ function create_account($arr) {
$parent = ((x($arr,'parent')) ? intval($arr['parent']) : 0 );
$flags = ((x($arr,'account_flags')) ? intval($arr['account_flags']) : ACCOUNT_OK);
$roles = ((x($arr,'account_roles')) ? intval($arr['account_roles']) : 0 );
-
+ $expires = ((x($arr,'expires')) ? intval($arr['expires']) : '0000-00-00 00:00:00');
+
$default_service_class = get_config('system','default_service_class');
+
if($default_service_class === false)
$default_service_class = '';
@@ -129,9 +132,16 @@ function create_account($arr) {
// allow the admin_email account to be admin, but only if it's the first account.
$c = account_total();
- if((c === 0) && (check_account_admin($arr)))
+ if(($c === 0) && (check_account_admin($arr)))
$roles |= ACCOUNT_ROLE_ADMIN;
+ // Ensure that there is a host keypair.
+
+ if((! get_config('system','pubkey')) && (! get_config('system','prvkey'))) {
+ $hostkey = new_keypair(4096);
+ set_config('system','pubkey',$hostkey['pubkey']);
+ set_config('system','prvkey',$hostkey['prvkey']);
+ }
$invite_result = check_account_invite($invite_code);
if($invite_result['error']) {
@@ -281,7 +291,7 @@ function send_reg_approval_email($arr) {
function send_verification_email($email,$password) {
$email_msg = replace_macros(get_intltext_template('register_open_eml.tpl'), array(
- '$sitename' => get_config('config','sitename'),
+ '$sitename' => get_config('system','sitename'),
'$siteurl' => z_root(),
'$email' => $email,
'$password' => t('your registration password'),
@@ -373,11 +383,11 @@ function user_deny($hash) {
if(! count($register))
return false;
- $user = q("SELECT account_id FROM account WHERE account_id = %d LIMIT 1",
+ $account = q("SELECT account_id FROM account WHERE account_id = %d LIMIT 1",
intval($register[0]['uid'])
);
- if(! $user)
+ if(! $account)
return false;
$r = q("DELETE FROM account WHERE account_id = %d LIMIT 1",
@@ -391,3 +401,58 @@ function user_deny($hash) {
return true;
}
+
+
+/**
+ * @function downgrade_accounts()
+ * Checks for accounts that have past their expiration date.
+ * If the account has a service class which is not the site default,
+ * the service class is reset to the site default and expiration reset to never.
+ * If the account has no service class it is expired and subsequently disabled.
+ * called from include/poller.php as a scheduled task.
+ *
+ * Reclaiming resources which are no longer within the service class limits is
+ * not the job of this function, but this can be implemented by plugin if desired.
+ * Default behaviour is to stop allowing additional resources to be consumed.
+ */
+
+
+function downgrade_accounts() {
+
+ $r = q("select * from account where not ( account_flags & %d )
+ and account_expires != '0000-00-00 00:00:00'
+ and account_expires < UTC_TIMESTAMP() ",
+ intval(ACCOUNT_EXPIRED)
+ );
+
+ if(! $r)
+ return;
+
+ $basic = get_config('system','default_service_class');
+
+
+ foreach($r as $rr) {
+
+ if(($basic) && ($rr['account_service_class']) && ($rr['account_service_class'] != $basic)) {
+ $x = q("UPDATE account set account_service_class = '%s', account_expires = '%s'
+ where account_id = %d limit 1",
+ dbesc($basic),
+ dbesc('0000-00-00 00:00:00'),
+ intval($rr['account_id'])
+ );
+ $ret = array('account' => $rr);
+ call_hooks('account_downgrade', $ret );
+ logger('downgrade_accounts: Account id ' . $rr['account_id'] . ' downgraded.');
+ }
+ else {
+ $x = q("UPDATE account SET account_flags = (account_flags | %d) where account_id = %d limit 1",
+ intval(ACCOUNT_EXPIRED),
+ intval($rr['account_id'])
+ );
+ $ret = array('account' => $rr);
+ call_hooks('account_downgrade', $ret);
+ logger('downgrade_accounts: Account id ' . $rr['account_id'] . ' expired.');
+ }
+ }
+}
+