Commit 45943ddee12407521b9e65965f04e0153a1a066d

Authored by Fabio Teixeira
Committed by Gabriela Navarro
1 parent 44739fca

Limit user password size at signup form

(correcoes_aderencia)

Signed-off-by: Fabio Teixeira <fabio1079@gmail.com>
lib/mpog_software_plugin.rb
... ... @@ -21,6 +21,7 @@ class MpogSoftwarePlugin &lt; Noosfero::Plugin
21 21  
22 22 Proc::new do
23 23 content_tag(:div,
  24 + hidden_field_tag("user_password_menssage", _("Choose a password that you can remember easily. It must have at least 6 characters.")) +
24 25 required(labelled_form_field(
25 26 _('Secondary e-Mail'),
26 27 text_field(:user, :secondary_email, :id => 'secondary_email_field') +
... ...
public/mpog-user-validations.js
1   -function check_reactivate_account(value, input_object){
2   - jQuery.ajax({
3   - url : "/plugin/mpog_software/check_reactivate_account",
4   - type: "GET",
5   - data: { "email": value },
6   - success: function(response) {
7   - if( jQuery("#forgot_link").length == 0 )
8   - jQuery(input_object).parent().append(response);
9   - else
10   - jQuery("#forgot_link").html(response);
11   - },
12   - error: function(type, err, message) {
13   - console.log(type+" -- "+err+" -- "+message);
14   - }
15   - });
16   -}
  1 +(function(){
  2 + function set_initial_form_custom_data() {
  3 + jQuery('#profile_data_country').val("BR");
17 4  
18   -function put_brazil_based_on_email(){
19   - var suffixes = ['gov.br', 'jus.br', 'leg.br', 'mp.br'];
20   - var value = this.value;
21   - var input_object = this;
22   - var gov_suffix = false;
  5 + jQuery("#password-balloon").html(jQuery("#user_password_menssage").val());
  6 + }
23 7  
24   - suffixes.each(function(suffix){
25   - var has_suffix = new RegExp("(.*)"+suffix+"$", "i");
  8 + function check_reactivate_account(value, input_object){
  9 + jQuery.ajax({
  10 + url : "/plugin/mpog_software/check_reactivate_account",
  11 + type: "GET",
  12 + data: { "email": value },
  13 + success: function(response) {
  14 + if( jQuery("#forgot_link").length == 0 )
  15 + jQuery(input_object).parent().append(response);
  16 + else
  17 + jQuery("#forgot_link").html(response);
  18 + },
  19 + error: function(type, err, message) {
  20 + console.log(type+" -- "+err+" -- "+message);
  21 + }
  22 + });
  23 + }
26 24  
27   - if( has_suffix.test(value) ) {
28   - gov_suffix = true;
29   - jQuery("#profile_data_country").val("BR");
30   - }
31   - });
  25 + function put_brazil_based_on_email(){
  26 + var suffixes = ['gov.br', 'jus.br', 'leg.br', 'mp.br'];
  27 + var value = this.value;
  28 + var input_object = this;
  29 + var gov_suffix = false;
32 30  
33   - jQuery("#profile_data_country").find(':not(:selected)').css('display', (gov_suffix?'none':'block'));
  31 + suffixes.each(function(suffix){
  32 + var has_suffix = new RegExp("(.*)"+suffix+"$", "i");
34 33  
  34 + if( has_suffix.test(value) ) {
  35 + gov_suffix = true;
  36 + jQuery("#profile_data_country").val("BR");
  37 + }
  38 + });
35 39  
36   - check_reactivate_account(value, input_object)
37   -}
  40 + jQuery("#profile_data_country").find(':not(:selected)').css('display', (gov_suffix?'none':'block'));
38 41  
39   -function validate_email_format(){
40   - var correct_format_regex = /^\w+@[a-zA-Z_]+?\.[a-zA-Z]{2,3}$/;
  42 + check_reactivate_account(value, input_object)
  43 + }
41 44  
42   - if( this.value.length > 0 ) {
43   - if(correct_format_regex.test(this.value))
44   - this.className = "validated";
45   - else
46   - this.className = "invalid";
47   - } else
48   - this.className = "";
49   -}
  45 + function validate_email_format(){
  46 + var correct_format_regex = /^\w+@[a-zA-Z_]+?\.[a-zA-Z]{2,3}$/;
50 47  
  48 + if( this.value.length > 0 ) {
  49 + if(correct_format_regex.test(this.value))
  50 + this.className = "validated";
  51 + else
  52 + this.className = "invalid";
  53 + } else
  54 + this.className = "";
  55 + }
  56 +
  57 + function verify_user_password_size() {
  58 + if( this.value.length < 6 ) {
  59 + jQuery(this).switchClass("validated", "invalid");
  60 + } else {
  61 + jQuery(this).switchClass("invalid", "validated");
  62 + }
  63 + }
51 64  
52   -jQuery(document).ready(function(){
53   - jQuery('#secondary_email_field').blur(
54   - validate_email_format
55   - );
  65 + jQuery(document).ready(function(){
  66 + set_initial_form_custom_data();
56 67  
57   - jQuery('#profile_data_country').val("BR");
  68 + jQuery('#secondary_email_field').blur(
  69 + validate_email_format
  70 + );
58 71  
59   - jQuery("#user_email").blur(
60   - put_brazil_based_on_email
61   - );
  72 + jQuery("#user_email").blur(put_brazil_based_on_email);
62 73  
63   - jQuery('#secondary_email_field').focus(function() { jQuery('#secondary-email-balloon').fadeIn('slow'); });
64   - jQuery('#secondary_email_field').blur(function() { jQuery('#secondary-email-balloon').fadeOut('slow'); });
  74 + jQuery('#secondary_email_field').focus(function() { jQuery('#secondary-email-balloon').fadeIn('slow'); });
  75 + jQuery('#secondary_email_field').blur(function() { jQuery('#secondary-email-balloon').fadeOut('slow'); });
65 76  
66   -});
  77 + jQuery("#user_pw").blur(verify_user_password_size);
  78 + });
  79 +})();
67 80 \ No newline at end of file
... ...