-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathverify.php
More file actions
77 lines (74 loc) · 2.25 KB
/
verify.php
File metadata and controls
77 lines (74 loc) · 2.25 KB
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
<?php
class DBCxn{
public static $dsn = 'mysql:host=localhost;dbname=webrss';
public static $user = 'root';
public static $pass = 'root';
//保存连接的内部变量
private static $db;
//不能克隆和技巧化
final private function __construct(){}
final private function __clone(){}
public static function get(){
if(is_null(self::$db)){
self::$db = new PDO(self::$dsn, self::$user, self::$pass);
}
//返回连接
self::$db->query('set names utf8');
return self::$db;
}
}
$db = DBCxn::get();
//处理干净字符串
function safe($str){
return strtolower(trim($str));
}
//存放返回结果的数组
$data = array();
//验证用户名是否存在
if(isset($_POST['usernameValue'])){
$userName = safe($_POST['usernameValue']);
$st = $db->prepare("SELECT COUNT(*) FROM users WHERE userName = ?");
$st->execute(array($userName));
$st_Num = $st->fetchColumn();
if($st_Num == 0){
$data = array("result" => "succeed");
} else{
$data = array("result" => "false");
}
echo json_encode($data);
unset($data);
}
//验证邮箱是否存在
if(isset($_POST['emailValue'])){
$email = safe($_POST['emailValue']);
$st = $db->prepare("SELECT COUNT(*) FROM users WHERE email = ?");
$st->execute(array($email));
$st_Num = $st->fetchColumn();
if($st_Num == 0){
$data = array("result" => "succeed");
} else{
$data = array("result" => "false");
}
echo json_encode($data);
unset($data);
}
//处理用户登录信息
if(isset($_POST['user']) && isset($_POST['pass'])){
$userName = safe($_POST['user']);
$pwd = safe($_POST['pass']);
$st = $db->prepare("SELECT COUNT(access_token) result_sum, access_token FROM users WHERE userName=? AND pwd =?");
$st->execute(array($userName,sha1($pwd) ));
$st_result = $st->fetchAll();
if($st_result[0]['result_sum'] == 1){
$data = array("result" => "succeed");
session_start();
$_SESSION['user'] = $userName;
//在这里读取用户GR授权信息
$_SESSION['access_token'] = $st_result[0]['access_token'];
} else{
$data = array("result" => "false");
}
echo json_encode($data);
unset($data);
}
?>