-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck_email.php
More file actions
188 lines (107 loc) · 4.94 KB
/
check_email.php
File metadata and controls
188 lines (107 loc) · 4.94 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
<?php
include(dirname(__FILE__)."/function.php");
$Wormdb = @mysql_connect($db_host, $db_user, $db_pass) or die ('錯誤:數據庫連接失敗');
mysql_select_db ($db_name);
//facebook===========
require 'facebook.php';
$facebook = new Facebook(array(
'appId' => $appId,
'secret' => $secret,
));
// Get User ID
$user = $facebook->getUser();
if ($user) {
try {
// Proceed knowing you have a logged in user who's authenticated.
$user_profile = $facebook->api('/me');
$fbid=$user_profile['id'];
$uid=fbid_to_uid($fbid);
if($uid!=''){
if(!empty($_GET['token'])){
$result = mysql_query("SELECT * from `account` WHERE fbid='".$fbid."' ORDER BY `uid` DESC LIMIT 1");
while($row = mysql_fetch_array($result))
{
$token_real=$row['email_ok'];
}
if($_GET['token']==$token_real){
$result = mysql_query("UPDATE `account` SET `email_ok`='1' WHERE fbid='".$fbid."' ORDER BY `uid` DESC LIMIT 1");
header("location:index.php?msg=tokenok");
die();
}else{
header("location:index.php?msg=tokenerror");
die();
}
}
$result = mysql_query("SELECT * from `account` WHERE fbid='".$fbid."' ORDER BY `uid` DESC LIMIT 1");
while($row = mysql_fetch_array($result))
{
$token_real=$row['email_ok'];
$user_schoolid=$row['schoolid'];
$user_uid=$row['uid'];
}
if($token_real==0){
//email
$token=md5(date("hi").date("s").rand(1,100));
/*
$subject = '台科防爆網 信箱確認信';
$message = '
<html>
<body>
<p>請打開連結以驗證:</p><a href="http://'.$test.'ntust-bomb.org/check_email.php?token='.$token.'</a>
<br />
<p>或:http://'.$test.'ntust-bomb.org/check_email.php?token='.$token.'</p>
</body>
</html>
';
// To send HTML mail, the Content-type header must be set
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=utf-8' . "\r\n";
$headers .= 'From: NTUST-bomb-service <noreply@ntust-bomb.org>' . "\r\n";
// Mail it
mail($user_schoolid.'@mail.ntust.edu.tw', $subject, $message, $headers);
//mail('mousems.kuo@gmail.com', $subject, $message, $headers);
*/
require 'PHPMailer-master/PHPMailerAutoload.php';
$mail = new PHPMailer;
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'mail.ntust.edu.tw'; // Specify main and backup server
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'b10115012'; // SMTP username
$mail->Password = 'eo3su32l4'; // SMTP password
$mail->SMTPSecure = ''; // Enable encryption, 'ssl' also accepted
$mail->setLanguage('zh', '/optional/path/to/language/directory/');
$mail->From = 'b10115012@mail.ntust.edu.tw';
$mail->FromName = 'NTUST-Bomb';
//$mail->addAddress($user_schoolid.'@mail.ntust.edu.tw', $user_schoolid); // Add a recipient
$mail->addAddress('mousems.kuo@gmail.com', $user_schoolid); // Add a recipient
$mail->WordWrap = 50; // Set word wrap to 50 characters
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = 'NTUST BOMB email address authorization ';
//$mail->Body = '<html><body><a href="http://'.$test.'ntust-bomb.org/check_email.php?token='.$token.'</a></body></html>';
$mail->AltBody = 'http://'.$test.'ntust-bomb.org/check_email.php?token='.$token.'';
if(!$mail->send()) {
echo '<p>送信失敗,有時候回沒辦法連線到。</p><a href="index.php">返回首頁</a>';
exit;
}
//$result = mysql_query("UPDATE `account` SET `email_ok`='".$token."' WHERE fbid='".$fbid."' ORDER BY `uid` DESC LIMIT 1");
log_do($user_uid , "schoolid =".$user_schoolid." token=".$token , "check email sent.");
header("location:index.php?msg=emailed");
}else if($token_real==1){
header("location:index.php");
}else{
header("location:index.php?msg=tokenleave");
}
//email
}else{
//already reg
header("location:index.php");
}
} catch (FacebookApiException $e) {
error_log($e);
$user = null;
header("location:index.php?msg=fb_not_login");
}
}else{
header("location:index.php?msg=fb_not_login");
}
?>