From 45943ddee12407521b9e65965f04e0153a1a066d Mon Sep 17 00:00:00 2001 From: Fabio Teixeira Date: Thu, 11 Sep 2014 15:08:17 -0300 Subject: [PATCH] Limit user password size at signup form --- lib/mpog_software_plugin.rb | 1 + public/mpog-user-validations.js | 117 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---------------------------------------------------- 2 files changed, 66 insertions(+), 52 deletions(-) diff --git a/lib/mpog_software_plugin.rb b/lib/mpog_software_plugin.rb index d6908c4..31132c6 100644 --- a/lib/mpog_software_plugin.rb +++ b/lib/mpog_software_plugin.rb @@ -21,6 +21,7 @@ class MpogSoftwarePlugin < Noosfero::Plugin Proc::new do content_tag(:div, + hidden_field_tag("user_password_menssage", _("Choose a password that you can remember easily. It must have at least 6 characters.")) + required(labelled_form_field( _('Secondary e-Mail'), text_field(:user, :secondary_email, :id => 'secondary_email_field') + diff --git a/public/mpog-user-validations.js b/public/mpog-user-validations.js index 3962d3c..cd6d761 100644 --- a/public/mpog-user-validations.js +++ b/public/mpog-user-validations.js @@ -1,66 +1,79 @@ -function check_reactivate_account(value, input_object){ - jQuery.ajax({ - url : "/plugin/mpog_software/check_reactivate_account", - type: "GET", - data: { "email": value }, - success: function(response) { - if( jQuery("#forgot_link").length == 0 ) - jQuery(input_object).parent().append(response); - else - jQuery("#forgot_link").html(response); - }, - error: function(type, err, message) { - console.log(type+" -- "+err+" -- "+message); - } - }); -} +(function(){ + function set_initial_form_custom_data() { + jQuery('#profile_data_country').val("BR"); -function put_brazil_based_on_email(){ - var suffixes = ['gov.br', 'jus.br', 'leg.br', 'mp.br']; - var value = this.value; - var input_object = this; - var gov_suffix = false; + jQuery("#password-balloon").html(jQuery("#user_password_menssage").val()); + } - suffixes.each(function(suffix){ - var has_suffix = new RegExp("(.*)"+suffix+"$", "i"); + function check_reactivate_account(value, input_object){ + jQuery.ajax({ + url : "/plugin/mpog_software/check_reactivate_account", + type: "GET", + data: { "email": value }, + success: function(response) { + if( jQuery("#forgot_link").length == 0 ) + jQuery(input_object).parent().append(response); + else + jQuery("#forgot_link").html(response); + }, + error: function(type, err, message) { + console.log(type+" -- "+err+" -- "+message); + } + }); + } - if( has_suffix.test(value) ) { - gov_suffix = true; - jQuery("#profile_data_country").val("BR"); - } - }); + function put_brazil_based_on_email(){ + var suffixes = ['gov.br', 'jus.br', 'leg.br', 'mp.br']; + var value = this.value; + var input_object = this; + var gov_suffix = false; - jQuery("#profile_data_country").find(':not(:selected)').css('display', (gov_suffix?'none':'block')); + suffixes.each(function(suffix){ + var has_suffix = new RegExp("(.*)"+suffix+"$", "i"); + if( has_suffix.test(value) ) { + gov_suffix = true; + jQuery("#profile_data_country").val("BR"); + } + }); - check_reactivate_account(value, input_object) -} + jQuery("#profile_data_country").find(':not(:selected)').css('display', (gov_suffix?'none':'block')); -function validate_email_format(){ - var correct_format_regex = /^\w+@[a-zA-Z_]+?\.[a-zA-Z]{2,3}$/; + check_reactivate_account(value, input_object) + } - if( this.value.length > 0 ) { - if(correct_format_regex.test(this.value)) - this.className = "validated"; - else - this.className = "invalid"; - } else - this.className = ""; -} + function validate_email_format(){ + var correct_format_regex = /^\w+@[a-zA-Z_]+?\.[a-zA-Z]{2,3}$/; + if( this.value.length > 0 ) { + if(correct_format_regex.test(this.value)) + this.className = "validated"; + else + this.className = "invalid"; + } else + this.className = ""; + } + + function verify_user_password_size() { + if( this.value.length < 6 ) { + jQuery(this).switchClass("validated", "invalid"); + } else { + jQuery(this).switchClass("invalid", "validated"); + } + } -jQuery(document).ready(function(){ - jQuery('#secondary_email_field').blur( - validate_email_format - ); + jQuery(document).ready(function(){ + set_initial_form_custom_data(); - jQuery('#profile_data_country').val("BR"); + jQuery('#secondary_email_field').blur( + validate_email_format + ); - jQuery("#user_email").blur( - put_brazil_based_on_email - ); + jQuery("#user_email").blur(put_brazil_based_on_email); - jQuery('#secondary_email_field').focus(function() { jQuery('#secondary-email-balloon').fadeIn('slow'); }); - jQuery('#secondary_email_field').blur(function() { jQuery('#secondary-email-balloon').fadeOut('slow'); }); + jQuery('#secondary_email_field').focus(function() { jQuery('#secondary-email-balloon').fadeIn('slow'); }); + jQuery('#secondary_email_field').blur(function() { jQuery('#secondary-email-balloon').fadeOut('slow'); }); -}); + jQuery("#user_pw").blur(verify_user_password_size); + }); +})(); \ No newline at end of file -- libgit2 0.21.2