-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaction.auth.php
More file actions
226 lines (207 loc) · 6.24 KB
/
Copy pathaction.auth.php
File metadata and controls
226 lines (207 loc) · 6.24 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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
<?php
#----------------------------------------------------------------------
# Module: Booker - a resource booking module
# Action: openrequest - view or edit a booking-request
#----------------------------------------------------------------------
# See file Booker.module.php for full details of copyright, licence, etc.
#----------------------------------------------------------------------
/* first-pass $params = array
'returnid' => int 159
'bkr_returnid' => string '159'
'bkr_subgrpcount' => string '1'
'bkr_showfrom' => string '1486512000'
'bkr_itempick' => string '10001'
'bkr_range' => string '1'
'bkr_item_id' => string '10001'
'bkr_cartkey' => string 'bkr_Cart5896c3ba0e1e2'
'bkr_firstpick' => string '10001'
'bkr_resume' => string '["default"]'
'bkr_view' => string 'table'
'task' => string 'register'
'action' => string 'auth'
later from authpanel some of the following all prefixed like [A-Za-z][A-Za-z0-9]\d{3}_
'success' + 'user_id'
'repeat' + 'token'
'message'
'focus'
'html'
'cancel'
*/
if (!function_exists('SaveBookerParms')) {
function SaveBookerParms(&$cache, $key, $params)
{
if (!$key) {
$key = Booker\Cache::GetKey(\Booker::PARMKEY);
}
$cache->set($key, $params, 43200);
return $key;
}
function RetrieveBookerParms(&$cache, $key)
{
return $cache->get($key);
}
}
//parameter keys filtered out before redirect etc
$localparams = array(
'authdata',
'bulletin',
'cancel',
'change',
'focus',
'html',
// 'message',
// 'recover',
// 'repeat',
// 'success',
// 'task',
// 'token',
// 'user_id' //etc as per authpanel feedback, above
);
$utils = new Booker\Utils();
if (isset($params['bkr_resume'])) { //first-time here
$cache = Booker\Cache::GetCache($this);
$utils->UnFilterParameters($params);
$_SESSION['parmkey'] = SaveBookerParms($cache, FALSE, $params);
$utils->DecodeParameters($params);
} elseif (isset($params['authdata'])) {
$cache = Booker\Cache::GetCache($this);
$saved = RetrieveBookerParms($cache, $_SESSION['parmkey']);
$utils->DecodeParameters($saved);
$finish = TRUE;
$data = json_decode(base64_decode($params['authdata']));
if ($data) { //stdClass
if (isset($data->success)) {
//TODO deal with stuff e.g. $data->message
$ufuncs = new Booker\Userops($this);
switch ($data->task) {
case 'register':
$name = $data->name ? $data->name : FALSE;
$phone = ($data->contact && preg_match(Booker::PATNPHONE,$data->contact)) ? $data->contact : FALSE;
$address = ($data->contact && !$phone) ? $data->contact : FALSE;
$ufuncs->AddUser($this, $name, $address, $phone, TRUE, $data->login, FALSE, TRUE);
break;
case 'change':
$bookerid = $ufuncs->GetKnown($this, $data->login, FALSE);
if ($bookerid) {
$name = $data->name ? $data->name : FALSE;
$phone = ($data->contact && preg_match(Booker::PATNPHONE,$data->contact)) ? $data->contact : FALSE;
$address = ($data->contact && !$phone) ? $data->contact : FALSE;
$ufuncs->ChangeUser($this, $bookerid, $name, $address, $phone, FALSE, $data->login, $data->loginnew, FALSE, TRUE);
} else {
$saved['message'] = $this->Lang('err_system');
}
break;
case 'delete':
$bookerid = $ufuncs->GetKnown($this, $data->login, FALSE);
if ($bookerid) {
$ufuncs->DeleteUser($this, $bookerid, TRUE);
} else {
$saved['message'] = $this->Lang('err_system');
}
break;
case 'login':
case 'recover':
case 'reset':
break;
default:
break;
}
unset($_SESSION['parmkey']); //TODO iff ok
} elseif (isset($data->cancel)) {
//TODO deal with stuff e.g. $data->message
unset($saved['task']);
unset($_SESSION['parmkey']);
} elseif (isset($data->repeat)) {
//re-run notice from authpanel
$saved += (array)$data;
$saved['task'] = $data->task; //force this
unset($saved['repeat']);
$newparms = $utils->FilterParameters($saved, $localparams);
//self-redirect to generate a foramtted page
$this->Redirect($id, $saved['action'], $saved['returnid'], $newparms);
exit;
}
} else { //data error
$saved['message'] = $this->Lang('err_system');
}
if ($finish) {
$resume = array_pop($saved['resume']);
$returnid = $saved['returnid'];
$saved = $utils->FilterParameters($saved, $localparams);
$this->Redirect($id, $resume, $returnid, $saved);
}
}
$item_id = (int)$params['item_id'];
$baseurl = $this->GetModuleURLPath();
$baseurl2 = str_replace($this->GetName(), 'Auther', $baseurl);
$stylers = <<<EOS
<link rel="stylesheet" type="text/css" href="{$baseurl2}/css/authpanel.css" />
<link rel="stylesheet" type="text/css" href="{$baseurl}/css/public.css" />
EOS;
$customcss = $utils->GetStylesURL($this, $item_id);
if ($customcss) {
$stylers .= <<<EOS
<link rel="stylesheet" type="text/css" href="{$customcss}" />
EOS;
}
//heredoc-var newlines are a problem for in-js quoted strings! so ...
$stylers = preg_replace('/[\\n\\r]+/', '', $stylers);
$js = <<<EOS
var linkadd = '$stylers',
\$head = $('head'),
\$linklast = \$head.find("link[rel='stylesheet']:last");
if (\$linklast.length) {
\$linklast.after(linkadd);
} else {
\$head.append(linkadd);
}
EOS;
echo $utils->MergeJS(FALSE,array($js),FALSE);
$context = $this->GetPreference('authcontext',0);
$task = (empty($params['task'])) ? 'login' : $params['task'];
$token = (empty($params['token'])) ? FALSE : $params['token'];
$ob = cms_utils::get_module('Auther'); //get the autoloader into play
if ($ob) {
unset($ob);
} else {
$this->Crash();
// echo something; exit;
}
$funcs = new Auther\Setup();
list($authhtm,$authjs) = $funcs->GetPanel($context, $task, ['Booker','auth',$id], TRUE, $token);
$tplvars = array('authform' => $authhtm);
switch ($task) {
case 'register':
$key = 'title_register';
break;
case 'recover':
$key = 'title_recover';
break;
case 'change':
$key = 'title_change';
break;
case 'delete':
$key = 'title_delete';
break;
case 'login':
$key = FALSE;
break;
case 'reset':
$key = 'title_reset';
break;
}
$tplvars['title'] = ($key) ? $this->Lang($key) : NULL;
if (!empty($params['bulletin'])) {
$t = htmlspecialchars_decode($params['bulletin'], ENT_XHTML);
if (!preg_match('/\/[a-z]*>/i', $t)) {
$t = '<p>'.$t.'</p>';
}
$tplvars['bulletin'] = $t;
}
if (!empty($params['message'])) {
$tplvars['message'] = $params['message'];
}
echo Booker\Utils::ProcessTemplate($this, 'auth.tpl', $tplvars);
if ($authjs) {
echo $authjs;
}