-
Notifications
You must be signed in to change notification settings - Fork 2
/
login.php
57 lines (46 loc) · 1.48 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
45
46
47
48
49
50
51
52
53
54
55
56
57
<?php
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: GET, POST');
header("Access-Control-Allow-Headers: *");
require 'conn.php';
require 'getUniqId.php';
$data = file_get_contents('php://input');
$error = '';
$wasLoginSucess = false;
$response = [];
$data = json_decode($data);
$data = objectToArray($data);
function objectToArray ($object) {
if(!is_object($object) && !is_array($object)){
return $object;
}
return array_map('objectToArray', (array) $object);
}
$data = $data['loginData'];
$usernameOrEmail = $data['usernameOrEmail'];
$pwd = md5($data['password']);
$token = getUniqId();
// checking emty filds
if($usernameOrEmail == '' || $pwd == '')
{
$error = "Plz Complete all fields";
}else{
$query = mysqli_query($conn,
"SELECT username FROM users WHERE username = '$usernameOrEmail' AND pwd = '$pwd' OR email='$usernameOrEmail' AND pwd='$pwd' ");
if(mysqli_num_rows($query)==1)
{
$wasLoginSucess = true;
$username = mysqli_fetch_assoc($query)['username'];
mysqli_query($conn,"UPDATE loginouth SET outhToken = '$token' WHERE userId = '$username' ");
}else{
$error = "username/emal or password was wrong ";
}
}
$response['sucess'] = $wasLoginSucess;
if($wasLoginSucess){
$response['token'] = $token;
}else{
$response['error'] = $error;
}
echo json_encode($response);
?>