# This allows the administrator to undisable him when he is
# authenticated.
#
import MoinMoin
from   MoinMoin import userform
import os
import time

def execute(pagename, request):
  #
  # Execute the form identically to how wikiaction.do_userform()
  # does it.
  #
  form = request.form
  userName = form['name'][0]
  isCreate = (
    form.has_key('create') or
    form.has_key('create_only') or
    form.has_key('create_and_mail'))
  isNewUser = not MoinMoin.user.getUserId(request, userName)
  message = userform.savedata(request)
  #
  # If that created a new user then generate a cookie and
  # see if he wants to send an email.
  #
  user = MoinMoin.user.User(request, auth_username=userName)
  if isCreate and isNewUser and user.exists():
    userform_action = MoinMoin.wikiutil.importPlugin(
	request.cfg, "macro", "EmailActivation", function="userform_action")
    new_message = userform_action(request, user)
    if new_message != None:
      message = new_message
  MoinMoin.Page.Page(request, pagename).send_page(request, msg=message)
