basic identity creation

This commit is contained in:
friendica 2012-08-24 01:14:42 -07:00
parent 2456174cc9
commit b08d070e15
2 changed files with 51 additions and 46 deletions

View File

@ -1,10 +1,51 @@
<?php
require_once('include/zot.php');
require_once('include/crypto.php');
function create_identity($arr) {
$ret = array('success' => false, 'message' => '');
$nick = trim($_POST['nickname']);
$name = escape_tags($_POST['name']);
if(check_webbie(array($nick)) !== 'nick') {
$ret['message'] = t('Nickname has unsupported characters or is already being used on this site.');
return $ret;
}
$guid = zot_new_uid($nick);
$key = new_keypair(4096);
$primary = true;
$r = q("insert into entity ( entity_account_id, entity_primary,
entity_name, entity_address, entity_global_id, entity_prvkey,
entity_pubkey, entity_pageflags )
values( %d, %d, '%s', '%s', '%s' '%s', '%s', %d ) ",
intval(local_user()),
intval($primary),
dbesc($name),
dbesc($nick),
dbesc($guid),
dbesc($key['prvkey']),
dbesc($key['pubkey']),
intval(PAGE_NORMAL)
);
$r = q("select * from entity where entity_account_id = %d
and entity_global_id = '%s' limit 1",
intval(local_user()),
dbesc($guid)
);
if(! ($r && count($r))) {
$ret['message'] = t('Unable to retrieve created identity');
return $ret;
}
$ret['entity'] = $r[0];
$ret['success'] = true;
return $ret;
}

View File

@ -1,8 +1,8 @@
<?php
require_once('include/identity.php');
function zentity_init(&$a) {
$a->page['template'] = 'full';
$cmd = ((argc() > 1) ? argv(1) : '');
@ -50,8 +50,6 @@ function zentity_init(&$a) {
for($y = 0; $y < 100; $y ++)
$test[] = 'id' . mt_rand(1000,9999);
//print_r($test);
json_return_and_die(check_webbie($test));
}
@ -61,58 +59,24 @@ function zentity_init(&$a) {
function zentity_post(&$a) {
$verified = 0;
$blocked = 1;
$arr = array('post' => $_POST);
call_hooks('zregister_post', $arr);
$max_dailies = intval(get_config('system','max_daily_registrations'));
if($max_dailies) {
$r = q("select count(*) as total from account where account_created > UTC_TIMESTAMP - INTERVAL 1 day");
if($r && $r[0]['total'] >= $max_dailies) {
return;
}
}
switch(get_config('system','register_policy')) {
case REGISTER_OPEN:
$blocked = 0;
$verified = 0;
break;
case REGISTER_APPROVE:
$blocked = 0;
$verified = 0;
break;
default:
case REGISTER_CLOSED:
// TODO check against service class and fix this line
if((! x($_SESSION,'authenticated') && (! x($_SESSION,'administrator')))) {
notice( t('Permission denied.') . EOL );
return;
}
$blocked = 1;
$verified = 0;
break;
}
require_once('include/account.php');
$arr = $_POST;
$arr['blocked'] = $blocked;
$arr['verified'] = $verified;
if(($uid = intval(local_user())) == 0) {
notice( t('Permission denied.') . EOL );
return;
}
$result = create_account($arr);
$result = create_identity($arr);
if(! $result['success']) {
notice($result['message']);
return;
}
$user = $result['user'];
$using_invites = get_config('system','invitation_only');