-
Notifications
You must be signed in to change notification settings - Fork 0
/
login.php
44 lines (39 loc) · 1.34 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
/**
* Created by PhpStorm.
* User: root
* Date: 17/3/20
* Time: 12:52 AM
*/
require_once 'include/DB_Function.php';
$db = new DB_Functions();
// json response array
$response = array("error" => false);
if (isset($_POST['username']) && isset($_POST['password'])) {
// receiving the post params
$username = $_POST['username'];
$password = $_POST['password'];
// get the user by username and password
$user = $db->getUserByUsernameAndPassword($username, $password);
if ($user != null && $user != false) {
// user is found
$response["error"] = false;
$response["user"]["id"] = $user["id"];
$response["user"]["name"] = $user["name"];
$response["user"]["username"] = $user["username"];
$response["user"]["email"] = $user["email"];
$response["user"]["lat"] = $user["lat"];
$response["user"]["lon"] = $user["lon"];
echo json_encode($response);
} else {
// user is not found with the credentials
$response["error"] = true;
$response["error_msg"] = "Login credentials are wrong. Please try again!";
echo json_encode($response);
}
} else {
// required post params is missing
$response["error"] = true;
$response["error_msg"] = "Required parameteres email or password is missing!";
echo json_encode($response);
}