SimpleCloudNotifier/web/register.php

28 lines
685 B
PHP
Raw Normal View History

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]]']));
$fcmtoken = $INPUT['fcm_token'];
2018-09-22 01:35:41 +02:00
$user_key = generateRandomAuthKey();
$pdo = getDatabase();
$stmt = $pdo->prepare('INSERT INTO users (user_key, fcm_token, timestamp_accessed) VALUES (:key, :token, NOW())');
$stmt->execute(['key' => $user_key, 'token' => $fcmtoken]);
$user_id = $pdo->lastInsertId('user_id');
2018-09-23 20:00:10 +02:00
echo json_encode(
[
'success' => true,
'user_id' => $user_id,
'user_key' => $user_key,
'quota' => 0,
'quota_max'=> 100,
'message' => 'New user registered'
]);
2018-09-22 01:35:41 +02:00
return 0;