Skip to content

Commit 8eac553

Browse files
author
Sixto Martin
committed
Implement alternative for mail verification (manual token)
1 parent 458a9f0 commit 8eac553

10 files changed

+187
-17
lines changed

dictionaries/userregistration.definition.json

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,13 @@
148148
"en": "To reset your password at %SNAME%, use the following URL:"
149149
},
150150
"mail_tokeninfo": {
151-
"en": "This URL contains a secret token that validates your e-mail address. This token is valid for only %DAYS% days. If this token expires, you have to request a new token by starting the process over again."
151+
"en": "That secret token validates your e-mail address. This token is valid for only %DAYS% days. If this token expires, you have to request a new token by starting the process over again."
152+
},
153+
"mail_manualtoken_url": {
154+
"en": "If you experience problems with the previous link, try to manually copy the following link in a browser"
155+
},
156+
"mail_manualtoken_token": {
157+
"en": "And add the following token to the field that will appear when accessing this view"
152158
},
153159
"mail1_signature": {
154160
"en": "Kind regards\n%SNAME%"
@@ -159,6 +165,12 @@
159165
"s1_sent_head": {
160166
"en": "Verification email sent"
161167
},
168+
"s1_readtoken_head": {
169+
"en": "Set the token"
170+
},
171+
"s1_readtoken_info": {
172+
"en": "Copy the token that appears on the mail"
173+
},
162174
"s1_para1": {
163175
"en": "The first step is to register and verify your e-mail address. Make sure that you fill in an e-mail address where you can receive e-mail. Notice that some servers could mark this email as SPAM."
164176
},

dictionaries/userregistration.translation.json

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,9 +162,15 @@
162162
},
163163
"mail_tokeninfo": {
164164
"no": "Denne URL-en inneholder en billett som validerer epostadressen din. Denne billetten er gyldig i %DAYS% dager. Dersom den utl\u00f8per blir du n\u00f8dt til \u00e5 be om en ny billett og starte registreringen om igjen.",
165-
"es": "Esta URL contiene un token secreto que valida tu direcci\u00f3n de correo. Este token es v\u00e1lido s\u00f3lo durante %DAYS% d\u00edas. Si el token expira deber\u00e1s repetir la solicitud.",
165+
"es": "El token secreto valida tu direcci\u00f3n de correo. Este token es v\u00e1lido s\u00f3lo durante %DAYS% d\u00edas. Si el token expira deber\u00e1s repetir la solicitud.",
166166
"de": "Dieser URL enth\u00e4lt einen Code, um Ihre E-Mail-Adresse zu best\u00e4tigen. Dieser Code gilt f\u00fcnf Tage lang. Danach m\u00fcssten Sie die Registrierung von Neuem beginnen (und erhalten dann auch einen neuen Code)."
167167
},
168+
"mail_manualtoken_url": {
169+
"es": "Si experimenta problemas con el enlace anterior, intente copiar manualmente el siguiente enlace en un navegador"
170+
},
171+
"mail_manualtoken_token": {
172+
"es": "Y añada el siguiente token al formulario que le aparecerá al acceder a dicha dirección"
173+
},
168174
"mail1_signature": {
169175
"no": "Vennlig hilsen %SNAME%",
170176
"es": "Muchas gracias %SNAME%",
@@ -178,6 +184,12 @@
178184
"s1_sent_head": {
179185
"es": "Correo de confirmación enviado"
180186
},
187+
"s1_readtoken_head": {
188+
"es": "Inserta el token"
189+
},
190+
"s1_readtoken_info": {
191+
"es": "Copia el token que te fue enviado al correo"
192+
},
181193
"s3_head": {
182194
"no": "Data for ny bruker",
183195
"es": "Escoja una contraseña para su cuenta",

lib/Registration.php

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,10 @@ public function step1($error = null)
113113

114114
// Are we coming from an error?
115115
if ($error !== null) {
116-
$values = $this->validator->getRawInput();
117-
$formGen->setValues($values);
116+
if (isset($this->validator)) {
117+
$values = $this->validator->getRawInput();
118+
$formGen->setValues($values);
119+
}
118120

119121
if(method_exists($error, 'getMesgId')) {
120122

@@ -212,19 +214,29 @@ public function step2($refresh_token = FALSE)
212214
}
213215

214216
$url = SimpleSAML_Utilities::selfURL();
215-
217+
$token_string = $token_struct->getKey();
218+
216219
$registerurl = SimpleSAML_Utilities::addURLparameter(
217220
$url,
218221
array(
219-
'token' => $token_struct->getKey()
222+
'token' => $token_string
223+
)
224+
);
225+
226+
$registerManualTokenUrl = SimpleSAML_Utilities::addURLparameter(
227+
$url,
228+
array(
229+
'manualtoken' => '1'
220230
)
221231
);
222232

223233
$tokenExpiration = $this->mailoptions['token.lifetime'];
224234
$mail_data = array(
225235
'email' => $email,
226236
'tokenLifetime' => $tokenExpiration,
237+
'tokenValue' => $token_string,
227238
'registerurl' => $registerurl,
239+
'registerManualTokenUrl' => $registerManualTokenUrl,
228240
'systemName' => $this->systemName,
229241
);
230242

@@ -259,6 +271,27 @@ public function step2($refresh_token = FALSE)
259271
}
260272

261273

274+
// Stage 2c: User copies a URL and manually set the token.
275+
public function step2c()
276+
{
277+
try {
278+
$this->steps->setCurrent(2);
279+
280+
$html = new SimpleSAML_XHTML_Template(
281+
$this->config,
282+
'userregistration:step2c_readtoken.tpl.php',
283+
'userregistration:userregistration');
284+
$html->data['stepsHtml'] = $this->steps->generate();
285+
$html->data['url'] = SimpleSAML_Utilities::selfURLNoQuery();
286+
$html->data['customNavigation'] = $this->customNavigation;
287+
288+
$html->show();
289+
} catch (Exception $e) {
290+
return $e;
291+
}
292+
}
293+
294+
262295
// Stage 3: User clicked on verification URL in email
263296
public function step3($error = null)
264297
{
@@ -338,7 +371,7 @@ public function step3($error = null)
338371
}
339372
}
340373

341-
374+
342375
public function step4()
343376
{
344377
try {

templates/lostPasswordMail_token.tpl.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,12 @@
22
<h1><?php echo $this->t('mailLost_header', $this->data['systemName']);?></h1>
33

44
<p><?php echo $this->t('mailLost_urlintro', $this->data['systemName']);?></p>
5-
<p><tt><a href="<?php echo $this->data['registerurl']; ?>"><?php echo $this->data['registerurl']; ?></a></tt></p>
5+
<p><tt><a href="<?php echo $this->data['pwResetUrl']; ?>"><?php echo $this->data['pwResetUrl']; ?></a></tt></p>
6+
7+
<p><?php echo $this->t('mail_manualtoken_url');?>:</p>
8+
<p><?php echo $this->data['pwManualResetUrl'];?></p>
9+
<p><?php echo $this->t('mail_manualtoken_token');?>:</p>
10+
<p><?php echo $this->data['tokenValue'];?></p>
611

712
<p><?php echo $this->t('mail_tokeninfo', array('%DAYS%' => $this->data['tokenLifetime']/(3600*24)));?></p>
813

templates/mail1_ch_token.tpl.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@
66
<p><?php echo $this->t('mailChange_urlintro', $this->data['systemName']);?></p>
77
<p><tt><a href="<?php echo $this->data['changemailurl']; ?>"><?php echo $this->data['changemailurl']; ?></a></tt></p>
88

9+
<p><?php echo $this->t('mail_manualtoken_url');?>:</p>
10+
<p><?php echo $this->data['mailChangeManualUrl'];?></p>
11+
<p><?php echo $this->t('mail_manualtoken_token');?>:</p>
12+
<p><?php echo $this->data['tokenValue'];?></p>
13+
914
<p><?php echo $this->t('mail_tokeninfo', array('%DAYS%' => $this->data['tokenLifetime']/(3600*24)));?></p>
1015

11-
<p><?php echo $this->t('mail1_signature', $this->data['systemName']);?></p>
16+
<p><?php echo $this->t('mail1_signature', $this->data['systemName']);?></p>

templates/mail1_token.tpl.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@
66
<p><?php echo $this->t('mailNew_urlintro', $this->data['systemName']);?></p>
77
<p><tt><a href="<?php echo $this->data['registerurl']; ?>"><?php echo $this->data['registerurl']; ?></a></tt></p>
88

9+
<p><?php echo $this->t('mail_manualtoken_url');?>:</p>
10+
<p><?php echo $this->data['registerManualTokenUrl'];?></p>
11+
<p><?php echo $this->t('mail_manualtoken_token');?>:</p>
12+
<p><?php echo $this->data['tokenValue'];?></p>
13+
914
<p><?php echo $this->t('mail_tokeninfo', array('%DAYS%' => $this->data['tokenLifetime']/(3600*24)));?></p>
1015

1116
<p><?php echo $this->t('mail1_signature', $this->data['systemName']);?></p>

templates/step2c_readtoken.tpl.php

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
3+
$this->data['header'] = $this->t('{userregistration:userregistration:link_newuser}');
4+
$this->data['head'] = '<link rel="stylesheet" href="resources/userregistration.css" type="text/css">';
5+
6+
$this->includeAtTemplateBase('includes/header.php'); ?>
7+
8+
<?php
9+
if (isset($this->data['stepsHtml'])) {
10+
echo $this->data['stepsHtml'];
11+
}
12+
?>
13+
14+
<div style="margin: 1em">
15+
<h1><?php echo $this->t('s1_readtoken_head'); ?></h1>
16+
<p><?php echo $this->t('s1_readtoken_info'); ?></p>
17+
</div>
18+
19+
20+
<div style="margin: 1em">
21+
<form method="POST" action="<?php echo $this->data['url'];?>">
22+
23+
<label>Token</label>: <input class="inputelement" type="text" value="" name="token" id="token" size="50">
24+
<input type="submit" value="<?php echo $this->t('save');?>" name="savetoken">
25+
</form>
26+
</div>
27+
28+
<?php
29+
if (!$this->data['customNavigation']) {
30+
?>
31+
32+
<p>
33+
<ul>
34+
<li><a href="index.php"><?php echo $this->t('return'); ?></a></li>
35+
</ul>
36+
</p>
37+
38+
<?php
39+
}
40+
?>
41+
42+
<?php $this->includeAtTemplateBase('includes/footer.php'); ?>

www/changeMail.php

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@
147147
$terr->data['customNavigation'] = $customNavigation;
148148
$terr->show();
149149
}
150-
} elseif(array_key_exists('refreshtoken', $_POST)){
150+
} else if(array_key_exists('refreshtoken', $_POST)){
151151
// Resend token
152152

153153
try {
@@ -202,7 +202,6 @@
202202
$html->data['systemName'] = $systemName;
203203
$html->data['customNavigation'] = $customNavigation;
204204
$html->show();
205-
exit();
206205

207206
} catch(sspmod_userregistration_Error_UserException $e) {
208207
// Some user error detected
@@ -240,7 +239,21 @@
240239
$terr->data['customNavigation'] = $customNavigation;
241240
$terr->show();
242241
}
242+
} else if(array_key_exists('manualtoken', $_REQUEST)) {
243+
// Stage 2c: User copies a URL and manually set the token.
244+
try {
243245

246+
$html = new SimpleSAML_XHTML_Template(
247+
$config,
248+
'userregistration:step2c_readtoken.tpl.php',
249+
'userregistration:userregistration');
250+
$html->data['url'] = SimpleSAML_Utilities::selfURLNoQuery();
251+
$html->data['customNavigation'] = $customNavigation;
252+
253+
$html->show();
254+
} catch (Exception $e) {
255+
return $e;
256+
}
244257
} else if (array_key_exists('sender', $_REQUEST) && array_key_exists('newmail', $_REQUEST) && !empty($_REQUEST['newmail'])) {
245258

246259
try {
@@ -279,11 +292,20 @@
279292
)
280293
);
281294

295+
$changemailmanualurl = SimpleSAML_Utilities::addURLparameter(
296+
$url,
297+
array(
298+
'manualtoken' => '1'
299+
)
300+
);
301+
282302
$mail_data = array(
283303
'newmail' => $newmail,
284304
'tokenLifetime' => $mailoptions['token.lifetime'],
285305
'changemailurl' => $changemailurl,
286306
'systemName' => $systemName,
307+
'mailChangeManualUrl' => $changemailmanualurl,
308+
'tokenValue' => $token_string,
287309
);
288310

289311
sspmod_userregistration_Util::sendEmail(
@@ -340,7 +362,7 @@
340362
$terr->show();
341363
}
342364

343-
} elseif (array_key_exists('logout', $_GET)) {
365+
} else if (array_key_exists('logout', $_GET)) {
344366
if ($customNavigation) {
345367
$as->logout($as->getLoginURL());
346368
}

www/lostPassword.php

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,16 +53,27 @@
5353

5454
$url = SimpleSAML_Utilities::selfURL();
5555

56-
$registerurl = SimpleSAML_Utilities::addURLparameter(
56+
$pw_reset_url = SimpleSAML_Utilities::addURLparameter(
5757
$url,
5858
array(
59-
'token' => $token_string));
59+
'token' => $token_string)
60+
);
61+
62+
$pw_manual_reset_url = SimpleSAML_Utilities::addURLparameter(
63+
$url,
64+
array(
65+
'manualtoken' => '1'
66+
)
67+
);
68+
6069

