-
Notifications
You must be signed in to change notification settings - Fork 0
/
register.php
33 lines (28 loc) · 984 Bytes
/
register.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
<?php
try {
$inputJSON = file_get_contents('php://input');
$inputData = json_decode($inputJSON);
$password = password_hash($inputData -> password, PASSWORD_DEFAULT);
$token = md5(uniqid($inputData -> email, true));
$conn = require('./includes/getPDOConnection.php');
// prepare sql and bind parameters
$stmt = $conn->prepare("INSERT INTO users (email, password, token)
VALUES (:email, :password, :token)");
$stmt->bindParam(':email', $inputData -> email);
$stmt->bindParam(':password', $password);
$stmt->bindParam(':token', $token);
$success = $stmt->execute();
echo json_encode(array(
'message' => 'Registered successfully',
'success' => $success,
'data' => array(
'token' => $token,
'id' => $conn->lastInsertId()
)
));
} catch(PDOException $e) {
echo json_encode(array(
'message' => "Error: " . $e->getMessage(),
'success' => false
));
}