Work on register.php, look at TODOs

This commit is contained in:
nikolark committed 2014-05-11 21:44:12 +02:00
1 parent 5d7db34397
commit b561dc0531
7 files changed
+126 -40

No files matched your search

+64 -7
View File
@@ -1,6 +1,20 @@
<?php
/* Pull in Inside */
set_include_path("../../inside/");
require_once("functions.php");
require_once("User.php");
set_include_path("../../includes/");
require_once("DB.php");
/* Our own */
require_once("../lib/CryptoHelper.php");
require_once("../lib/functions.php");
require_once("../config.php");
/*
* Registers a temporary user in the temp user table
* Registers a user in the user table
*
* Request:
*
@@ -25,13 +39,56 @@
* }
*
* TODO:
* - Decode encrypted http body
* - validate http body
* - register user in temp user db
* - register user with fromSnappOrder flag
* - return result
*/
/* Decrypt body */
$crypt = new CryptoHelper(SNAP_IV, SNAP_KEY);
var_dump($crypt->decrypt($crypt->encrypt("lol")));
/* Validate request */
$body = file_get_contents('php://input');
if(strlen($body) === 0) {
set_response_code(400);
echo json_encode(array('error' => 'Invalid request'));
die();
}
/* Decrypt body */
// TODO enable
//$crypt = new CryptoHelper(SNAP_IV, SNAP_KEY);
//$body = $crypt->decrypt($body);
$data = (array) json_decode($body);
if($data === NULL) {
set_response_code(400);
echo json_encode(array('error' => 'Can\'t decode body'));
die();
}
/* Validate supplied data */
$required_keys = array('firstname', 'lastname', 'phone', 'email');
foreach($required_keys as $key) {
if(!array_key_exists($key, $data)) {
set_response_code(400);
echo json_encode(array('error' => 'missing required field \''.$key.'\''));
die();
}
}
// TODO validate phonenumber
// TODO validate email
// TODO look at getUseridFromPhone in inside/functions.php
// TODO when $fromSnappOrder is sent to User-constructor...
// ...then work around requirements for username, password, birthdate, address
/* Create user */
//$new_user = new User(NULL, $data);
/* Get and format user */
//$user = get_user($new_user->id);
/* Add back phone number from query */
//$user['phone'] = $phone;
/* Return encrypted user object */
//echo json_encode($user);
//echo $crypt->encrypt(json_encode($user));
?>