6170
$systemName = array('%SNAME%' => $uregconf->getString('system.name') );
6271
$mail_data = array(
63-
'registerurl' => $registerurl,
72+
'pwResetUrl' => $pw_reset_url,
6473
'systemName' => $systemName,
6574
'tokenLifetime' => $mailoptions['token.lifetime'],
75+
'pwManualResetUrl' => $pw_manual_reset_url,
76+
'tokenValue' => $token_string,
6677
);
6778

6879
$emailto = $email;
@@ -96,12 +107,27 @@
96107
$terr->data['customNavigation'] = $customNavigation;
97108
$terr->show();
98109
}
110+
} elseif(array_key_exists('manualtoken', $_REQUEST)) {
111+
// Stage 2c: User copies a URL and manually set the token.
112+
try {
113+
114+
$html = new SimpleSAML_XHTML_Template(
115+
$config,
116+
'userregistration:step2c_readtoken.tpl.php',
117+
'userregistration:userregistration');
118+
$html->data['url'] = SimpleSAML_Utilities::selfURLNoQuery();
119+
$html->data['customNavigation'] = $customNavigation;
120+
121+
$html->show();
122+
} catch (Exception $e) {
123+
return $e;
124+
}
99125

100-
} elseif(array_key_exists('token', $_GET)) {
126+
} elseif(array_key_exists('token', $_REQUEST) && ! array_key_exists('emailconfirmed', $_REQUEST)) {
101127
// Stage 3: User access page from url in e-mail
102128
try{
103129

104-
$token_string = $_GET['token'];
130+
$token_string = $_REQUEST['token'];
105131
$token_struct = $extraStorage->retrieve($token_string, 'sspmod_userregistration_ExtraData_PasswordChangeToken');
106132

107133
if ($token_struct === false) {

www/newUser.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,14 @@
4545
$registration->step3($result_step_3);
4646
}
4747

48+
} elseif(array_key_exists('manualtoken', $_REQUEST) && !array_key_exists('refreshtoken', $_REQUEST)){
49+
// Stage 2 (c): User access page from alternative url in e-mail
50+
$result_step_2c = $registration->step2c();
51+
52+
if (is_a($result_step_2c, 'Exception')) {
53+
$registration->step1($result_step_2c);
54+
}
55+
4856
} elseif(array_key_exists('refreshtoken', $_POST)){
4957
// Stage 2 (b): Resend email token
5058
$registration->step2(TRUE);

0 commit comments

Comments
 (0)