Changes for page Registration

Last modified by John Stroy [Xino] on 2014/01/03 03:52

From version Icon 8.1 Icon
edited by John Stroy
on 2012/11/04 04:42
Change comment: Rollback to version 1.1
To version Icon 9.1 Icon
edited by John Stroy [Xino]
on 2013/09/18 03:58
Change comment: Import

Summary

Details

Icon Page properties
Author
... ... @@ -1,1 +1,1 @@
1 -XWiki.jdstroy
1 +xwiki:XWiki.xino
Hidden
... ... @@ -1,1 +1,1 @@
1 -false
1 +true
Content
... ... @@ -18,7 +18,7 @@
18 18  ## The error message when a field is entered incorrectly
19 19  #set($failureMessageParams = { 'class' : 'LV_validation_message LV_invalid'})
20 20  ## 'LV_validation_message LV_invalid' depends on this:
21 -$xwiki.get('ssfx').use('uicomponents/widgets/validation/livevalidation.css')
21 +$xwiki.get('ssfx').use('uicomponents/widgets/validation/livevalidation.css', true)
22 22  ##
23 23  ## The * next to the fields to denote they are mandatory.
24 24  #set($fieldMandatoryStar = { 'class' : 'xRequired'})
... ... @@ -124,7 +124,7 @@
124 124  ## The first name field, no checking.
125 125  #set($field =
126 126   {'name' : 'register_first_name',
127 - 'label' : $msg.get('core.register.firstName'),
127 + 'label' : $services.localization.render('core.register.firstName'),
128 128   'params' : {
129 129   'type' : 'text',
130 130   'size' : '60'
... ... @@ -135,7 +135,7 @@
135 135  ## The last name field, no checking.
136 136  #set($field =
137 137   {'name' : 'register_last_name',
138 - 'label' : $msg.get('core.register.lastName'),
138 + 'label' : $services.localization.render('core.register.lastName'),
139 139   'params' : {
140 140   'type' : 'text',
141 141   'size' : '60'
... ... @@ -146,7 +146,7 @@
146 146  ## The user name field, mandatory and programmatically checked to make sure the username doesn't exist.
147 147  #set($field =
148 148   {'name' : 'xwikiname',
149 - 'label' : $msg.get('core.register.username'),
149 + 'label' : $services.localization.render('core.register.username'),
150 150   'params' : {
151 151   'type' : 'text',
152 152   'onfocus' : 'prepareName(document.forms.register);',
... ... @@ -154,11 +154,11 @@
154 154   },
155 155   'validate' : {
156 156   'mandatory' : {
157 - 'failureMessage' : $msg.get('core.validation.required.message')
157 + 'failureMessage' : $services.localization.render('core.validation.required.message')
158 158   },
159 159   'programmaticValidation' : {
160 160   'code' : '#nameAvailable($request.get("xwikiname"))',
161 - 'failureMessage' : $msg.get('core.register.userAlreadyExists')
161 + 'failureMessage' : $services.localization.render('core.register.userAlreadyExists')
162 162   }
163 163   }
164 164   })
... ... @@ -174,18 +174,19 @@
174 174  ##The password field, mandatory and must be at least 6 characters long.
175 175  #set($field =
176 176   {'name' : 'register_password',
177 - 'label' : $msg.get('core.register.password'),
177 + 'label' : $services.localization.render('core.register.password'),
178 178   'params' : {
179 179   'type' : 'password',
180 + 'autocomplete' : 'off',
180 180   'size' : '60'
181 181   },
182 182   'validate' : {
183 183   'mandatory' : {
184 - 'failureMessage' : $msg.get('core.validation.required.message')
185 + 'failureMessage' : $services.localization.render('core.validation.required.message')
185 185   },
186 186   'regex' : {
187 187   'pattern' : '/.{6,}/',
188 - 'failureMessage' : $msg.get('xe.admin.registration.passwordTooShort')
189 + 'failureMessage' : $services.localization.render('xe.admin.registration.passwordTooShort')
189 189   }
190 190   }
191 191   })
... ... @@ -194,22 +194,23 @@
194 194  ##The confirm password field, mandatory, must match password field, and must also be 6+ characters long.
195 195  #set($field =
196 196   {'name' : 'register2_password',
197 - 'label' : $msg.get('core.register.passwordRepeat'),
198 + 'label' : $services.localization.render('core.register.passwordRepeat'),
198 198   'params' : {
199 199   'type' : 'password',
201 + 'autocomplete' : 'off',
200 200   'size' : '60'
201 201   },
202 202   'validate' : {
203 203   'mandatory' : {
204 - 'failureMessage' : $msg.get('core.validation.required.message')
206 + 'failureMessage' : $services.localization.render('core.validation.required.message')
205 205   },
206 206   'mustMatch' : {
207 207   'name' : 'register_password',
208 - 'failureMessage' : $msg.get('xe.admin.registration.passwordMismatch')
210 + 'failureMessage' : $services.localization.render('xe.admin.registration.passwordMismatch')
209 209   },
210 210   'regex' : {
211 211   'pattern' : '/.{6,}/',
212 - 'failureMessage' : $msg.get('xe.admin.registration.passwordTooShort')
214 + 'failureMessage' : $services.localization.render('xe.admin.registration.passwordTooShort')
213 213   }
214 214   }
215 215   })
... ... @@ -218,7 +218,7 @@
218 218  ## The email address field, regex checked with an email pattern.
219 219  #set($field =
220 220   {'name' : 'register_email',
221 - 'label' : $msg.get('core.register.email'),
223 + 'label' : $services.localization.render('core.register.email'),
222 222   'params' : {
223 223   'type' : 'text',
224 224   'size' : '60'
... ... @@ -226,14 +226,17 @@
226 226   'validate' : {
227 227   'regex' : {
228 228   'pattern' : '/^([^@\s]+)@((?:[-a-zA-Z0-9]+\.)+[a-zA-Z]{2,})$/',
229 - 'failureMessage' : $msg.get('xe.admin.registration.invalidEmail')
231 + 'failureMessage' : $services.localization.render('xe.admin.registration.invalidEmail')
230 230   }
231 231   }
232 232   })
233 233  #set($discard = $fields.add($field))
234 234  ##
235 -#* ## Uncomment this code to see an example of how you can easily add a field to the registration page
236 -## Note: The user's favorite color is not saved anywhere, see above for information on how to save it.
237 +#*********
238 +## Uncomment this code to see an example of how you can easily add a field to the registration page
239 +## NOTE: In order to save the favorite color in the "doAfterRegistration" hook, this page must be
240 +## saved by an administrator and can not self sandboxing.
241 +#set($sandbox = false)
237 237  #set($field =
238 238   {'name' : 'favorite_color',
239 239   'label' : 'What is your favorite color',
... ... @@ -243,10 +243,10 @@
243 243   },
244 244   'validate' : {
245 245   'mandatory' : {
246 - 'failureMessage' : $msg.get('core.validation.required.message')
251 + 'failureMessage' : $services.localization.render('core.validation.required.message')
247 247   },
248 248   'regex' : {
249 - 'pattern' : '/^green$/i',
254 + 'pattern' : '/^green$/',
250 250   'failureMessage' : 'You are not cool enough to register here.'
251 251   },
252 252   'fieldOkayMessage' : 'You are awesome.'
... ... @@ -263,7 +263,8 @@
263 263   ## will save the document as long as the user who last saved this registration page has programming rights.
264 264   $userDoc.saveWithProgrammingRights("Saved favorite color from registration form.")
265 265  #end
266 -## *###
271 +*********###
272 +##
267 267  ## To disable the captcha on this page, comment out the next two entries.
268 268  ## The captcha image, not an input field but still defined the same way.
269 269  #if($captchaservice
... ... @@ -274,11 +274,11 @@
274 274   ## Empty 'name' field overriddes name="captcha_image" with "" so name is not specified at all.
275 275   #set($field =
276 276   {'name' : 'captcha_image',
277 - 'label' : "<span class='hidden'>$msg.get('core.captcha.image.label')</span>",
283 + 'label' : "<span class='hidden'>$services.localization.render('core.captcha.image.label')</span>",
278 278   'tag' : 'img',
279 279   'params' : {
280 280   'src' : $doc.getURL('imagecaptcha'),
281 - 'alt' : $msg.get('core.captcha.image.alternateText', [$msg.get('core.register.submit')]),
287 + 'alt' : $services.localization.render('core.captcha.image.alternateText', [$services.localization.render('core.register.submit')]),
282 282   'name' : ''
283 283   }
284 284   })
... ... @@ -289,7 +289,7 @@
289 289   ## and not filled back in if there is an error ('noReturn')
290 290   #set($field =
291 291   {'name' : 'captcha_answer',
292 - 'label' : $msg.get('core.captcha.image.instruction'),
298 + 'label' : $services.localization.render('core.captcha.image.instruction'),
293 293   'params' : {
294 294   'type' : 'text',
295 295   'size' : '60'
... ... @@ -296,12 +296,12 @@
296 296   },
297 297   'validate' : {
298 298   'mandatory' : {
299 - 'failureMessage' : $msg.get('core.captcha.captchaAnswerIsWrong'),
305 + 'failureMessage' : $services.localization.render('core.captcha.captchaAnswerIsWrong'),
300 300   'noscript' : true
301 301   },
302 302   'programmaticValidation' : {
303 303   'code' : '#checkCaptcha($request, $request.get("captcha_answer"))',
304 - 'failureMessage' : $msg.get('core.captcha.captchaAnswerIsWrong')
310 + 'failureMessage' : $services.localization.render('core.captcha.captchaAnswerIsWrong')
305 305   }
306 306   },
307 307   'noReturn' : true
... ... @@ -343,7 +343,7 @@
343 343  ##
344 344  #if($useLiveValidation)
345 345   $xwiki.get('jsfx').use('uicomponents/widgets/validation/livevalidation_prototype.js')
346 - $xwiki.get('ssfx').use('uicomponents/widgets/validation/livevalidation.css')
352 + $xwiki.get('ssfx').use('uicomponents/widgets/validation/livevalidation.css', true)
347 347  #end
348 348  ## This application's HTML is dynamically generated and editing in WYSIWYG would not work
349 349  #if($xcontext.getAction() == 'edit')
... ... @@ -379,7 +379,8 @@
379 379  ## If the submit button has been pressed, then we test the input and maybe create the user.
380 380  #if($request.getParameter('xwikiname'))
381 381   ## Do server side validation of input fields.
382 - #set($discard = "#validateFields($fields, $request)")
388 + ## This must not be in a #set directive as it will output messages if something goes wrong.
389 + #validateFields($fields, $request)
383 383   ## If server side validation was successfull, create the user
384 384   #if(!$registrationFailed)
385 385   #createUser($fields, $request, $response, $doAfterRegistration)
... ... @@ -394,6 +394,10 @@
394 394   <form id="register" action="" method="post" class="xform half">
395 395   <div>
396 396   <input type="hidden" name="form_token" value="$!{services.csrf.getToken()}" />
404 + #set ($userDirectoryReference = $services.model.createDocumentReference('', 'Main', 'UserDirectory'))
405 + #if ($xwiki.exists($userDirectoryReference))
406 + <input type="hidden" name="parent" value="$!{services.model.serialize($userDirectoryReference, 'default')}" />
407 + #end
397 397   #generateHtml($fields, $fieldMandatoryStar, $failureMessageParams)
398 398   <div class="wikimodel-emptyline"></div>
399 399   <span class="buttonwrapper">
... ... @@ -421,12 +421,12 @@
421 421   <!-- com.xpn.xwiki.plugin.skinx.CssSkinFileExtensionPlugin -->
422 422   <!-- com.xpn.xwiki.plugin.skinx.JsSkinFileExtensionPlugin -->
423 423   ##
424 - <input class="button" type="submit" value="$msg.get('save')" onclick="window.lb.lbSaveForm();"/>
435 + <input class="button" type="submit" value="$services.localization.render('save')" onclick="window.lb.lbSaveForm();"/>
425 425   </span>#* End ButtonWrapper then start another...*#<span class="buttonwrapper">
426 - <input class="button secondary" type="submit" value="$msg.get("cancel")" onclick="Form.disable(window.lb.form); window.lb.lbClose();"/>
437 + <input class="button secondary" type="submit" value="$services.localization.render("cancel")" onclick="Form.disable(window.lb.form); window.lb.lbClose();"/>
427 427   #else
428 428   ## Not using the LightBox
429 - <input type="submit" value="$msg.get('core.register.submit')" class="button"/>
440 + <input type="submit" value="$services.localization.render('core.register.submit')" class="button"/>
430 430   #end
431 431   </span>## ButtonWrapper
432 432   </div>
... ... @@ -439,8 +439,8 @@
439 439   ##
440 440   ## Allow permitted users to configure this application.
441 441   #if($xcontext.getUser() != 'XWiki.XWikiGuest' && $xcontext.hasAccessLevel("edit", $documentName))
442 - [[$msg.get('xe.admin.registration.youCanConfigureRegistrationHere')>>XWiki.XWikiPreferences?section=Registration&editor=globaladmin#HCustomizeXWikiRegistration]]
443 - {{html}}<a href="$xwiki.getURL($documentName, 'edit', 'editor=wiki')">$msg.get('xe.admin.registration.youCanConfigureRegistrationFieldsHere')</a>{{/html}}
453 + [[{{translation key="xe.admin.registration.youCanConfigureRegistrationHere"/}}>>XWiki.XWikiPreferences?section=Registration&editor=globaladmin#HCustomizeXWikiRegistration]]
454 + {{html}}<a href="$xwiki.getURL($documentName, 'edit', 'editor=wiki')">$services.localization.render('xe.admin.registration.youCanConfigureRegistrationFieldsHere')</a>{{/html}}
444 444   #end
445 445  ## If the registration is done (successful) and we detect the Lightbox simply send the user back to the original page.
446 446  #elseif($assumeLightbox)
... ... @@ -497,7 +497,11 @@
497 497   #if($regex.get('pattern') && $regex.get('failureMessage'))
498 498   ## Make Java regexes more compatible with Perl/js style regexes by removing leading and trailing /
499 499   #if($regex.get('pattern').length() > 1)
500 - #set($pattern = $regex.get('pattern').substring(1, $mathtool.add($regex.get('pattern').length(), -1)))
511 + #set($pattern = $regex.get('pattern'))
512 + #if($pattern.lastIndexOf('/') < $pattern.length() - 1)
513 + ERROR: In field: ${fieldName}: regex validation does not allow flags after the /, please fix [${pattern}].
514 + #end
515 + #set($pattern = $pattern.substring($mathtool.add(1, $pattern.indexOf('/')), $pattern.lastIndexOf('/')))
501 501   #else
502 502   ## I don't expect this but want to maintain compatibility.
503 503   #set($pattern = $regex.get('pattern'))
... ... @@ -568,14 +568,14 @@
568 568   #if($reg && $reg <= 0)
569 569   {{error}}
570 570   #if($reg == -2)
571 - $msg.get('core.register.passwordMismatch')
586 + {{translation key="core.register.passwordMismatch"/}}
572 572   ## -3 means username taken, -8 means username is superadmin name
573 573   #elseif($reg == -3 || $reg == -8)
574 - $msg.get('core.register.userAlreadyExists')
589 + {{translation key="core.register.userAlreadyExists"/}}
575 575   #elseif($reg == -4)
576 - $msg.get('core.register.invalidUsername')
591 + {{translation key="core.register.invalidUsername"/}}
577 577   #else
578 - $msg.get('core.register.registerFailed', [$reg])
593 + {{translation key="core.register.registerFailed" parameters="$reg"/}}
579 579   #end
580 580   {{/error}}
581 581   #elseif($reg)
... ... @@ -612,13 +612,13 @@
612 612  
613 613   {{html clean=false wiki=false}}
614 614   <form id="loginForm" action="$loginURL" method="post">
615 - <div>
630 + <div class="centered">
616 616   <input type="hidden" name="form_token" value="$!{services.csrf.getToken()}" />
617 617   <input id="j_username" name="j_username" type="hidden" value="$escapetool.xml($!userName)" />
618 618   <input id="j_password" name="j_password" type="hidden" value="$escapetool.xml($!password)" />
619 619   <input id="$redirectParam" name="$redirectParam" type="hidden" value="$escapetool.xml($redirect)" />
620 - <span class="buttonwrapper" style="margin-left:47%;">
621 - <input type="submit" value="$msg.get('login')" class="button"/>
635 + <span class="buttonwrapper">
636 + <input type="submit" value="$services.localization.render('login')" class="button"/>
622 622   </span>
623 623   </div>
624 624   </form>
... ... @@ -625,7 +625,7 @@
625 625   ## We don't want autoLogin if we are administrators adding users...
626 626   #if($autoLogin && !$assumeLightbox)
627 627   <script type='text/javascript'>
628 - document.observe('dom:loaded', function() {
643 + document.observe('xwiki:dom:loaded', function() {
629 629   document.forms['loginForm'].submit();
630 630   });
631 631   </script>
... ... @@ -659,7 +659,7 @@
659 659   #foreach($entry in $fieldMandatoryStar.entrySet())
660 660   $entry.getKey()="$entry.getValue()" ##
661 661   #end
662 - >$msg.get('core.validation.required')</span>
677 + >$services.localization.render('core.validation.required')</span>
663 663   #end
664 664   </label>
665 665   </dt>
... ... @@ -705,7 +705,7 @@
705 705  #macro(generateJavascript, $fields)
706 706   <script type='text/javascript'>
707 707   /* <![CDATA[ */
708 - document.observe('dom:loaded', function() {
723 + document.observe('xwiki:dom:loaded', function() {
709 709   ##
710 710   #foreach($field in $fields)
711 711   #if($field.get('validate') && $field.get('name'))
... ... @@ -790,14 +790,14 @@
790 790   #set($configDocument = $xwiki.getDocument($configDocumentName))
791 791   #if(!$configDocument || !$configDocument.getObject($documentName))
792 792   ## No config document, load defaults.
793 - #set($heading = "$msg.get('core.register.title')")
794 - #set($welcomeMessage = "$msg.get('core.register.welcome')")
808 + #set($heading = "$services.localization.render('core.register.title')")
809 + #set($welcomeMessage = "$services.localization.render('core.register.welcome')")
795 795   #set($useLiveValidation = true)
796 - #set($defaultFieldOkayMessage = "$msg.get('core.validation.valid.message')")
811 + #set($defaultFieldOkayMessage = "$services.localization.render('core.validation.valid.message')")
797 797   #set($loginButton = true)
798 - #set($defaultRedirect = "$xwiki.getURL('Main.WebHome')")
813 + #set($defaultRedirect = "$xwiki.getURL($services.model.resolveDocument('', 'default', $doc.documentReference.extractReference('WIKI')))")
799 799   #set($userFullName = "$request.get('register_first_name') $request.get('register_last_name')")
800 - #set($registrationSuccessMessage = '{{info}}$msg.get("core.register.successful", ["[[$fullName>>$userSpace$userName]]", $userName]){{/info}}')
815 + #set($registrationSuccessMessage = '{{info}}$services.localization.render("core.register.successful", ["[[${userFullName}>>${userSpace}${userName}]]", ${userName}]){{/info}}')
801 801   #else
802 802   #set($configObject = $configDocument.getObject($documentName))
803 803   #if ($context.action == 'register')