-
Notifications
You must be signed in to change notification settings - Fork 0
/
signin.php
62 lines (50 loc) · 1.79 KB
/
signin.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
<?php
session_start(); // start session
include_once "./adoConnection.php";
$email = $password = $result = "";
$returnData = array();
$returnData[ "message" ] = "";
$returnData[ "code" ] = -1;
//-----------------------------------------------------------------
// get data from front-end
if ( isset( $_POST[ "email" ] ) && $_POST[ "email" ] != "" ) {
$email = $_POST[ "email" ];
}
if ( isset( $_POST[ "password" ] ) && $_POST[ "password" ] != "" ) {
$password = $_POST[ "password" ];
}
if ( $_POST[ "email" ] == "" || $_POST[ "password" ] == "" ) {
$returnData[ "code" ] = 1;
$returnData[ "message" ] = "帳號或密碼不可為空!!";
}
if ( $returnData[ "message" ] != "" ) {
echo json_encode( $returnData );
exit();
}
$sql = "select name , id , email , password from remind_user where email = ?";
$sql = $conn->prepare( $sql );
$result = $conn->execute( $sql , array( $email ) );
// check query status
if ( !$result ) {
$returnData[ "code" ] = 1;
$returnData[ "message" ] = "查詢錯誤!! 請重試";
}
// check whether password is correct or not
if ( !password_verify( $password , $result->fields[ "password" ] ) ) {
$returnData[ "code" ] = 1;
$returnData[ "message" ] = "帳號或密碼錯誤!!";
}
if ( $returnData[ "message" ] != "" ) {
echo json_encode( $returnData );
exit();
}
// register session
$_SESSION[ "id" ] = $result->fields[ "id" ];
$_SESSION[ "email" ] = $result->fields[ "email" ];
$_SESSION[ "username" ] = $result->fields[ "name" ];
// return true
$returnData[ "code" ] = 0;
$returnData[ "message" ] = "";
echo json_encode( $returnData );
$conn->close();
?>