Zeige letzte Bearbeiter
1 ==== Bitte wenden Sie sich dazu an Ihren DIMAG-Wiki-[[Administrator>>mailto:adnane.bousfiha@la-bw.de?subject=DIMAG-Wiki%20Passwort%20vergessen||title="E-Mail schreiben"]] ====
2
3 {{comment}}
4
5
6 {{velocity}}
7 #**
8 This page starts the password reset procedure. It works according to the next algorithm:
9 1. Display a form requesting the username
10 2. When receiving the username via form submission, generate a random verification string which is stored (as a hash) inside a ResetPasswordRequestClass object attached to the user's profile page. If no such object exists, it is created, but an existing object will be reused, meaning that at most one password reset request can be active at a moment.
11 3. Send an email to the address configured in the user's profile, containing a link to the second step of the password reset procedure.
12
13 URL parameters:
14
15 u = user account sent in the form
16 *###
17 ##
18 ##
19 ## The name of the class used for storing password reset verification data.
20 #set ($verifClass = 'XWiki.ResetPasswordRequestClass')
21 #set ($userName = "$!request.get('u')")
22 ## First step, display the form requesting the username
23 #if ($userName == '' || !$services.csrf.isTokenValid($request.form_token))
24 {{translation key="xe.admin.passwordReset.instructions"/}}
25
26 {{html}}
27 <form method="post" action="$doc.getURL()" class="xformInline">
28 <div>
29 <input type="hidden" name="form_token" value="$!{services.csrf.getToken()}" />
30 <label for="u">$services.localization.render('xe.admin.passwordReset.username.label')</label> <input type="text" id="u" name="u"/> <span class="buttonwrapper"><input type="submit" value="$services.localization.render('xe.admin.passwordReset.submit')" class="button"/></span>
31 </div>
32 </form>
33 {{/html}}
34 #else## Second step, generate the verification string, store it, and send the email
35 ## TODO: Once the usernames are not bound to the XWiki space, revisit this code
36 #if ($userName.indexOf('.') != -1)
37 #set ($userDoc = $xwiki.getDocumentAsAuthor(${userName}))
38 #else
39 #set ($userDoc = $xwiki.getDocumentAsAuthor("XWiki.${userName}"))
40 #end
41 ## Check if the user exists and has a valid email address configured in his profile
42 #set ($userObj = '')
43 #set ($userObj = $userDoc.getObject('XWiki.XWikiUsers'))
44 ## If local user does not exist check global user
45 #if (!$userObj && ${xcontext.database} != ${xcontext.mainWikiName})
46 #if ($userName.indexOf('.') != -1)
47 #set ($userDoc = $xwiki.getDocumentAsAuthor("${xcontext.mainWikiName}:${userName}"))
48 #else
49 #set ($userDoc = $xwiki.getDocumentAsAuthor("${xcontext.mainWikiName}:XWiki.${userName}"))
50 #end
51 #set ($userObj = $userDoc.getObject('XWiki.XWikiUsers'))
52 #end
53 #if (!$userObj)
54
55 {{warning}}$services.localization.render('xe.admin.passwordReset.error.noUser', ["//${escapetool.xml($userName)}//"]){{/warning}}
56
57 #elseif ($userDoc.getObject('XWiki.LDAPProfileClass'))
58
59 {{warning}}$services.localization.render('xe.admin.passwordReset.error.ldapUser', ["//${escapetool.xml($userName)}//"]){{/warning}}
60
61 #else
62 #set ($userEmail = $userObj.getProperty('email').value)
63 #if ("$!userEmail" == '')
64
65 {{error}}{{translation key="xe.admin.passwordReset.error.noEmail"/}}{{/error}}
66
67 #else
68 ## Find the object that will hold the verification string
69 #set ($verifObj = '')
70 #set ($verifObj = $userDoc.getObject($verifClass, true))
71 ## Generate a random string
72 #set ($verifStr = $util.generateRandomString(30))
73 ## If the class is correctly configured, the string should automatically be stored as a hash
74 #set ($discard = $verifObj.set('verification', $verifStr))
75 #set ($discard = $userDoc.saveAsAuthor($services.localization.render('xe.admin.passwordReset.versionComment'), true))
76 ## Compose the verification URL
77 #set ($userDocRef = $escapetool.url($services.model.serialize($userDoc.documentReference, 'default')))
78 #set ($passwordResetURL = $xwiki.getDocument("XWiki.ResetPasswordComplete").getExternalURL('view', "u=${userDocRef}&v=${verifStr}"))
79 ## Send the email
80 #set ($from = $services.mail.sender.configuration.fromAddress)
81 #if ("$!from" == '')
82 #set ($from = "no-reply@${request.serverName}")
83 #end
84 #set ($mailTemplateReference = $services.model.createDocumentReference('', 'XWiki', 'ResetPasswordMailContent'))
85 #set ($mailParameters = {'from' : $from, 'to' : $userEmail, 'language' : $xcontext.locale})
86 #set ($message = $services.mail.sender.createMessage('template', $mailTemplateReference, $mailParameters))
87 #set ($discard = $message.setType('Reset Password'))
88 #macro (displayError $text)
89
90 {{html}}
91 <div class="xwikirenderingerror" title="Click to get more details about the error" style="cursor: pointer;">
92 $services.localization.render('xe.admin.passwordReset.error.emailFailed')
93 </div>
94 <div class="xwikirenderingerrordescription hidden">
95 <pre>${text}</pre>
96 </div>
97 {{/html}}
98
99 #end
100 ## Check for an error constructing the message!
101 #if ($services.mail.sender.lastError)
102 #displayError($exceptiontool.getStackTrace($services.mail.sender.lastError))
103 #else
104 ## Send the message and wait for it to be sent or for any error to be raised.
105 #set ($mailResult = $services.mail.sender.send([$message], 'database'))
106 ## Check for errors during the send
107 #if ($services.mail.sender.lastError)
108 #displayError($exceptiontool.getStackTrace($services.mail.sender.lastError))
109 #else
110 #set ($failedMailStatuses = $mailResult.statusResult.getAllErrors())
111 #if ($failedMailStatuses.hasNext())
112 #set ($mailStatus = $failedMailStatuses.next())
113 #displayError($mailStatus.errorDescription)
114 #else
115
116 {{info}}$services.localization.render('xe.admin.passwordReset.emailSent', ["$userDoc.display('email', $userObj)"]){{/info}}
117
118 #end
119 #end
120 #end
121 #end
122 #end
123 [[{{translation key="xe.admin.passwordReset.error.retry"/}}>>$doc.fullName]] | [[{{translation key="xe.admin.passwordReset.error.recoverUsername"/}}>>ForgotUsername]] | [[{{translation key="xe.admin.passwordReset.login"/}}>>path:$xwiki.getURL('XWiki.XWikiLogin', 'login')]]
124 #end
125 ## Clear private variables, so that they cannot be accessed from the rest of the page (comments, panels...)
126 #set ($verifStr = '')
127 #set ($passwordResetURL = '')
128 {{/velocity}}
129
130 {{/comment}}
Landesarchiv Baden-Württemberg