1 import web
2 import re
3 from decorators import i18n
4 from model import User
9
11 form = web.form.Form(
12 web.form.Textbox('username', description=_('Username (3 to 60 alfanumeric chars)')),
13 web.form.Password('password', description=_('Password (7 or more characters)')),
14 web.form.Password('password2', description=_('Repeat Password')),
15 web.form.Textbox('email', description=_('Email')),
16 web.form.Button('submit', type='submit', value=_('Register')),
17 validators = [
18 web.form.Validator(_('Passwords did\'t match'),
19 lambda i: i.password == i.password2),
20
21 web.form.Validator(_('Password shorter than 7 characters'),
22 lambda i: len(i.password) >= 7),
23
24 web.form.Validator(_('Username length should be from 3 to 60 characters'),
25 lambda i: len(i.username) >= 3 or len(i.username) <= 60),
26
27 web.form.Validator(_('Invalid username'),
28 lambda i: re.compile("^\w+$").match(i.username)),
29
30 web.form.Validator(_('Email too long'),
31 lambda i: len(i.email) <= 250),
32
33 web.form.Validator(_('Invalid email'),
34 lambda i: re.compile("^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$").match(i.email)),
35
36 web.form.Validator(_('Username already exists'),
37 unique_username)
38 ])
39
40 @i18n
43
45 if not self.form.validates():
46 return web.ctx.render.user.create(self.form)
47
48
49 new_user = User(
50 name = web.input().username,
51 password = web.input().password,
52 email = web.input().email)
53 web.ctx.orm.add(new_user)
54 new_user.send_activation_mail()
55 web.ctx.notify(_('User %s registered successfully, check your email to activate it') % web.input().username, 'notification')
56
57
58 raise web.seeother('/')
59