-
Notifications
You must be signed in to change notification settings - Fork 17
/
login.php
44 lines (34 loc) · 1.24 KB
/
login.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
34
35
36
37
38
39
40
41
42
43
44
<?php
if(isset($silence_other_functions)) {
$suppression = true;
}
else {
$suppression = false;
}
function print_if_needed($string_to_print,$suppression) {
if(!$suppression) {
print $string_to_print;
}
}
print_if_needed("\n",$suppression);
include_once 'config.php';
if($oldtoken = file_get_contents("token")) {
print_if_needed("Found Old Session Token. Attempting Logout... ",$suppression);
include 'logout.php';
}
$json = json_encode(array("email_address" => $email_address, "password" => $password, "device_id" => $device_id));
$ch = curl_init($endpoint."/api/auth/login");
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $json);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json","Content-Length: ".strlen($json)));
$result = json_decode(curl_exec($ch),true) or die("Curl Failed\n");
if($result['data']['token']) {
print_if_needed("New Login Successful for ".$result['data']['user']['first_name']." ".$result['data']['user']['last_name']."!\nToken: ".$result['data']['token'],$suppression);
$token = $result['data']['token'];
file_put_contents("token",$token);
} else {
die("Login Failed!\n");
}
print_if_needed("\n",$suppression);
?>