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