Back to index

moin  1.9.0~rc2
Functions
MoinMoin.action.newaccount Namespace Reference

Functions

def _create_user
def _create_form
def execute

Function Documentation

def MoinMoin.action.newaccount._create_form (   request) [private]

Definition at line 88 of file newaccount.py.

00088 
00089 def _create_form(request):
00090     _ = request.getText
00091     url = request.page.url(request)
00092     ret = html.FORM(action=url)
00093     ret.append(html.INPUT(type='hidden', name='action', value='newaccount'))
00094     lang_attr = request.theme.ui_lang_attr()
00095     ret.append(html.Raw('<div class="userpref"%s>' % lang_attr))
00096     tbl = html.TABLE(border="0")
00097     ret.append(tbl)
00098     ret.append(html.Raw('</div>'))
00099 
00100     row = html.TR()
00101     tbl.append(row)
00102     row.append(html.TD().append(html.STRONG().append(
00103                                   html.Text(_("Name")))))
00104     cell = html.TD()
00105     row.append(cell)
00106     cell.append(html.INPUT(type="text", size="36", name="name"))
00107     cell.append(html.Text(' ' + _("(Use FirstnameLastname)")))
00108 
00109     row = html.TR()
00110     tbl.append(row)
00111     row.append(html.TD().append(html.STRONG().append(
00112                                   html.Text(_("Password")))))
00113     row.append(html.TD().append(html.INPUT(type="password", size="36",
00114                                            name="password1")))
00115 
00116     row = html.TR()
00117     tbl.append(row)
00118     row.append(html.TD().append(html.STRONG().append(
00119                                   html.Text(_("Password repeat")))))
00120     row.append(html.TD().append(html.INPUT(type="password", size="36",
00121                                            name="password2")))
00122 
00123     row = html.TR()
00124     tbl.append(row)
00125     row.append(html.TD().append(html.STRONG().append(html.Text(_("Email")))))
00126     row.append(html.TD().append(html.INPUT(type="text", size="36",
00127                                            name="email")))
00128 
00129     textcha = TextCha(request)
00130     if textcha.is_enabled():
00131         row = html.TR()
00132         tbl.append(row)
00133         row.append(html.TD().append(html.STRONG().append(
00134                                       html.Text(_('TextCha (required)')))))
00135         td = html.TD()
00136         if textcha:
00137             td.append(textcha.render())
00138         row.append(td)
00139 
00140     row = html.TR()
00141     tbl.append(row)
00142     row.append(html.TD())
00143     td = html.TD()
00144     row.append(td)
00145     td.append(html.INPUT(type="submit", name="create",
00146                          value=_('Create Profile')))
00147 
00148     return unicode(ret)

Here is the caller graph for this function:

def MoinMoin.action.newaccount._create_user (   request) [private]

Definition at line 16 of file newaccount.py.

00016 
00017 def _create_user(request):
00018     _ = request.getText
00019     form = request.form
00020 
00021     if request.method != 'POST':
00022         return
00023 
00024     if not TextCha(request).check_answer_from_form():
00025         return _('TextCha: Wrong answer! Go back and try again...')
00026 
00027     # Create user profile
00028     theuser = user.User(request, auth_method="new-user")
00029 
00030     # Require non-empty name
00031     try:
00032         theuser.name = form['name']
00033     except KeyError:
00034         return _("Empty user name. Please enter a user name.")
00035 
00036     # Don't allow creating users with invalid names
00037     if not user.isValidName(request, theuser.name):
00038         return _("""Invalid user name {{{'%s'}}}.
00039 Name may contain any Unicode alpha numeric character, with optional one
00040 space between words. Group page name is not allowed.""", wiki=True) % wikiutil.escape(theuser.name)
00041 
00042     # Name required to be unique. Check if name belong to another user.
00043     if user.getUserId(request, theuser.name):
00044         return _("This user name already belongs to somebody else.")
00045 
00046     # try to get the password and pw repeat
00047     password = form.get('password1', '')
00048     password2 = form.get('password2', '')
00049 
00050     # Check if password is given and matches with password repeat
00051     if password != password2:
00052         return _("Passwords don't match!")
00053     if not password:
00054         return _("Please specify a password!")
00055 
00056     pw_checker = request.cfg.password_checker
00057     if pw_checker:
00058         pw_error = pw_checker(request, theuser.name, password)
00059         if pw_error:
00060             return _("Password not acceptable: %s") % pw_error
00061 
00062     # Encode password
00063     if password and not password.startswith('{SHA}'):
00064         try:
00065             theuser.enc_password = user.encodePassword(password)
00066         except UnicodeError, err:
00067             # Should never happen
00068             return "Can't encode password: %s" % str(err)
00069 
00070     # try to get the email, for new users it is required
00071     email = wikiutil.clean_input(form.get('email', ''))
00072     theuser.email = email.strip()
00073     if not theuser.email and 'email' not in request.cfg.user_form_remove:
00074         return _("Please provide your email address. If you lose your"
00075                  " login information, you can get it by email.")
00076 
00077     # Email should be unique - see also MoinMoin/script/accounts/moin_usercheck.py
00078     if theuser.email and request.cfg.user_email_unique:
00079         if user.get_by_email_address(request, theuser.email):
00080             return _("This email already belongs to somebody else.")
00081 
00082     # save data
00083     theuser.save()
00084 
00085     result = _("User account created! You can use this account to login now...")
00086     return result
00087 

Here is the caller graph for this function:

def MoinMoin.action.newaccount.execute (   pagename,
  request 
)

Definition at line 149 of file newaccount.py.

00149 
00150 def execute(pagename, request):
00151     found = False
00152     for auth in request.cfg.auth:
00153         if isinstance(auth, MoinAuth):
00154             found = True
00155             break
00156 
00157     if not found:
00158         # we will not have linked, so forbid access
00159         request.makeForbidden(403, 'No MoinAuth in auth list')
00160         return
00161 
00162     page = Page(request, pagename)
00163     _ = request.getText
00164     form = request.form
00165 
00166     submitted = form.has_key('create')
00167 
00168     if submitted: # user pressed create button
00169         request.theme.add_msg(_create_user(request), "dialog")
00170         return page.send_page()
00171     else: # show create form
00172         request.theme.send_title(_("Create Account"), pagename=pagename)
00173 
00174         request.write(request.formatter.startContent("content"))
00175 
00176         # THIS IS A BIG HACK. IT NEEDS TO BE CLEANED UP
00177         request.write(_create_form(request))
00178 
00179         request.write(request.formatter.endContent())
00180 
00181         request.theme.send_footer(pagename)
00182         request.theme.send_closing_html()
00183 

Here is the call graph for this function: