Исходный код вики Registration

Версия 1.1 от Полина Герасимова на 20.09.2024

Последние авторы
1 {{velocity}}
2 ## The registration is enabled:
3 ## - on the main wiki
4 ## - on a subwiki if there is no service "$services.wiki.user"
5 ## - on a subwiki where the user scope allows local users
6 #if($xcontext.isMainWiki() || "$!services.wiki.user" == '' || $services.wiki.user.getUserScope() != "GLOBAL_ONLY")
7 ## These are defined in other places around XWiki, changing them here will result in undefined behavior.
8 #set($redirectParam = 'xredirect')
9 #set($userSpace = 'XWiki.')
10 #set($loginPage = 'XWiki.XWikiLogin')
11 #set($loginAction = 'loginsubmit')
12 ##
13 #set($documentName = 'XWiki.Registration')
14 #set($configurationClassName = 'XWiki.Registration')
15 ##
16 ## Security measure:
17 ## If this document is changed such that it must have programming permission in order to run, change this to false.
18 #set($sandbox = true)
19 ##
20 ## Load the configuration from a seperate document.
21 #loadConfig('XWiki.RegistrationConfig')
22 ##
23 ## Defines what server generated error messages should look like
24 ## The error message when a field is entered incorrectly
25 #set($failureMessageParams = { 'class' : 'LV_validation_message LV_invalid'})
26 ## 'LV_validation_message LV_invalid' depends on this:
27 $xwiki.get('ssfx').use('uicomponents/widgets/validation/livevalidation.css', true)
28 ##
29 ## The * next to the fields to denote they are mandatory.
30 #set($fieldMandatoryStar = { 'class' : 'xRequired'})
31 ##
32 #*
33 * You may include this document in other documents using {{include reference="XWiki.Registration"/}}
34 * To specify that the user is invited and should be allowed to register even if Guest does not have permission to
35 * register, set $invited to true. NOTE: The including script must have programming permission to do this.
36 *
37 * To specify some code which should run after registration is successfully completed, set
38 * $doAfterRegistration to a define block of velocity code like so:
39 * #define($doAfterRegistration)
40 * some code
41 * #end
42 * Output from running this code will not be printed.
43 *
44 * The fields which will be seen on the registration page are defined here.
45 * $fields is an array and each field is a Map. The names shown below are Map keys.
46 *
47 * Each field must have:
48 * name - this is the name of the field, it will be the value for "name" and "id"
49 *
50 * Each field may have:
51 * label - this String will be written above the field.
52 *
53 * tag - the HTML tag which will be created, default is <input>, may also be a non form tag such as <img>
54 *
55 * params - a Map, each key value pair will be in the html tag. eg: {"size" : "30"} becomes <input size=30...
56 *
57 * validate a Map describing how to validate the field, validation is done in javascript then redone in velocity
58 * | for security and because not everyone has javascript.
59 * |
60 * +-mandatory (Optional) - Will fail if the field is not filled in.
61 * | +-failureMessage (Required) - The message to display if the field is not filled in.
62 * | +-noscript (Optional) - will not be checked by javascript
63 * |
64 * +-regex (Optional) - Will validate the field using a regular expression.
65 * | | because of character escaping, you must provide a different expression for the
66 * | | javascript validation and the server side validation. Both javascript and server side
67 * | | validation are optional, but if you provide neither, then your field will not be validated.
68 * | |
69 * | +-failureMessage (Optional) - The message to display if the regex evaluation returns false.
70 * | +-jsFailureMessage (Optional) - The message for Javascript to display if regex fails.
71 * | | If jsFailureMessage is not defined Javascript uses failureMessage.
72 * | | NOTE: Javascript injects the failure message using createTextNode so &lt; will
73 * | | be displayed as &lt;
74 * | |
75 * | +-pattern (Optional) - The regular expression to test the input at the server side, it's important to use
76 * | | this if you need to validate the field for security reasons, also it is good because not
77 * | | all browsers use javascript or have it enabled.
78 * | |
79 * | +-jsPattern (Optional) - The regular expression to use for client side, you can use escaped characters to avoid
80 * | | them being parsed as HTML or javascript. To get javascript to unescape characters use:
81 * | | {"jsPattern" : "'+unescape('%5E%5B%24')+'"}
82 * | | NOTE: If no jsPattern is specified, the jsValidator will try to validate
83 * | | using the server pattern.
84 * | |
85 * | +-noscript (Optional) - will not be checked by javascript
86 * |
87 * +-mustMatch (Optional) - Will fail if the entry into the field is not the same as the entry in another field.
88 * | | Good for password confirmation.
89 * | |
90 * | +-failureMessage (Required) - The message to display if the field doesn't match the named field.
91 * | +-name (Required) - The name of the field which this field must match.
92 * | +-noscript (Optional) - will not be checked by javascript
93 * |
94 * +-programmaticValidation (Optional) - This form of validation executes a piece of code which you give it and
95 * | | if the code returns the word "failed" then it gives the error message.
96 * | | Remember to put the code in singel quotes ('') because you want the value
97 * | | of 'code' to equal the literal code, not the output from running it.
98 * | |
99 * | +-code (Required) - The code which will be executed to test whether the field is filled in correctly.
100 * | +-failureMessage (Required) - The message which will be displayed if evaluating the code returns "false"
101 * |
102 * +-fieldOkayMessage (Optional) - The message which is displayed by LiveValidation when a field is validated as okay.
103 * If not specified, will be $defaultFieldOkayMessage
104 *
105 * noReturn - If this is specified, the field will not be filled in if there is an error and the user has to fix their
106 * registration information. If you don't want a password to be passed back in html then set this true
107 * for the password fields. Used for the captcha because it makes no sense to pass back a captcha answer.
108 *
109 * doAfterRegistration - Some Velocity code which will be executed after a successfull registration.
110 * This is used in the favorite color example.
111 * Remember to put the code in singel quotes ('') because you want the 'code' entry to equal the literal
112 * code, not the output from running it.
113 *
114 * Each field may not have: (reserved names)
115 * error - This is used to pass back any error message from the server side code.
116 *
117 * NOTE: This template uses a registration method which requires:
118 * * register_first_name
119 * * register_last_name
120 * * xwikiname
121 * * register_password
122 * * register2_password
123 * * register_email
124 * * template
125 * Removing or renaming any of these fields will result in undefined behavior.
126 *
127 *###
128 #set($fields = [])
129 ##
130 ## The first name field, no checking.
131 #set($field =
132 {'name' : 'register_first_name',
133 'label' : $services.localization.render('core.register.firstName'),
134 'params' : {
135 'type' : 'text',
136 'size' : '60'
137 }
138 })
139 #set($discard = $fields.add($field))
140 ##
141 ## The last name field, no checking.
142 #set($field =
143 {'name' : 'register_last_name',
144 'label' : $services.localization.render('core.register.lastName'),
145 'params' : {
146 'type' : 'text',
147 'size' : '60'
148 }
149 })
150 #set($discard = $fields.add($field))
151 ##
152 ## The user name field, mandatory and programmatically checked to make sure the username doesn't exist.
153 #set($field =
154 {'name' : 'xwikiname',
155 'label' : $services.localization.render('core.register.username'),
156 'params' : {
157 'type' : 'text',
158 'onfocus' : 'prepareName(document.forms.register);',
159 'size' : '60'
160 },
161 'validate' : {
162 'mandatory' : {
163 'failureMessage' : $services.localization.render('core.validation.required.message')
164 },
165 'programmaticValidation' : {
166 'code' : '#nameAvailable($request.get("xwikiname"))',
167 'failureMessage' : $services.localization.render('core.register.userAlreadyExists')
168 }
169 }
170 })
171 #set($discard = $fields.add($field))
172 ## Make sure the chosen user name is not already taken
173 ## This macro is called by programmaticValidation for xwikiname (above)
174 #macro(nameAvailable, $name)
175 #if($xwiki.exists("$userSpace$name"))
176 failed
177 #end
178 #end
179 ##
180 ##The password field, mandatory and must be at least 6 characters long.
181 #set($field =
182 {'name' : 'register_password',
183 'label' : $services.localization.render('core.register.password'),
184 'params' : {
185 'type' : 'password',
186 'autocomplete' : 'off',
187 'size' : '60'
188 },
189 'validate' : {
190 'mandatory' : {
191 'failureMessage' : $services.localization.render('core.validation.required.message')
192 },
193 'regex' : {
194 'pattern' : '/.{6,}/',
195 'failureMessage' : $services.localization.render('xe.admin.registration.passwordTooShort')
196 }
197 }
198 })
199 #set($discard = $fields.add($field))
200 ##
201 ##The confirm password field, mandatory, must match password field, and must also be 6+ characters long.
202 #set($field =
203 {'name' : 'register2_password',
204 'label' : $services.localization.render('core.register.passwordRepeat'),
205 'params' : {
206 'type' : 'password',
207 'autocomplete' : 'off',
208 'size' : '60'
209 },
210 'validate' : {
211 'mandatory' : {
212 'failureMessage' : $services.localization.render('core.validation.required.message')
213 },
214 'mustMatch' : {
215 'name' : 'register_password',
216 'failureMessage' : $services.localization.render('xe.admin.registration.passwordMismatch')
217 },
218 'regex' : {
219 'pattern' : '/.{6,}/',
220 'failureMessage' : $services.localization.render('xe.admin.registration.passwordTooShort')
221 }
222 }
223 })
224 #set($discard = $fields.add($field))
225 ##
226 ## The email address field, regex checked with an email pattern. Mandatory if registration uses email verification
227 #set($field =
228 {'name' : 'register_email',
229 'label' : $services.localization.render('core.register.email'),
230 'params' : {
231 'type' : 'text',
232 'size' : '60'
233 },
234 'validate' : {
235 'regex' : {
236 'pattern' : '/^([^@\s]+)@((?:[-a-zA-Z0-9]+\.)+[a-zA-Z]{2,})$/',
237 'failureMessage' : $services.localization.render('xe.admin.registration.invalidEmail')
238 }
239 }
240 })
241 #if($xwiki.getXWikiPreferenceAsInt('use_email_verification', 0) == 1)
242 #set($field.validate.mandatory = {'failureMessage' : $services.localization.render('core.validation.required.message')})
243 #end
244 #set($discard = $fields.add($field))
245 ##
246 #*********
247 ## Uncomment this code to see an example of how you can easily add a field to the registration page
248 ## NOTE: In order to save the favorite color in the "doAfterRegistration" hook, this page must be
249 ## saved by an administrator and can not self sandboxing.
250 #set($sandbox = false)
251 #set($field =
252 {'name' : 'favorite_color',
253 'label' : 'What is your favorite color',
254 'params' : {
255 'type' : 'text',
256 'size' : '60'
257 },
258 'validate' : {
259 'mandatory' : {
260 'failureMessage' : $services.localization.render('core.validation.required.message')
261 },
262 'regex' : {
263 'pattern' : '/^green$/',
264 'failureMessage' : 'You are not cool enough to register here.'
265 },
266 'fieldOkayMessage' : 'You are awesome.'
267 },
268 'doAfterRegistration' : '#saveFavoriteColor()'
269 })
270 #set($discard = $fields.add($field))
271 ## Save the user's favorite color on their user page.
272 #macro(saveFavoriteColor)
273 #set($xwikiname = $request.get('xwikiname'))
274 #set($userDoc = $xwiki.getDocument("$userSpace$xwikiname"))
275 $userDoc.setContent("$userDoc.getContent() ${xwikiname}'s favorite color is $request.get('favorite_color')!")
276 ## The user (who is not yet logged in) can't save documents so saveWithProgrammingRights
277 ## will save the document as long as the user who last saved this registration page has programming rights.
278 $userDoc.saveWithProgrammingRights("Saved favorite color from registration form.")
279 #end
280 *********###
281 ##
282 ## To disable the CAPTCHA on this page, comment out the next entry.
283 ## The CAPTCHA, not really an input field but still defined the same way.
284 #if($services.captcha
285 && !$invited
286 && $xcontext.getUser() == "XWiki.XWikiGuest"
287 && $requireCaptcha)
288 ## The CAPTCHA field, programmatically checked to make sure the CAPTCHA is right.
289 ## Not checked by javascript because javascript can't check the CAPTCHA and the Ok message because it passes the
290 ## mandatory test is misleading.
291 ## Also, not filled back in if there is an error ('noReturn').
292 #set($field =
293 {'name' : 'captcha_placeholder',
294 'label' : $services.localization.render('core.captcha.instruction'),
295 'skipLabelFor' : true,
296 'type' : 'html',
297 'html' : "$!{services.captcha.default.display()}",
298 'validate' : {
299 'programmaticValidation' : {
300 'code' : '#if (!$services.captcha.default.isValid())failed#end',
301 'failureMessage' : $services.localization.render('core.captcha.captchaAnswerIsWrong')
302 }
303 },
304 'noReturn' : true
305 })
306 #set($discard = $fields.add($field))
307 #end
308 ##
309 ## Pass the name of the template to $xwiki.createUser so any contained information will be passed in.
310 #set($field =
311 {'name' : 'template',
312 'params' : {
313 'type' : 'hidden',
314 'value' : 'XWiki.XWikiUserTemplate'
315 }
316 })
317 #set($discard = $fields.add($field))
318 ##
319 ## Pass the redirect parameter on so that the login page may redirect to the right place.
320 ## Not necessary in Firefox 3.0.10 or Opera 9.64, I don't know about IE or Safari.
321 #set($field =
322 {'name' : $redirectParam,
323 'params' : {
324 'type' : 'hidden'
325 }
326 })
327 #set($discard = $fields.add($field))
328 ##
329 #######################################################################
330 ## The Code.
331 #######################################################################
332 ##
333 #if($useLiveValidation)
334 $xwiki.get('jsfx').use('uicomponents/widgets/validation/livevalidation_prototype.js')
335 $xwiki.get('ssfx').use('uicomponents/widgets/validation/livevalidation.css', true)
336 #end
337 ## This application's HTML is dynamically generated and editing in WYSIWYG would not work
338 #if($xcontext.getAction() == 'edit')
339 $response.sendRedirect("$xwiki.getURL($doc.getFullName(), 'edit')?editor=wiki")
340 #end
341 ##
342 ## If this document has PR and is not included from another document then it's author should be set to Guest
343 ## for the duration of it's execution in order to improve security.
344 ## Note we compare document ids because
345 #if($sandbox
346 && $xcontext.hasProgrammingRights()
347 && $xcontext.getDoc().getDocumentReference().equals($xwiki.getDocument($documentName).getDocumentReference()))
348 ##
349 $xcontext.dropPermissions()##
350 #end
351 ##
352 ## Access level to register must be explicitly checked because it is only checked in XWiki.prepareDocuments
353 ## and this page is accessible through view action.
354 #if(!$xcontext.hasAccessLevel('register', 'XWiki.XWikiPreferences'))
355 ## Make an exception if another document with programming permission (Invitation app) has included this
356 ## document and set $invited to true.
357 #if(!$invited || !$xcontext.hasProgrammingRights())
358 $response.sendRedirect("$xwiki.getURL($doc.getFullName(), 'login')")
359 #end
360 #end
361 ##
362 ## Display the heading
363 $heading
364 ## If the submit button has been pressed, then we test the input and maybe create the user.
365 #if($request.getParameter('xwikiname'))
366 ## Do server side validation of input fields.
367 ## This must not be in a #set directive as it will output messages if something goes wrong.
368 #validateFields($fields, $request)
369 ## If server side validation was successfull, create the user
370 #if(!$registrationFailed)
371 #createUser($fields, $request, $response, $doAfterRegistration)
372 #end
373 #end
374 ## If the registration was not successful or if the user hasn't submitted the info yet
375 ## Then we display the registration form.
376 #if(!$registrationDone)
377 $welcomeMessage
378
379 {{html clean="false"}}
380 <form id="register" action="$xwiki.relativeRequestURL" method="post" class="xform half">
381 <div class="hidden">
382 #if ($request.xpage == 'registerinline')
383 #skinExtensionHooks
384 #end
385 <input type="hidden" name="form_token" value="$!{services.csrf.getToken()}" />
386 #set ($userDirectoryReference = $services.model.createDocumentReference('', 'Main', 'UserDirectory'))
387 #if ($xwiki.exists($userDirectoryReference))
388 <input type="hidden" name="parent" value="$!{services.model.serialize($userDirectoryReference, 'default')}" />
389 #end
390 </div>
391 #generateHtml($fields, $fieldMandatoryStar, $failureMessageParams)
392 <p class="buttons">
393 <span class="buttonwrapper">
394 <input type="submit" value="$services.localization.render('core.register.submit')" class="button"/>
395 </span>
396 </p>
397 #if ($useLiveValidation)
398 #generateJavascript($fields)
399 #end
400 </form>
401 {{/html}}
402
403 ##
404 ## Allow permitted users to configure this application.
405 #if($xcontext.getUser() != 'XWiki.XWikiGuest' && $xcontext.hasAccessLevel("edit", $documentName))
406 [[{{translation key="xe.admin.registration.youCanConfigureRegistrationHere"/}}>>XWiki.XWikiPreferences?section=Registration&editor=globaladmin#HCustomizeXWikiRegistration]]
407 {{html}}<a href="$xwiki.getURL($documentName, 'edit', 'editor=wiki')">$services.localization.render('xe.admin.registration.youCanConfigureRegistrationFieldsHere')</a>{{/html}}
408 #end
409 #end
410 #else
411 ## The registration is not allowed on the subwiki
412 ## Redirecting to main wiki's registration page since local user registration is not allowed.
413 #set($mainWikiRegisterPageReference = $services.model.createDocumentReference($services.wiki.mainWikiId, 'XWiki', 'Register'))
414 #set($temp = $response.sendRedirect($xwiki.getURL($mainWikiRegisterPageReference, 'register', $request.queryString)))
415 #end
416 ##
417 ####### The Macros (nothing below this point is run directly) #########
418 #*
419 * Server side validation, this is necessary for security and because not everyone has Javascript
420 *
421 * @param $fields The array of fields to validate.
422 * @param $request An XWikiRequest object which made the register request, used to get parameters.
423 *###
424 #macro(validateFields, $fields, $request)
425 #foreach($field in $fields)
426 #if($field.get('validate') && $field.get('name'))
427 #set($fieldName = $field.get('name'))
428 #set($validate = $field.get('validate'))
429 #set($error = '')
430 #set($value = $request.get($fieldName))
431 #if("$!value" != '' || $field.get('type') == 'html')
432 ##
433 ## mustMatch validation
434 #if($error == '' && $validate.get('mustMatch'))
435 #set($mustMatch = $validate.get('mustMatch'))
436 #if($mustMatch.get('name') && $mustMatch.get('failureMessage'))
437 #if($request.get($fieldName) != $request.get($mustMatch.get('name')))
438 #set($error = $mustMatch.get('failureMessage'))
439 #end
440 #else
441 ERROR: In field: ${fieldName}: mustMatch validation required both name
442 (of field which this field must match) and failureMessage.
443 #end
444 #end
445 ##
446 ## Regex validation
447 ## We won't bother with regex validation if there is no entry, that would defeat the purpose of 'mandatory'
448 #if($error == '' && $validate.get('regex') && $value && $value != '')
449 #set($regex = $validate.get('regex'))
450 #if($regex.get('pattern') && $regex.get('failureMessage'))
451 ## Make Java regexes more compatible with Perl/js style regexes by removing leading and trailing /
452 #if($regex.get('pattern').length() > 1)
453 #set($pattern = $regex.get('pattern'))
454 #if($pattern.lastIndexOf('/') < $pattern.length() - 1)
455 ERROR: In field: ${fieldName}: regex validation does not allow flags after the /, please fix [${pattern}].
456 #end
457 #set($pattern = $pattern.substring($mathtool.add(1, $pattern.indexOf('/')), $pattern.lastIndexOf('/')))
458 #else
459 ## I don't expect this but want to maintain compatibility.
460 #set($pattern = $regex.get('pattern'))
461 #end
462 #if($regextool.find($value, $pattern).isEmpty())
463 #set($error = $regex.get('failureMessage'))
464 #end
465 #elseif($regex.get('pattern'))
466 ERROR: In field: ${fieldName}: regex validation must include failureMessage.
467 #end
468 #end
469 ##
470 ## If regex and mustMatch validation passed, try programmatic validation
471 #if($error == '' && $validate.get('programmaticValidation'))
472 #set($pv = $validate.get('programmaticValidation'))
473 #if($pv.get('code') && $pv.get('failureMessage'))
474 #set($pvReturn = "#evaluate($pv.get('code'))")
475 #if($pvReturn.indexOf('failed') != -1)
476 #set($error = $pv.get('failureMessage'))
477 #end
478 #else
479 ERROR: In field: ${fieldName}: programmaticValidation requires code and failureMessage
480 #end
481 #end
482 #else
483 ##
484 ## If no content, check if content is mandatory
485 #if($validate.get('mandatory'))
486 #set($mandatory = $validate.get('mandatory'))
487 #if($mandatory.get('failureMessage'))
488 #set($error = $mandatory.get('failureMessage'))
489 #else
490 ERROR: In field: ${fieldName}: mandatory validation requires a failureMessage
491 #end
492 #end
493 #end
494 #if($error != '')
495 #set($discard = $field.put('error', $error))
496 #set($registrationFailed = true)
497 #end
498 #elseif(!$field.get('name'))
499 ERROR: Field with no name.
500 #end##if(validate)
501 #end##loop
502 #end##macro
503 #*
504 * Create the user.
505 * Calls $xwiki.createUser to create a new user.
506 *
507 * @param $request An XWikiRequest object which made the register request.
508 * @param $response The XWikiResponse object to send any redirects to.
509 * @param $doAfterRegistration code block to run after registration completes successfully.
510 *###
511 #macro(createUser, $fields, $request, $response, $doAfterRegistration)
512 ## CSRF check
513 #if(${services.csrf.isTokenValid("$!{request.getParameter('form_token')}")})
514 ## See if email verification is required and register the user.
515 #if($xwiki.getXWikiPreferenceAsInt('use_email_verification', 0) == 1)
516 #set($reg = $xwiki.createUser(true))
517 #else
518 #set($reg = $xwiki.createUser(false))
519 #end
520 #else
521 $response.sendRedirect("$!{services.csrf.getResubmissionURL()}")
522 #end
523 ##
524 ## Handle output from the registration.
525 #if($reg && $reg <= 0)
526 {{error}}
527 #if($reg == -2)
528 {{translation key="core.register.passwordMismatch"/}}
529 ## -3 means username taken, -8 means username is superadmin name
530 #elseif($reg == -3 || $reg == -8)
531 {{translation key="core.register.userAlreadyExists"/}}
532 #elseif($reg == -4)
533 {{translation key="core.register.invalidUsername"/}}
534 #elseif($reg == -11)
535 {{translation key="core.register.mailSenderWronglyConfigured"/}}
536 #else
537 {{translation key="core.register.registerFailed" parameters="$reg"/}}
538 #end
539 {{/error}}
540 #elseif($reg)
541 ## Registration was successful
542 #set($registrationDone = true)
543 ##
544 ## If there is any thing to "doAfterRegistration" then do it.
545 #foreach($field in $fields)
546 #if($field.get('doAfterRegistration'))
547 #evaluate($field.get('doAfterRegistration'))
548 #end
549 #end
550 ## If there is a "global" doAfterRegistration, do that as well.
551 ## Calling toString() on a #define block will execute it and we discard the result.
552 #set($discard = $doAfterRegistration.toString())
553 ##
554 ## Define some strings which may be used by autoLogin or loginButton
555 #set($userName = $!request.get('xwikiname'))
556 #set($password = $!request.get('register_password'))
557 #set($loginURL = $xwiki.getURL($loginPage, $loginAction))
558 #if("$!request.getParameter($redirectParam)" != '')
559 #set($redirect = $request.getParameter($redirectParam))
560 #else
561 #set($redirect = $defaultRedirect)
562 #end
563 ## Display a "registration successful" message
564
565 #evaluate($registrationSuccessMessage)
566
567 ## Empty line prevents message from being forced into a <p> block.
568
569 ## Give the user a login button which posts their username and password to loginsubmit
570 #if($loginButton)
571
572 {{html clean=false wiki=false}}
573 <form id="loginForm" action="$loginURL" method="post">
574 <div class="centered">
575 <input type="hidden" name="form_token" value="$!{services.csrf.getToken()}" />
576 <input id="j_username" name="j_username" type="hidden" value="$escapetool.xml($!userName)" />
577 <input id="j_password" name="j_password" type="hidden" value="$escapetool.xml($!password)" />
578 <input id="$redirectParam" name="$redirectParam" type="hidden" value="$escapetool.xml($redirect)" />
579 <span class="buttonwrapper">
580 <input type="submit" value="$services.localization.render('login')" class="button"/>
581 </span>
582 </div>
583 </form>
584 ## We don't want autoLogin if we are administrators adding users...
585 #if ($autoLogin && $request.xpage != 'registerinline')
586 <script type='text/javascript'>
587 document.observe('xwiki:dom:loaded', function() {
588 document.forms['loginForm'].submit();
589 });
590 </script>
591 #end
592 {{/html}}
593
594 #end
595 #end
596 ##
597 #end## createUser Macro
598 #*
599 * Generate HTML form, this is the only place where HTML is written.
600 *
601 * @param $fields The array of fields to use for generating html code.
602 * @param $fieldMandatoryStar The tag parameters for a * indicating a mandatory field.
603 * @param $failureMessageParams The tag parameters for a failure message.
604 *###
605 #macro(generateHtml, $fields, $fieldMandatoryStar, $failureMessageParams)
606 ## Put the same values back into the fields.
607 #getParams($fields)
608 ##
609 <dl>
610 #foreach($field in $fields)
611 #if($field.get('name'))
612 #set($fieldName = $field.get('name'))
613 #if($field.get('label'))
614 #set($label = $field.get('label'))
615 <dt><label #if (!$field.get('skipLabelFor'))for="$fieldName"#end>$label
616 #if($field.get('validate').get('mandatory'))
617 <span ##
618 #foreach($entry in $fieldMandatoryStar.entrySet())
619 $entry.getKey()="$entry.getValue()" ##
620 #end
621 >$services.localization.render('core.validation.required')</span>
622 #end
623 </label>
624 </dt>
625 #end
626 <dd>
627 #if ($field.get('type') == 'html')
628 $field.get('html')
629 #elseif ($field.get('type') == 'tag' || "$!{field.get('type')}" == '')
630 ## If no tag then default tag is <input>
631 #if($field.get('tag'))
632 #set($tag = $field.get('tag'))
633 #else
634 #set($tag = 'input')
635 #end
636 <$tag id="$fieldName" ##
637 #set($params = $field.get('params'))
638 ## If no name parameter is spacified, then we use the field name
639 #if(!$params.get('name'))
640 #set($discard = $params.put('name', $fieldName))
641 #end
642 #foreach($entry in $params.entrySet())
643 ## If a parameter is specified as '' then we don't include it.
644 #if($entry.getValue() != '')
645 $entry.getKey()="$escapetool.xml($entry.getValue())" ##
646 #end
647 #end
648 ## Close the opened tag in a way that is valid for its type (i.e. with "/>" or with "></tag>").
649 #if ($tag == 'input')
650 #set ($voidTag = true)
651 #end
652 #if ($voidTag)/#end>#if (!$voidTag)</$tag>#end
653 #end
654 #if($field.get('error'))
655 <span ##
656 #foreach($entry in $failureMessageParams.entrySet())
657 $entry.getKey()="$entry.getValue()" ##
658 #end
659 >$field.get('error')</span>
660 #end
661 </dd>
662 #else
663 ERROR: Field with no name.
664 #end##if fieldName exists
665 #end
666 </dl>
667 #end
668 #*
669 * Generate the Javascript for interacting with LiveValidation.
670 *
671 * @param $fields The array of fields which to validate.
672 *###
673 #macro(generateJavascript, $fields)
674 <script type='text/javascript'>
675 /* <![CDATA[ */
676 var initRegistrationFormValidation = function() {
677 ##
678 #foreach($field in $fields)
679 #if($field.get('validate') && $field.get('name'))
680 #set($validate = $field.get('validate'))
681 #if(($validate.get('mandatory') && !$validate.get('mandatory').get('noscript'))
682 || ($validate.get('regex') && !$validate.get('regex').get('noscript'))
683 || ($validate.get('mustMatch') && !$validate.get('mustMatch').get('noscript')))
684 #set($fieldName = $field.get('name'))
685 #if($validate.get('fieldOkayMessage'))
686 #set($okayMessage = $validate.get('fieldOkayMessage'))
687 #else
688 #set($okayMessage = $defaultFieldOkayMessage)
689 #end
690 var ${fieldName}Validator = new LiveValidation("$fieldName", { validMessage: "$okayMessage", wait: 500} );
691 ##
692 #if($validate.get('mandatory'))
693 #set($mandatory = $validate.get('mandatory'))
694 #if($mandatory.get('failureMessage') && !$mandatory.get('noscript'))
695 ${fieldName}Validator.add( Validate.Presence, { failureMessage: "$!mandatory.get('failureMessage')"} );
696 #end
697 #end
698 ##
699 #if($validate.get('mustMatch'))
700 #set($mustMatch = $validate.get('mustMatch'))
701 #if($mustMatch.get('name') && $mustMatch.get('failureMessage') && !$mustMatch.get('noscript'))
702 ${fieldName}Validator.add( Validate.Confirmation, { match: $$("input[name=$!mustMatch.get('name')]")[0], failureMessage: "$!mustMatch.get('failureMessage')"} );
703 #end
704 #end
705 ##
706 #if($validate.get('regex'))
707 #set($regex = $validate.get('regex'))
708 #set($pattern = "")
709 #if($regex.get('jsPattern'))
710 #set($pattern = $regex.get('jsPattern'))
711 #elseif($regex.get('pattern'))
712 #set($pattern = $regex.get('pattern'))
713 #end
714 #set($failMessage = "")
715 #if($regex.get('jsFailureMessage'))
716 #set($failMessage = $regex.get('jsFailureMessage'))
717 #elseif($regex.get('failureMessage'))
718 #set($failMessage = $regex.get('failureMessage'))
719 #end
720 #if($pattern != '' && $failMessage != '' && !$regex.get('noscript'))
721 ${fieldName}Validator.add( Validate.Format, { pattern: $pattern, failureMessage: "$failMessage"} );
722 #end
723 #end##if regex
724 #end##if contains js validateable fields.
725 #end##if validate
726 #end##loop
727 };
728 document.observe('xwiki:dom:loaded', initRegistrationFormValidation);
729 document.observe('xwiki:dom:updated', function(event) {
730 var container = (event && event.memo && event.memo.elements && event.memo.elements[0]) || $('body');
731 if (container.down('form#register')) {
732 initRegistrationFormValidation();
733 }
734 });// ]]>
735 </script>
736 #end##macro
737 #*
738 * Get parameters from request so that values will be filled in if there is a mistake
739 * in one of the entries. Entries will be returned to fields[n].params.value
740 * Fields will not be returned if they have either noReturn or error specified.
741 *
742 * @param $fields The array of fields to get parameters for.
743 *###
744 #macro(getParams $fields)
745 #foreach($field in $fields)
746 #if($field.get('name') && $request.get($field.get('name')))
747 #if(!$field.get('noReturn') && !$field.get('error'))
748 #if(!$field.get('params'))
749 #set($params = {})
750 #set($discard = $field.put('params', $params))
751 #else
752 #set($params = $field.get('params'))
753 #end
754 #set($discard = $params.put('value', $request.get($field.get('name'))))
755 #end
756 #end
757 #end
758 #end
759 #*
760 * Get the configuration from the configuration object.
761 *
762 * @param $configDocumentName The name of the document to get the configuration from.
763 *###
764 #macro(loadConfig, $configDocumentName)
765 #set($configDocument = $xwiki.getDocument($configDocumentName))
766 #if(!$configDocument || !$configDocument.getObject($configurationClassName))
767 ## No config document, load defaults.
768 #set($heading = "$services.localization.render('core.register.title')")
769 #set($welcomeMessage = "$services.localization.render('core.register.welcome')")
770 #set($useLiveValidation = true)
771 #set($defaultFieldOkayMessage = "$services.localization.render('core.validation.valid.message')")
772 #set($loginButton = true)
773 #set($defaultRedirect = "$xwiki.getURL($services.model.resolveDocument('', 'default', $doc.documentReference.extractReference('WIKI')))")
774 #set($userFullName = "$request.get('register_first_name') $request.get('register_last_name')")
775 #set($registrationSuccessMessage = '{{info}}$services.localization.render("core.register.successful", ["[[${userFullName}>>${userSpace}${userName}]]", ${userName}]){{/info}}')
776 #else
777 #set($configObject = $configDocument.getObject($configurationClassName))
778 #if ($xcontext.action == 'register')
779 #set ($heading = "(% id='document-title'%)((( = #evaluate($configObject.getProperty('heading').getValue()) = )))(%%)")
780 #else
781 #set ($heading = "= #evaluate($configObject.getProperty('heading').getValue()) =")
782 #end
783 #set($welcomeMessage = "#evaluate($configObject.getProperty('welcomeMessage').getValue())")
784 #if($configObject.getProperty('liveValidation_enabled').getValue() == 1)
785 #set($useLiveValidation = true)
786 #end
787 #set($defaultFieldOkayMessage = "#evaluate($configObject.getProperty('liveValidation_defaultFieldOkMessage').getValue())")
788 #if($configObject.getProperty('loginButton_enabled').getValue() == 1)
789 #set($loginButton = true)
790 #end
791 #if($configObject.getProperty('loginButton_autoLogin_enabled').getValue() == 1)
792 #set($autoLogin = true)
793 #end
794 #set($defaultRedirect = "#evaluate($configObject.getProperty('defaultRedirect').getValue())")
795 #set($registrationSuccessMessage = "$configObject.getProperty('registrationSuccessMessage').getValue()")
796 #if($configObject.getProperty('requireCaptcha').getValue() == 1)
797 #set($requireCaptcha = true)
798 #end
799 #end
800 #end
801 {{/velocity}}