From 80816a71955b8959bd9f1e24ee39d52aac3158eb Mon Sep 17 00:00:00 2001 From: Klaus Weidenbach Date: Sat, 14 Mar 2015 00:10:06 +0100 Subject: Some documentation, fix chatroom service class lookup. Add some Doxygen documentation and fixing a service class lookup for chatroom_create(). --- include/account.php | 51 ++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 38 insertions(+), 13 deletions(-) (limited to 'include/account.php') diff --git a/include/account.php b/include/account.php index 19c13d5bd..5793c2724 100644 --- a/include/account.php +++ b/include/account.php @@ -559,7 +559,7 @@ function downgrade_accounts() { // or what the subscriber is not allowed to do. -function service_class_allows($uid,$property,$usage = false) { +function service_class_allows($uid, $property, $usage = false) { $a = get_app(); if($uid == local_channel()) { $service_class = $a->account['account_service_class']; @@ -586,13 +586,26 @@ function service_class_allows($uid,$property,$usage = false) { else { if(! array_key_exists($property,$arr)) return true; + return (((intval($usage)) < intval($arr[$property])) ? true : false); } } -// like service_class_allows but queries by account rather than channel -function account_service_class_allows($aid,$property,$usage = false) { - $a = get_app(); +/** + * @brief Checks service class restrictions by account_id. + * + * Like service_class_allows() but queries by account rather than channel. + * + * @see service_class_allows() + * + * @param int $aid account_id + * @param string $property + * @param int|boolean $usage, default false + * @return boolean + * + * @todo Can't we use here internally account_service_class_fetch() to reduce duplicate code? + */ +function account_service_class_allows($aid, $property, $usage = false) { $r = q("select account_service_class as service_class from account where account_id = %d limit 1", intval($aid) ); @@ -603,21 +616,33 @@ function account_service_class_allows($aid,$property,$usage = false) { if(! x($service_class)) return true; // everything is allowed - $arr = get_config('service_class',$service_class); + $arr = get_config('service_class', $service_class); if(! is_array($arr) || (! count($arr))) return true; if($usage === false) return ((x($arr[$property])) ? (bool) $arr[$property] : true); else { - if(! array_key_exists($property,$arr)) + if(! array_key_exists($property, $arr)) return true; + return (((intval($usage)) < intval($arr[$property])) ? true : false); } } - -function service_class_fetch($uid,$property) { +/** + * @brief Fetches a service class for a channel_id and property. + * + * This method not just checks if a service class is allowed like service_class_allows(), + * but also returns the service class value. + * If no service class is available it returns false and everything should be + * allowed. + * + * @param int $uid channel_id + * @param string $property + * @return boolean|int + */ +function service_class_fetch($uid, $property) { $a = get_app(); if($uid == local_channel()) { $service_class = $a->account['account_service_class']; @@ -635,17 +660,17 @@ function service_class_fetch($uid,$property) { if(! x($service_class)) return false; // everything is allowed - $arr = get_config('service_class',$service_class); + $arr = get_config('service_class', $service_class); if(! is_array($arr) || (! count($arr))) return false; - return((array_key_exists($property,$arr)) ? $arr[$property] : false); + return((array_key_exists($property, $arr)) ? $arr[$property] : false); } // like service_class_fetch but queries by account rather than channel -function account_service_class_fetch($aid,$property) { +function account_service_class_fetch($aid, $property) { $r = q("select account_service_class as service_class from account where account_id = %d limit 1", intval($aid) @@ -657,12 +682,12 @@ function account_service_class_fetch($aid,$property) { if(! x($service_class)) return false; // everything is allowed - $arr = get_config('service_class',$service_class); + $arr = get_config('service_class', $service_class); if(! is_array($arr) || (! count($arr))) return false; - return((array_key_exists($property,$arr)) ? $arr[$property] : false); + return((array_key_exists($property, $arr)) ? $arr[$property] : false); } -- cgit v1.2.3 From 864116805b7adf8e82be582c2df8524c44a829fd Mon Sep 17 00:00:00 2001 From: Klaus Weidenbach Date: Mon, 16 Mar 2015 00:20:14 +0100 Subject: Documentation and remove duplicate code. Add a bit Doxygen documentation and remove some duplicate code from account.php. --- include/account.php | 151 +++++++++++++++++++++++++++------------------------- 1 file changed, 79 insertions(+), 72 deletions(-) (limited to 'include/account.php') diff --git a/include/account.php b/include/account.php index 5793c2724..caac0b178 100644 --- a/include/account.php +++ b/include/account.php @@ -523,9 +523,7 @@ function downgrade_accounts() { $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", @@ -550,97 +548,96 @@ function downgrade_accounts() { } - -// check service_class restrictions. If there are no service_classes defined, everything is allowed. -// if $usage is supplied, we check against a maximum count and return true if the current usage is -// less than the subscriber plan allows. Otherwise we return boolean true or false if the property -// is allowed (or not) in this subscriber plan. An unset property for this service plan means -// the property is allowed, so it is only necessary to provide negative properties for each plan, -// or what the subscriber is not allowed to do. - - +/** + * @brief Check service_class restrictions. + * + * If there are no service_classes defined, everything is allowed. + * If $usage is supplied, we check against a maximum count and return true if + * the current usage is less than the subscriber plan allows. Otherwise we + * return boolean true or false if the property is allowed (or not) in this + * subscriber plan. An unset property for this service plan means the property + * is allowed, so it is only necessary to provide negative properties for each + * plan, or what the subscriber is not allowed to do. + * + * Like account_service_class_allows() but queries directly by account rather + * than channel. Service classes are set for accounts, so we look up the + * account for the channel and fetch the service class restrictions of the + * account. + * + * @see account_service_class_allows() if you have a channel_id already + * @see service_class_fetch() + * + * @param int $uid The channel_id to check + * @param string $property The service class property to check for + * @param string|boolean $usage (optional) The value to check against + * @return boolean + */ function service_class_allows($uid, $property, $usage = false) { - $a = get_app(); - if($uid == local_channel()) { - $service_class = $a->account['account_service_class']; - } - else { - $r = q("select account_service_class as service_class - from channel c, account a - where c.channel_account_id=a.account_id and c.channel_id= %d limit 1", - intval($uid) - ); - if($r !== false and count($r)) { - $service_class = $r[0]['service_class']; - } - } - if(! x($service_class)) - return true; // everything is allowed - - $arr = get_config('service_class',$service_class); - if(! is_array($arr) || (! count($arr))) - return true; + $limit = service_class_fetch($uid, $property); - if($usage === false) - return ((x($arr[$property])) ? (bool) $arr[$property] : true); - else { - if(! array_key_exists($property,$arr)) - return true; + if($limit === false) + return true; // No service class set => everything is allowed - return (((intval($usage)) < intval($arr[$property])) ? true : false); + if($usage === false) { + // We use negative values for not allowed properties in a subscriber plan + return ((x($limit)) ? (bool) $limit : true); + } else { + return (((intval($usage)) < intval($limit)) ? true : false); } } /** - * @brief Checks service class restrictions by account_id. + * @brief Check service class restrictions by account. * - * Like service_class_allows() but queries by account rather than channel. + * If there are no service_classes defined, everything is allowed. + * If $usage is supplied, we check against a maximum count and return true if + * the current usage is less than the subscriber plan allows. Otherwise we + * return boolean true or false if the property is allowed (or not) in this + * subscriber plan. An unset property for this service plan means the property + * is allowed, so it is only necessary to provide negative properties for each + * plan, or what the subscriber is not allowed to do. * - * @see service_class_allows() + * Like service_class_allows() but queries directly by account rather than channel. * - * @param int $aid account_id - * @param string $property - * @param int|boolean $usage, default false - * @return boolean + * @see service_class_allows() if you have a channel_id instead of an account_id + * @see account_service_class_fetch() * - * @todo Can't we use here internally account_service_class_fetch() to reduce duplicate code? + * @param int $aid The account_id to check + * @param string $property The service class property to check for + * @param int|boolean $usage, (optional) The value to check against + * @return boolean */ function account_service_class_allows($aid, $property, $usage = false) { - $r = q("select account_service_class as service_class from account where account_id = %d limit 1", - intval($aid) - ); - if($r !== false and count($r)) { - $service_class = $r[0]['service_class']; - } - if(! x($service_class)) - return true; // everything is allowed + $limit = account_service_class_fetch($aid, $property); - $arr = get_config('service_class', $service_class); - if(! is_array($arr) || (! count($arr))) - return true; + if($limit === false) + return true; // No service class is set => everything is allowed - if($usage === false) - return ((x($arr[$property])) ? (bool) $arr[$property] : true); - else { - if(! array_key_exists($property, $arr)) - return true; - - return (((intval($usage)) < intval($arr[$property])) ? true : false); + if($usage === false) { + // We use negative values for not allowed properties in a subscriber plan + return ((x($limit)) ? (bool) $limit : true); + } else { + return (((intval($usage)) < intval($limit)) ? true : false); } } /** - * @brief Fetches a service class for a channel_id and property. + * @brief Queries a service class value for a channel and property. + * + * Service classes are set for accounts, so look up the account for this channel + * and fetch the service classe of the account. * - * This method not just checks if a service class is allowed like service_class_allows(), - * but also returns the service class value. * If no service class is available it returns false and everything should be * allowed. * - * @param int $uid channel_id - * @param string $property + * @see account_service_class_fetch() + * + * @param int $uid The channel_id to query + * @param string $property The service property name to check for * @return boolean|int + * + * @todo Should we merge this with account_service_class_fetch()? */ function service_class_fetch($uid, $property) { $a = get_app(); @@ -668,8 +665,18 @@ function service_class_fetch($uid, $property) { return((array_key_exists($property, $arr)) ? $arr[$property] : false); } -// like service_class_fetch but queries by account rather than channel - +/** + * @brief Queries a service class value for an account and property. + * + * Like service_class_fetch() but queries by account rather than channel. + * + * @see service_class_fetch() if you have channel_id. + * @see account_service_class_allows() + * + * @param int $aid The account_id to query + * @param string $property The service property name to check for + * @return boolean|int + */ function account_service_class_fetch($aid, $property) { $r = q("select account_service_class as service_class from account where account_id = %d limit 1", @@ -692,7 +699,7 @@ function account_service_class_fetch($aid, $property) { function upgrade_link($bbcode = false) { - $l = get_config('service_class','upgrade_link'); + $l = get_config('service_class', 'upgrade_link'); if(! $l) return ''; if($bbcode) @@ -710,4 +717,4 @@ function upgrade_message($bbcode = false) { function upgrade_bool_message($bbcode = false) { $x = upgrade_link($bbcode); return t('This action is not available under your subscription plan.') . (($x) ? ' ' . $x : '') ; -} +} \ No newline at end of file -- cgit v1.2.3 From d0361582b0b620064aff90bf88f01d1072b308fe Mon Sep 17 00:00:00 2001 From: Klaus Weidenbach Date: Sun, 22 Mar 2015 00:06:08 +0100 Subject: Correcting reported Doxygen syntax warnings. Fixed wrong Doxygen syntax and add some of the available FIXME to Doxygen documentation. Updated Doxygen configuration to add also all capital letter tags. Adding some more Doxygen documentation. --- include/account.php | 91 ++++++++++++++++++++++++++--------------------------- 1 file changed, 45 insertions(+), 46 deletions(-) (limited to 'include/account.php') diff --git a/include/account.php b/include/account.php index caac0b178..5926e05c1 100644 --- a/include/account.php +++ b/include/account.php @@ -1,4 +1,8 @@ - false, 'message' => ''); - // The only validation we perform by default is pure Javascript to + // The only validation we perform by default is pure Javascript to // check minimum length and that both entered passwords match. - // Use hooked functions to perform complexity requirement checks. + // Use hooked functions to perform complexity requirement checks. $arr = array('password' => $password, 'result' => $result); call_hooks('check_account_password', $arr); return $arr['result']; - } function check_account_invite($invite_code) { @@ -75,7 +78,6 @@ function check_account_invite($invite_code) { call_hooks('check_account_invite', $arr); return $arr['result']; - } function check_account_admin($arr) { @@ -109,7 +111,7 @@ function create_account($arr) { $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']) : NULL_DATE); - + $default_service_class = get_config('system','default_service_class'); if($default_service_class === false) @@ -132,16 +134,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. + // 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']); - } + 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']) { @@ -180,7 +182,6 @@ function create_account($arr) { dbesc($roles), dbesc($expires), dbesc($default_service_class) - ); if(! $r) { logger('create_account: DB INSERT failed.'); @@ -195,7 +196,7 @@ function create_account($arr) { if($r && count($r)) { $result['account'] = $r[0]; } - else { + else { logger('create_account: could not retrieve newly created account'); } @@ -215,8 +216,8 @@ function create_account($arr) { $result['success'] = true; $result['email'] = $email; $result['password'] = $password; - return $result; + return $result; } @@ -255,7 +256,6 @@ function verify_email_address($arr) { logger('send_reg_approval_email: failed to ' . $admin['email'] . 'account_id: ' . $arr['account']['account_id']); return $res; - } @@ -292,7 +292,6 @@ function send_reg_approval_email($arr) { $details = (($ip) ? $ip . ' [' . gethostbyaddr($ip) . ']' : '[unknown or stealth IP]'); - $delivered = 0; foreach($admins as $admin) { @@ -346,11 +345,14 @@ function send_verification_email($email,$password) { return($res ? true : false); } - +/** + * @brief Allows a user registration. + * + * @param string $hash + * @return array|boolean + */ function user_allow($hash) { - $a = get_app(); - $ret = array('success' => false); $register = q("SELECT * FROM `register` WHERE `hash` = '%s' LIMIT 1", @@ -363,7 +365,7 @@ function user_allow($hash) { $account = q("SELECT * FROM account WHERE account_id = %d LIMIT 1", intval($register[0]['uid']) ); - + if(! $account) return $ret; @@ -381,7 +383,7 @@ function user_allow($hash) { intval(ACCOUNT_PENDING), intval($register[0]['uid']) ); - + push_lang($register[0]['language']); $email_tpl = get_intltext_template("register_open_eml.tpl"); @@ -402,18 +404,23 @@ function user_allow($hash) { pop_lang(); - if($res) { + if ($res) { info( t('Account approved.') . EOL ); return true; - } - + } } -// This does not have to go through user_remove() and save the nickname -// permanently against re-registration, as the person was not yet -// allowed to have friends on this system - +/** + * @brief Denies a user registration. + * + * This does not have to go through user_remove() and save the nickname + * permanently against re-registration, as the person was not yet + * allowed to have friends on this system + * + * @param string $hash + * @return boolean + */ function user_deny($hash) { $register = q("SELECT * FROM register WHERE hash = '%s' LIMIT 1", @@ -426,7 +433,7 @@ function user_deny($hash) { $account = q("SELECT account_id, account_email FROM account WHERE account_id = %d LIMIT 1", intval($register[0]['uid']) ); - + if(! $account) return false; @@ -438,15 +445,14 @@ function user_deny($hash) { dbesc($register[0]['id']) ); notice( sprintf(t('Registration revoked for %s'), $account[0]['account_email']) . EOL); + return true; - + } function user_approve($hash) { - $a = get_app(); - $ret = array('success' => false); $register = q("SELECT * FROM `register` WHERE `hash` = '%s' and password = 'verify' LIMIT 1", @@ -459,7 +465,7 @@ function user_approve($hash) { $account = q("SELECT * FROM account WHERE account_id = %d LIMIT 1", intval($register[0]['uid']) ); - + if(! $account) return $ret; @@ -482,21 +488,16 @@ function user_approve($hash) { intval(ACCOUNT_UNVERIFIED), intval($register[0]['uid']) ); - + info( t('Account verified. Please login.') . EOL ); return true; - } - - - - /** - * @function downgrade_accounts() - * Checks for accounts that have past their expiration date. + * @brief 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. @@ -506,8 +507,6 @@ function user_approve($hash) { * 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 )>0 @@ -604,7 +603,7 @@ function service_class_allows($uid, $property, $usage = false) { * * @param int $aid The account_id to check * @param string $property The service class property to check for - * @param int|boolean $usage, (optional) The value to check against + * @param int|boolean $usage (optional) The value to check against * @return boolean */ function account_service_class_allows($aid, $property, $usage = false) { -- cgit v1.2.3