aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/identity.php41
-rw-r--r--mod/zentity.php54
2 files changed, 50 insertions, 45 deletions
diff --git a/include/identity.php b/include/identity.php
index 8f906228f..e4696940c 100644
--- a/include/identity.php
+++ b/include/identity.php
@@ -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;
}
diff --git a/mod/zentity.php b/mod/zentity.php
index 794ac0ecb..969d731dd 100644
--- a/mod/zentity.php
+++ b/mod/zentity.php
@@ -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,57 +59,23 @@ function zentity_init(&$a) {
function zentity_post(&$a) {
- $verified = 0;
- $blocked = 1;
-
- $arr = array('post' => $_POST);
- call_hooks('zregister_post', $arr);
+ $arr = $_POST;
- $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;
- }
+ if(($uid = intval(local_user())) == 0) {
+ notice( t('Permission denied.') . EOL );
+ return;
}
- switch(get_config('system','register_policy')) {
-
- case REGISTER_OPEN:
- $blocked = 0;
- $verified = 0;
- break;
-
- case REGISTER_APPROVE:
- $blocked = 0;
- $verified = 0;
- break;
+ $result = create_identity($arr);
- 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;
+ if(! $result['success']) {
+ notice($result['message']);
+ return;
}
- require_once('include/account.php');
- $arr = $_POST;
- $arr['blocked'] = $blocked;
- $arr['verified'] = $verified;
- $result = create_account($arr);
-
- if(! $result['success']) {
- notice($result['message']);
- return;
- }
$user = $result['user'];