If it is not explicitly told in following recipe, setting up services are described for Ubuntu 16.04 server, but applications are described for Ubuntu 16.04 and/or Lubuntu 16.04 workstation. If you use different Ubuntu version or Linux distribution, settings as well as content, names and places of configuration files may be different!
Got it.

XWiki registration

If any user is allowed to register in XWiki, it can be (and is) abused by spambots. This recipe shows, how to avoid it with customized XWiki.Registration class.
  1. Open XWiki.Registration class in edit mode, e.g. http://localhost:8080/xwiki/bin/edit/XWiki/Registration
  2. Uncomment sample code for sample code, which asks for favorite color (and accepts green as valid answer): 
...
  ## Uncomment this code to see an example of how you can easily add a field to the registration page
  ## NOTE: In order to save the favorite color in the "doAfterRegistration" hook, this page must be
  ## saved by an administrator and can not self sandboxing.
  #set($sandbox = false)
  #set($field =
    {'name' : 'favorite_color',
      'label' : 'What is your favorite color',
      'params' : {
        'type' : 'text',
        'size' : '60'
      },
      'validate' : {
        'mandatory' : {
          'failureMessage' : $services.localization.render('core.validation.required.message')
        },
        'regex' : {
          'pattern' : '/^green$/',
          'failureMessage' : 'You are not cool enough to register here.'
        },
        'fieldOkayMessage' : 'You are awesome.'
      },
      'doAfterRegistration' : '#saveFavoriteColor()'
    })
  #set($discard = $fields.add($field))
  ## Save the user's favorite color on their user page.
  #macro(saveFavoriteColor)
    #set($xwikiname = $request.get('xwikiname'))
    #set($userDoc = $xwiki.getDocument("$userSpace$xwikiname"))
    $userDoc.setContent("$userDoc.getContent() ${xwikiname}'s favorite color is $request.get('favorite_color')!")
    ## The user (who is not yet logged in) can't save documents so saveWithProgrammingRights
    ## will save the document as long as the user who last saved this registration page has programming rights.
    $userDoc.saveWithProgrammingRights("Saved favorite color from registration form.")
  #end
...
  1. If necessary, customize this code according to your needs and preferences.
  2. If multi lingual messages are needed, look at Writing Internationalized XWiki Applications for more info.
     
Tags: XWiki English
Created by Valdis Vītoliņš on 2013-11-09 15:24
Last modified by Valdis Vītoliņš on 2018-12-04 12:36
 
Xwiki Powered
Creative Commons Attribution 3.0 Unported License