Hide last authors
Poncho Dlv 1.1 1 {{velocity}}
2 #set($email = "$!request.get('e')")
Poncho Dlv 2.1 3 #if($email == '' || !$services.csrf.isTokenValid($request.form_token))
Poncho Dlv 1.1 4 {{translation key="xe.admin.forgotUsername.instructions"/}}
5
6 {{html}}
7 <form method="post" action="$doc.getURL()" class="xformInline">
Poncho Dlv 2.1 8 <div>
9 <label for="e">$services.localization.render('xe.admin.forgotUsername.email.label')</label>
10 <input type="text" id="e" name="e"/>
11 <input type="hidden" name="form_token" value="$services.csrf.getToken()"/>
12 <span class="buttonwrapper">
13 <input type="submit" value="$services.localization.render('xe.admin.forgotUsername.submit')" class="button"/>
14 </span>
15 </div>
Poncho Dlv 1.1 16 </form>
17 {{/html}}
18
19 #else
20 #set($query = $services.query.hql(", BaseObject obj, StringProperty prop where obj.name = doc.fullName and obj.className = 'XWiki.XWikiUsers' and prop.id.id = obj.id and prop.id.name = 'email' and LOWER(prop.value) = :email").bindValue('email', $email.toLowerCase()))
21 #set($results = $query.execute())
22 ## If local user does not exist check global user
23 #if($results.size() == 0 && ${xcontext.database} != ${xcontext.mainWikiName})
24 #set($results = $query.setWiki("${xcontext.mainWikiName}").execute())
25 #end
Poncho Dlv 2.1 26 #set ($emailError = false)
27 #if($results.size() != 0)
28 ## Send the email
29 #set ($from = $services.mail.sender.configuration.fromAddress)
30 #if ("$!from" == '')
31 #set ($from = "no-reply@${request.serverName}")
32 #end
33 ## The mail template use $usernames to display the results.
34 #set ($usernames = $results)
35 #set ($mailTemplateReference = $services.model.createDocumentReference('', 'XWiki', 'ForgotUsernameMailContent'))
36 #set ($mailParameters = {'from' : $from, 'to' : $email, 'language' : $xcontext.locale})
37 #set ($message = $services.mail.sender.createMessage('template', $mailTemplateReference, $mailParameters))
38 #set ($discard = $message.setType('Forgot Username'))
39 #macro (displayError $text)
Poncho Dlv 1.1 40
Poncho Dlv 2.1 41 {{html}}
42 <div class="xwikirenderingerror" title="Click to get more details about the error" style="cursor: pointer;">
43 $services.localization.render('xe.admin.forgotUsername.error.emailFailed')
44 </div>
45 <div class="xwikirenderingerrordescription hidden">
46 <pre>${text}</pre>
47 </div>
48 {{/html}}
Poncho Dlv 1.1 49
Poncho Dlv 2.1 50 #set ($emailError = true)
51 #end
52 ## Check for an error constructing the message!
53 #if ($services.mail.sender.lastError)
54 #displayError($exceptiontool.getStackTrace($services.mail.sender.lastError))
55 #else
56 ## Send the message and wait for it to be sent or for any error to be raised.
57 #set ($mailResult = $services.mail.sender.send([$message], 'database'))
58 ## Check for errors during the send
59 #if ($services.mail.sender.lastError)
60 #displayError($exceptiontool.getStackTrace($services.mail.sender.lastError))
61 #else
62 #set ($failedMailStatuses = $mailResult.statusResult.getAllErrors())
63 #if ($failedMailStatuses.hasNext())
64 #set ($mailStatus = $failedMailStatuses.next())
65 #displayError($mailStatus.errorDescription)
66 #end
67 #end
68 #end
Poncho Dlv 1.1 69 #end
Poncho Dlv 2.1 70 ## We always display a success message even if there's no user found to avoid disclosing information
71 ## about the users registered on the wiki.
72 #if (!$emailError)
73 {{success}}
74 $services.localization.render('xe.admin.forgotUsername.emailSent', ["$email"])
Poncho Dlv 1.1 75
Poncho Dlv 2.1 76 {{html}}
77 <div>
78 <a href="$xwiki.getURL('XWiki.XWikiLogin', 'login', 'loginLink=1')">$services.localization.render('xe.admin.forgotUsername.login')</a>
79 </div>
80 {{/html}}
81
82 {{/success}}
83 #end
Poncho Dlv 1.1 84 #end
85 {{/velocity}}