From 434bcfef8ba816805df29736efb36f8c95c20769 Mon Sep 17 00:00:00 2001 From: friendica Date: Thu, 16 Aug 2012 03:16:55 -0700 Subject: add invitiation logic to registrations - this is starting to look good --- include/account.php | 57 ++++++++++++++++++++++++++++++++++------------------- mod/zregister.php | 6 ++++++ 2 files changed, 43 insertions(+), 20 deletions(-) diff --git a/include/account.php b/include/account.php index 652048e29..ead8ce862 100644 --- a/include/account.php +++ b/include/account.php @@ -53,39 +53,56 @@ function check_account_password($password) { } -function create_account($arr) { - - // Required: { email, password } - - $result = array('success' => false, 'email' => '', 'password' => '', 'message' => ''); +function check_account_invite($invite_code) { + $result = array('error' => false, 'message' => ''); $using_invites = get_config('system','invitation_only'); - $num_invites = get_config('system','number_invites'); - - $invite_id = ((x($arr,'invite_id')) ? notags(trim($arr['invite_id'])) : ''); - $email = ((x($arr,'email')) ? notags(trim($arr['email'])) : ''); - $password = ((x($arr,'password')) ? trim($arr['password']) : ''); - $password2 = ((x($arr,'password2')) ? trim($arr['password2']) : ''); - $parent = ((x($arr,'parent')) ? intval($arr['parent']) : 0 ); - $flags = ((x($arr,'account_flags')) ? intval($arr['account_flags']) : ACCOUNT_OK); if($using_invites) { - if(! $invite_id) { + if(! $invite_code) { $result['message'] .= t('An invitation is required.') . EOL; - return $result; } - $r = q("select * from register where `hash` = '%s' limit 1", dbesc($invite_id)); + $r = q("select * from register where `hash` = '%s' limit 1", dbesc($invite_code)); if(! results($r)) { $result['message'] .= t('Invitation could not be verified.') . EOL; - return $result; } - } + } + if(strlen($result['message'])) + $result['error'] = true; + + $arr = array('invite_code' => $invite_code, 'result' => $result); + call_hooks('check_account_invite', $arr); + + return $arr['result']; + +} + + +function create_account($arr) { + + // Required: { email, password } + + $result = array('success' => false, 'email' => '', 'password' => '', 'message' => ''); + + $invite_code = ((x($arr,'invite_code')) ? notags(trim($arr['invite_code'])) : ''); + $email = ((x($arr,'email')) ? notags(trim($arr['email'])) : ''); + $password = ((x($arr,'password')) ? trim($arr['password']) : ''); + $password2 = ((x($arr,'password2')) ? trim($arr['password2']) : ''); + $parent = ((x($arr,'parent')) ? intval($arr['parent']) : 0 ); + $flags = ((x($arr,'account_flags')) ? intval($arr['account_flags']) : ACCOUNT_OK); if((! x($email)) || (! x($password))) { - notice( t('Please enter the required information.') . EOL ); - return; + $result['message'] = t('Please enter the required information.'); + return $result; + } + + $invite_result = check_account_invite($invite_code); + if(! $invite_result['error']) { + $result['message'] = $invite_result['message']; + return $result; } + $email_result = check_account_email($email); if(! $email_result['error']) { diff --git a/mod/zregister.php b/mod/zregister.php index 6d29cdf59..b8ed4c66b 100644 --- a/mod/zregister.php +++ b/mod/zregister.php @@ -7,6 +7,12 @@ function zregister_init(&$a) { $cmd = ((argc() > 1) ? argv(1) : ''); + + if($cmd === 'invite_check.json') { + $result = check_account_invite($_REQUEST['invite_code']); + json_return_and_die($result); + } + if($cmd === 'email_check.json') { $result = check_account_email($_REQUEST['email']); json_return_and_die($result); -- cgit v1.2.3