8000 Merge pull request #31 from dongweiming/feature_validate_email · lcppcl/code@e97e99e · GitHub
[go: up one dir, main page]

Skip to content

Commit e97e99e

Browse files
committed
Merge pull request douban#31 from dongweiming/feature_validate_email
Feature for when signup validate email
2 parents ec53dbf + 0b871a2 commit e97e99e

File tree

4 files changed

+29
-6
lines changed

4 files changed

+29
-6
lines changed

vilya/config.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@
6060

6161
MAKO_FS_CHECK = True
6262

63+
EMAIL_SUFFIX = 'douban.com'
64+
6365
try:
6466
from local_config import *
6567
except ImportError:

vilya/libs/text.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
from mikoto.libs.text import *
77
from mikoto.libs.emoji import *
88

9+
from vilya.config import EMAIL_SUFFIX
10+
911

1012
def trunc_utf8(string, num, etc="..."):
1113
"""truncate a utf-8 string, show as num chars.
@@ -47,7 +49,7 @@ def email_normalizer(name, email):
4749
if _validate_email(email):
4850
return email
4951
else:
50-
return name + '@douban.com'
52+
return name + '@' + EMAIL_SUFFIX
5153

5254

5355
def is_image(fname):

vilya/templates/users/new.html

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
<%inherit file="/layouts/base.html" />
22

33
<%def name="title()">New user</%def>
4+
<%def name="make_value(attr)">
5+
% if attr:
6+
value=${attr}
7+
% endif
8+
</%def>
49

510
<div class="hero-unit">
611
<div class="panel panel-default">
@@ -12,25 +17,29 @@ <h3 class="panel-title">New user</h3>
1217
<div class="form-group">
1318
<label for="inputName" class="col-sm-2 control-label">Name</label>
1419
<div class="col-sm-10">
15-
<input type="text" name="name" class="form-control" id="inputName" placeholder="Name">
20+
<input type="text" name="name" class="form-control" id="inputName" placeholder="Name" ${make_value(name)}>
1621
</div>
1722
</div>
1823
<div class="form-group">
1924
<label for="inputPassword" class="col-sm-2 control-label">Password</label>
2025
<div class="col-sm-10">
21-
<input type="password" name="password" class="form-control" id="inputPassword" placeholder="">
26+
<input type="password" name="password" class="form-control" id="inputPassword" placeholder="" ${make_value(password)}>
2227
</div>
2328
</div>
29+
% if not not_validate_email:
2430
<div class="form-group">
31+
% else:
32+
<div class="form-group has-error">
33+
% endif
2534
<label for="inputEmail" class="col-sm-2 control-label">Email</label>
2635
<div class="col-sm-10">
27-
<input type="text" name="email" class="form-control" id="inputEmail" placeholder="">
36+
<input type="text" name="email" class="form-control" id="inputEmail" placeholder="" ${make_value(email)}>
2837
</div>
2938
</div>
3039
<div class="form-group">
3140
<label for="inputDescription" class="col-sm-2 control-label">Description</label>
3241
<div class="col-sm-10">
33-
<input type="text" name="description" class="form-control" id="inputDescription" placeholder="Description">
42+
<input type="text" name="description" class="form-control" id="inputDescription" placeholder="Description" ${make_value(description)}>
3443
</div>
3544
</div>
3645
<div class="form-group">
@@ -43,4 +52,3 @@ <h3 class="panel-title">New user</h3>
4352
</div>
4453
</div>
4554
</div>
46-

vilya/views/users/__init__.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from vilya.models.project import Project
77
from vilya.models.user import User
88
from vilya.views.projects import ProjectUI
9+
from vilya.libs.text import _validate_email
910

1011
_q_exports = ['new']
1112

@@ -21,6 +22,16 @@ def _q_index(request):
2122
password = request.get_form_var('password')
2223
email = request.get_form_var('email')
2324
description = request.get_form_var('description')
25+
26+
# Forced mail format must be correct
27+
if not _validate_email(email):
28+
context['name'] = name
29+
context['not_validate_email'] = True
30+
context['password'] = password
31+
context['email'] = email
32+
context['description'] = description
33+
return st('users/new.html', **context)
34+
2435
user = User.add(name=name,
2536
password=password,
2637
description=description,

0 commit comments

Comments
 (0)
0