-
Notifications
You must be signed in to change notification settings - Fork 0
/
login.php
80 lines (55 loc) · 1.87 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
<?php
include 'config/db.php';
require 'vendor/autoload.php';
session_start();
$email = isset($_REQUEST['email']) ? $_REQUEST['email']:'';
$password = isset($_REQUEST['password']) ? $_REQUEST['password']:'';
$facebook_id = isset($_REQUEST['facebookId'])? $_REQUEST['facebookId'] : '';
if($email&&$password){
try {
$sql = "SELECT * FROM users WHERE email= '".$email."' LIMIT 1";
$result = $con->prepare($sql);
$result->execute();
$row = $result->fetch();
} catch (Exception $e) {
echo $e->getMessage();
}
if(!$row){
header('Location: index.php');
}
if (PHPassLib\Hash\BCrypt::verify($password, $row["password"])) {
$_SESSION["name"] = $row["name"]." ".$row["lastname"];
$_SESSION["id"] = $row["id"];
$_SESSION["email"] = $row["email"];
$_SESSION["score"] = $row["score"];
$_SESSION["current_score"] = 0;
$_SESSION["current_questions"] = [];
header('Location: question.php');
}
}else if($email&&$facebook_id){
$name = isset($_POST['name']) ? $_POST['name'] : '';
$lastname = isset($_POST['lastname'])? $_POST['lastname']:'';
$sql = "SELECT * FROM users WHERE email = '".$email."' LIMIT 1";
echo $sql;
$result = $con->prepare($sql);
$result->execute();
$row = $result->fetch();
if(!$row){
$sql = "INSERT INTO users (name,lastname,email,facebook_id) VALUES ('".$name."','".$lastname."','".$email."','".$facebook_id."')";
$result = $con->prepare($sql);
$result->execute();
}else{
$sql = "UPDATE users SET facebook_id = '".$facebook_id."' WHERE email='".$email."' ";
$result = $con->prepare($sql);
}
$_SESSION["name"] = $name." ".$lastname;
$_SESSION["id"] = $id["id"];
$_SESSION["email"] = $email;
$_SESSION["score"] = $score? $score:0;
$_SESSION["current_score"] = 0;
$_SESSION["current_questions"] = [];
header('Location: index.php');
}else{
http_response_code(503);
}
?>