~ubuntu-branches/ubuntu/oneiric/moin/oneiric-security

« back to all changes in this revision

Viewing changes to MoinMoin/action/newaccount.py

  • Committer: Bazaar Package Importer
  • Author(s): Jamie Strandboge
  • Date: 2010-03-30 12:55:34 UTC
  • mfrom: (0.1.17 sid)
  • Revision ID: james.westby@ubuntu.com-20100330125534-4c2ufc1rok24447l
Tags: 1.9.2-2ubuntu1
* Merge from Debian testing (LP: #521834). Based on work by Stefan Ebner.
  Remaining changes:
 - Remove python-xml from Suggests field, the package isn't anymore in
   sys.path.
 - Demote fckeditor from Recommends to Suggests; the code was previously
   embedded in moin, but it was also disabled, so there's no reason for us
   to pull this in by default currently. Note: This isn't necessary anymore
   but needs a MIR for fckeditor, so postpone dropping this change until
   lucid+1
* debian/rules:
  - Replace hardcoded python2.5 with python* and hardcore python2.6 for ln
* debian/control.in: drop versioned depends on cdbs

Show diffs side-by-side

added added

removed removed

Lines of Context:
6
6
    @license: GNU GPL, see COPYING for details.
7
7
"""
8
8
 
9
 
from MoinMoin import user, wikiutil, util
 
9
from MoinMoin import user, wikiutil
10
10
from MoinMoin.Page import Page
11
11
from MoinMoin.widget import html
12
12
from MoinMoin.security.textcha import TextCha
13
13
from MoinMoin.auth import MoinAuth
14
14
 
15
15
 
16
 
_debug = False
17
 
 
18
16
def _create_user(request):
19
17
    _ = request.getText
20
18
    form = request.form
21
19
 
22
 
    if request.request_method != 'POST':
 
20
    if request.method != 'POST':
 
21
        return
 
22
 
 
23
    if not wikiutil.checkTicket(request, form.get('ticket', '')):
23
24
        return
24
25
 
25
26
    if not TextCha(request).check_answer_from_form():
30
31
 
31
32
    # Require non-empty name
32
33
    try:
33
 
        theuser.name = form['name'][0]
 
34
        theuser.name = form['name']
34
35
    except KeyError:
35
36
        return _("Empty user name. Please enter a user name.")
36
37
 
45
46
        return _("This user name already belongs to somebody else.")
46
47
 
47
48
    # try to get the password and pw repeat
48
 
    password = form.get('password1', [''])[0]
49
 
    password2 = form.get('password2', [''])[0]
 
49
    password = form.get('password1', '')
 
50
    password2 = form.get('password2', '')
50
51
 
51
52
    # Check if password is given and matches with password repeat
52
53
    if password != password2:
69
70
            return "Can't encode password: %s" % str(err)
70
71
 
71
72
    # try to get the email, for new users it is required
72
 
    email = wikiutil.clean_input(form.get('email', [''])[0])
 
73
    email = wikiutil.clean_input(form.get('email', ''))
73
74
    theuser.email = email.strip()
74
75
    if not theuser.email and 'email' not in request.cfg.user_form_remove:
75
76
        return _("Please provide your email address. If you lose your"
84
85
    theuser.save()
85
86
 
86
87
    result = _("User account created! You can use this account to login now...")
87
 
    if _debug:
88
 
        result = result + util.dumpFormData(form)
89
88
    return result
90
89
 
91
90
 
94
93
    url = request.page.url(request)
95
94
    ret = html.FORM(action=url)
96
95
    ret.append(html.INPUT(type='hidden', name='action', value='newaccount'))
 
96
 
 
97
    ticket = wikiutil.createTicket(request)
 
98
    ret.append(html.INPUT(type="hidden", name="ticket", value="%s" % ticket))
 
99
 
97
100
    lang_attr = request.theme.ui_lang_attr()
98
101
    ret.append(html.Raw('<div class="userpref"%s>' % lang_attr))
99
102
    tbl = html.TABLE(border="0")
159
162
 
160
163
    if not found:
161
164
        # we will not have linked, so forbid access
162
 
        request.makeForbidden403()
 
165
        request.makeForbidden(403, 'No MoinAuth in auth list')
163
166
        return
164
167
 
165
168
    page = Page(request, pagename)
172
175
        request.theme.add_msg(_create_user(request), "dialog")
173
176
        return page.send_page()
174
177
    else: # show create form
175
 
        request.emit_http_headers()
176
178
        request.theme.send_title(_("Create Account"), pagename=pagename)
177
179
 
178
180
        request.write(request.formatter.startContent("content"))