Commit 59c15564ebca100f9019d942fcab3c1441a0bc93
Committed by
Gabriela Navarro
1 parent
f6dc326c
Exists in
master
and in
29 other branches
Fix user email validation
Signed-off-by: Andre Bernardes <andrebsguedes@gmail.com> Signed-off-by: Brenddon Gontijo <brenddongontijo@msn.com> Signed-off-by: Filipe Ribeiro <firibeiro77@live.com>
Showing
3 changed files
with
24 additions
and
2 deletions
Show diff stats
app/views/account/_signup_form.html.erb
... | ... | @@ -135,6 +135,10 @@ |
135 | 135 | |
136 | 136 | <script type="text/javascript"> |
137 | 137 | jQuery(function($) { |
138 | + $.validator.addMethod('validEmail', function(value, element) { | |
139 | + var regex = /^([^\W_])([\w._-]+)@((?:[-_a-z0-9]+\.)+[a-z]{2,})$/i; | |
140 | + return this.optional(element) || regex.test(value); | |
141 | + }, 'Please enter a valid e-mail'); | |
138 | 142 | |
139 | 143 | $('#signup-form input[type=text], #signup-form textarea').each(function() { |
140 | 144 | $(this).bind('blur', function() { |
... | ... | @@ -170,7 +174,7 @@ jQuery(function($) { |
170 | 174 | $('#signup-balloon').fadeIn('slow'); |
171 | 175 | }); |
172 | 176 | $('#user_login').blur(function() { $('#signup-balloon').fadeOut('slow'); }); |
173 | - $('#signup-form').validate({ rules: { 'user[email]': { email: true } }, messages: { 'user[email]' : '' } }); | |
177 | + $('#signup-form').validate({ rules: { 'user[email]': { email: true, validEmail: true } }, messages: { 'user[email]' : '' } }); | |
174 | 178 | $('#user_email').focus(function() { |
175 | 179 | $('#email-balloon').fadeIn('slow'); |
176 | 180 | }); | ... | ... |
lib/noosfero/constants.rb
test/unit/user_test.rb
... | ... | @@ -14,6 +14,24 @@ class UserTest < ActiveSupport::TestCase |
14 | 14 | end |
15 | 15 | end |
16 | 16 | |
17 | + should 'not create user with wrong email' do | |
18 | + user = User.new(login: 'test_user', email: 'tes*te@hotmail.com', | |
19 | + password: '123456', password_confirmation: '123456') | |
20 | + user.save | |
21 | + assert_equal user.valid?, false | |
22 | + assert !user.errors[:email].nil? | |
23 | + | |
24 | + user.email = '_teste@hotmail.com' | |
25 | + user.save | |
26 | + assert_equal user.valid?, false | |
27 | + assert !user.errors[:email].nil? | |
28 | + | |
29 | + user.email = 'teste$@hotmail.com' | |
30 | + user.save | |
31 | + assert_equal user.valid?, false | |
32 | + assert !user.errors[:email].nil? | |
33 | + end | |
34 | + | |
17 | 35 | def test_should_require_login |
18 | 36 | assert_no_difference 'User.count' do |
19 | 37 | u = new_user(:login => nil) | ... | ... |
-
mentioned in commit f176f5652c60bde2939053910b972ec77842b905