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,6 +135,10 @@ | ||
135 | 135 | ||
136 | <script type="text/javascript"> | 136 | <script type="text/javascript"> |
137 | jQuery(function($) { | 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 | $('#signup-form input[type=text], #signup-form textarea').each(function() { | 143 | $('#signup-form input[type=text], #signup-form textarea').each(function() { |
140 | $(this).bind('blur', function() { | 144 | $(this).bind('blur', function() { |
@@ -170,7 +174,7 @@ jQuery(function($) { | @@ -170,7 +174,7 @@ jQuery(function($) { | ||
170 | $('#signup-balloon').fadeIn('slow'); | 174 | $('#signup-balloon').fadeIn('slow'); |
171 | }); | 175 | }); |
172 | $('#user_login').blur(function() { $('#signup-balloon').fadeOut('slow'); }); | 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 | $('#user_email').focus(function() { | 178 | $('#user_email').focus(function() { |
175 | $('#email-balloon').fadeIn('slow'); | 179 | $('#email-balloon').fadeIn('slow'); |
176 | }); | 180 | }); |
lib/noosfero/constants.rb
1 | module Noosfero::Constants | 1 | module Noosfero::Constants |
2 | - EMAIL_FORMAT = /\A([^@\s]+)@((?:[-_a-z0-9]+\.)+[a-z]{2,})\Z/i | 2 | + EMAIL_FORMAT = /\A([^\W_])([\w._-]+)@((?:[-_a-z0-9]+\.)+[a-z]{2,})\Z/i |
3 | INTEGER_FORMAT = /\A\d*\Z/i | 3 | INTEGER_FORMAT = /\A\d*\Z/i |
4 | PROFILE_PER_PAGE = 10 | 4 | PROFILE_PER_PAGE = 10 |
5 | end | 5 | end |
test/unit/user_test.rb
@@ -14,6 +14,24 @@ class UserTest < ActiveSupport::TestCase | @@ -14,6 +14,24 @@ class UserTest < ActiveSupport::TestCase | ||
14 | end | 14 | end |
15 | end | 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 | def test_should_require_login | 35 | def test_should_require_login |
18 | assert_no_difference 'User.count' do | 36 | assert_no_difference 'User.count' do |
19 | u = new_user(:login => nil) | 37 | u = new_user(:login => nil) |
-
mentioned in commit f176f5652c60bde2939053910b972ec77842b905