-
Notifications
You must be signed in to change notification settings - Fork 5
/
cc98id.php
123 lines (97 loc) · 2.65 KB
/
cc98id.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
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
<?php
/*
* CC98 ID 相关功能页面
*
* 版本:1.0
* 作者:樱桃
* 时间:2014-10-14
*
* 修订记录:
* 无
*
*/
require_once("include/bittorrent.php");
dbconn();
loggedinorreturn();
$user_lang = get_current_user_lang();
$res = get_current_user_resource()['cc98_logon'];
function generate_uri($state) {
global $cc98_client_id, $cc98_client_secret, $cc98_redirect_uri;
return MessageFormatter::formatMessage('', 'https://openid.cc98.org/connect/authorize?client_id={0}&redirect_uri={1}&response_type=code&state={2}&scope=openid', array(urlencode($cc98_client_id), urlencode($cc98_redirect_uri), urlencode($state)));
}
// 是否是 Post 协议。
if(!empty($_POST)) {
switch($_POST['action']){
case 'delete':
dodelete();
break;
}
// 异常处理。
die();
}
else {
switch($_GET['action']){
case 'new':
$title = $res['msg_create_association_title'];
$state = array(
'id' => $CURUSER['id'],
'action' => 'new',
'returnto' => $_POST['returnto'],
);
generate_action_link($title, $state);
break;
case 'edit':
$title = $res['msg_edit_association_title'];
$state = array(
'id' => $CURUSER['id'],
'action' => 'edit',
'returnto' => $_POST['returnto'],
);
generate_action_link($title, $state);
break;
case 'delete':
generate_delete_link();
break;
}
}
function generate_delete_link() {
global $CURUSER, $user_lang, $res;
stdhead($res['msg_delete_association_title']);
?>
<form method="post">
<p><?= MessageFormatter::formatMessage($user_lang, $res['msg_delete_association_text'], array(htmlspecialchars($CURUSER['cc98id']))) ?></p>
<input type="hidden" name="action" value="delete" />
<button type="submit"><?= $res['msg_delete_association_button_text'] ?></button>
</form>
<?php
stdfoot();
}
function generate_action_link($title, $state) {
global $res;
$state_str = protect_data($state);
stdhead($title);
?>
<h1><?= $title ?></h1>
<p><?= $res['msg_edit_association_text'] ?></p>
<a href="<?= generate_uri($state_str) ?>"><?= $res['msg_edit_association_link_text'] ?></a>
<?php
}
/**
* 执行删除操作。
*/
function dodelete(){
global $CURUSER, $res;
$sql = new_mysqli();
$query = $sql->prepare('UPDATE `users` SET `cc98id` = NULL WHERE `id` = ?');
$query->bind_param('i', $CURUSER['id']);
$query->execute();
?>
<meta http-equiv="refresh" content="3; url=/" />
<?php
$title = $res['msg_delete_association_success_title'];
$msg = $res['msg_delete_association_success_text'];
stdhead($title);
stdmsg($title, $msg);
stdfoot();
die();
}