2018-09-22 01:35:41 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
include_once 'model.php';
|
|
|
|
|
2018-09-22 18:00:00 +02:00
|
|
|
$INPUT = array_merge($_GET, $_POST);
|
2018-09-22 01:35:41 +02:00
|
|
|
|
2018-09-22 18:00:00 +02:00
|
|
|
if (!isset($INPUT['fcm_token'])) die(json_encode(['success' => false, 'message' => 'Missing parameter [[fcm_token]]']));
|
2018-11-12 00:15:50 +01:00
|
|
|
if (!isset($INPUT['pro'])) die(json_encode(['success' => false, 'message' => 'Missing parameter [[pro]]']));
|
|
|
|
if (!isset($INPUT['pro_token'])) die(json_encode(['success' => false, 'message' => 'Missing parameter [[pro_token]]']));
|
2018-09-22 18:00:00 +02:00
|
|
|
|
|
|
|
$fcmtoken = $INPUT['fcm_token'];
|
2018-11-12 00:15:50 +01:00
|
|
|
$ispro = $INPUT['pro'] == 'true';
|
|
|
|
$pro_token = $INPUT['pro_token'];
|
2018-09-22 01:35:41 +02:00
|
|
|
$user_key = generateRandomAuthKey();
|
|
|
|
|
|
|
|
$pdo = getDatabase();
|
|
|
|
|
2018-11-12 00:15:50 +01:00
|
|
|
if ($ispro)
|
|
|
|
{
|
|
|
|
if (!verifyOrderToken($pro_token)) die(json_encode(['success' => false, 'message' => 'Purchase token could not be verified']));
|
|
|
|
}
|
|
|
|
|
|
|
|
$stmt = $pdo->prepare('INSERT INTO users (user_key, fcm_token, is_pro, pro_token, timestamp_accessed) VALUES (:key, :token, :bpro, :spro, NOW())');
|
|
|
|
$stmt->execute(['key' => $user_key, 'token' => $fcmtoken, 'bpro' => $ispro, 'spro' => $ispro ? $pro_token : null]);
|
2018-09-22 01:35:41 +02:00
|
|
|
$user_id = $pdo->lastInsertId('user_id');
|
|
|
|
|
2018-09-23 20:00:10 +02:00
|
|
|
echo json_encode(
|
|
|
|
[
|
2018-11-12 00:15:50 +01:00
|
|
|
'success' => true,
|
|
|
|
'user_id' => $user_id,
|
|
|
|
'user_key' => $user_key,
|
|
|
|
'quota' => 0,
|
|
|
|
'quota_max' => Statics::quota_max($ispro),
|
|
|
|
'is_pro' => $ispro,
|
|
|
|
'message' => 'New user registered'
|
2018-09-23 20:00:10 +02:00
|
|
|
]);
|
|
|
|
|
2018-09-22 01:35:41 +02:00
|
|
|
return 0;
|