add invitiation logic to registrations - this is starting to look good

This commit is contained in:
friendica 2012-08-16 03:16:55 -07:00
parent adba0bd98a
commit 434bcfef8b
2 changed files with 46 additions and 23 deletions

View file

@ -53,39 +53,56 @@ function check_account_password($password) {
} }
function check_account_invite($invite_code) {
$result = array('error' => false, 'message' => '');
$using_invites = get_config('system','invitation_only');
if($using_invites) {
if(! $invite_code) {
$result['message'] .= t('An invitation is required.') . EOL;
}
$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;
}
}
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) { function create_account($arr) {
// Required: { email, password } // Required: { email, password }
$result = array('success' => false, 'email' => '', 'password' => '', 'message' => ''); $result = array('success' => false, 'email' => '', 'password' => '', 'message' => '');
$using_invites = get_config('system','invitation_only'); $invite_code = ((x($arr,'invite_code')) ? notags(trim($arr['invite_code'])) : '');
$num_invites = get_config('system','number_invites'); $email = ((x($arr,'email')) ? notags(trim($arr['email'])) : '');
$password = ((x($arr,'password')) ? trim($arr['password']) : '');
$invite_id = ((x($arr,'invite_id')) ? notags(trim($arr['invite_id'])) : ''); $password2 = ((x($arr,'password2')) ? trim($arr['password2']) : '');
$email = ((x($arr,'email')) ? notags(trim($arr['email'])) : ''); $parent = ((x($arr,'parent')) ? intval($arr['parent']) : 0 );
$password = ((x($arr,'password')) ? trim($arr['password']) : ''); $flags = ((x($arr,'account_flags')) ? intval($arr['account_flags']) : ACCOUNT_OK);
$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) {
$result['message'] .= t('An invitation is required.') . EOL;
return $result;
}
$r = q("select * from register where `hash` = '%s' limit 1", dbesc($invite_id));
if(! results($r)) {
$result['message'] .= t('Invitation could not be verified.') . EOL;
return $result;
}
}
if((! x($email)) || (! x($password))) { if((! x($email)) || (! x($password))) {
notice( t('Please enter the required information.') . EOL ); $result['message'] = t('Please enter the required information.');
return; 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); $email_result = check_account_email($email);
if(! $email_result['error']) { if(! $email_result['error']) {

View file

@ -7,6 +7,12 @@ function zregister_init(&$a) {
$cmd = ((argc() > 1) ? argv(1) : ''); $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') { if($cmd === 'email_check.json') {
$result = check_account_email($_REQUEST['email']); $result = check_account_email($_REQUEST['email']);
json_return_and_die($result); json_return_and_die($result);