Sfoglia il codice sorgente

disabled submit on registration to avoid duplicate account creation

Bachir Soussi Chiadmi 10 anni fa
parent
commit
0c71144833
4 ha cambiato i file con 68 aggiunte e 40 eliminazioni
  1. 22 8
      js/materio_user.js
  2. 22 8
      js/materio_user.min.js
  3. 20 20
      materio_user.module
  4. 4 4
      materio_user.pages.inc

+ 22 - 8
js/materio_user.js

@@ -4,7 +4,7 @@
 (function($) {
 
 MaterioUser = function(){
-  
+
   var _isAdhesion = $('body').is('.page-node-11187') || $('body').is('.page-node-11186');
 
   function init() {
@@ -17,7 +17,7 @@ MaterioUser = function(){
     // trace('initAdhesion');
     $('.get-link a').bind('click', function(event) {
       // trace('get-link click');
-      
+
       // do not show the registration form if already logged-in
       if($('body').is('.logged-in'))
         return true;
@@ -29,7 +29,7 @@ MaterioUser = function(){
              href = $this.attr("href"),
              destination = href.match('/\?destination=([^,]+)');
 
-      destination = "/" + destination[1].replace('%23', '#');       
+      destination = "/" + destination[1].replace('%23', '#');
       destination = destination.replace('//', '/');
       // trace('destination', destination);
 
@@ -55,7 +55,7 @@ MaterioUser = function(){
   function formLoaded(json, destination){
     //trace('formLoaded | json', json);
     var $modal = $('<div>').addClass('modal-content').append(json.block);
-    
+
     var id,label, description;
     $('input.form-text', $modal).each(function(i) {
       id = $(this).attr('id');
@@ -83,11 +83,16 @@ MaterioUser = function(){
 
     $("#user-register-form #edit-submit, #user-register-form #edit-submit--2", $modal).click(function(event){
       event.preventDefault();
+
+      // disable submit button to avoid duplicate user creation
+      // console.log('click', this);
+      $(this).attr('disabled', 'true');
+
       $.ajax({
         type: 'POST',
         dataType:'json',
         url: Drupal.settings.basePath+Drupal.settings.pathPrefix+"materio_user/register/submit",
-        data: $('#user-register-form', $modal).serialize(), 
+        data: $('#user-register-form', $modal).serialize(),
         success: function(data) { onUserLoginRegisterSubmit($('#user-register-form'), data, destination);},
         error: function() {trace('error');}
       });
@@ -100,14 +105,14 @@ MaterioUser = function(){
         type: 'POST',
         dataType:'json',
         url: Drupal.settings.basePath+Drupal.settings.pathPrefix+"materio_user/login/submit",
-        data: $('#user-login', $modal).serialize(), 
+        data: $('#user-login', $modal).serialize(),
         success: function(data){ onUserLoginRegisterSubmit($('#user-login'), data, destination); },
         error: function() { trace('error'); }
       });
       return false;
     });
 
-    // google analytics 
+    // google analytics
     // $.event.trigger({
     //   type : "record-stat",
     //   categorie : 'Search',
@@ -120,12 +125,21 @@ MaterioUser = function(){
   };
 
   function onUserLoginRegisterSubmit($form, data, destination){
+    // console.log('data', data);
     cleanModalErrors();
     if(data.errors != null){
       for(field in data.errors){
         $('input[name='+field+']', $form).addClass('error');
         $form.prepend($('<div>').addClass('message-error').html(data.errors[field]));
       }
+
+      (function($form){
+        setTimeout(function(){
+          console.log('enabled');
+          $('input[type=submit]', $form).removeAttr('disabled');
+        }, 0.5*1000);
+      })($form);
+
     }else{
       // trace('destination = '+destination);
       window.location.pathname = destination;
@@ -143,5 +157,5 @@ MaterioUser = function(){
 $(document).ready(function() {
   var materiouser = new MaterioUser();
 });
-  
+
 })(jQuery);

+ 22 - 8
js/materio_user.min.js

@@ -374,7 +374,7 @@ function getElementAngle(x1, y1, x2, y2) {
 (function($) {
 
 MaterioUser = function(){
-  
+
   var _isAdhesion = $('body').is('.page-node-11187') || $('body').is('.page-node-11186');
 
   function init() {
@@ -387,7 +387,7 @@ MaterioUser = function(){
     // trace('initAdhesion');
     $('.get-link a').bind('click', function(event) {
       // trace('get-link click');
-      
+
       // do not show the registration form if already logged-in
       if($('body').is('.logged-in'))
         return true;
@@ -399,7 +399,7 @@ MaterioUser = function(){
              href = $this.attr("href"),
              destination = href.match('/\?destination=([^,]+)');
 
-      destination = "/" + destination[1].replace('%23', '#');       
+      destination = "/" + destination[1].replace('%23', '#');
       destination = destination.replace('//', '/');
       // trace('destination', destination);
 
@@ -425,7 +425,7 @@ MaterioUser = function(){
   function formLoaded(json, destination){
     //trace('formLoaded | json', json);
     var $modal = $('<div>').addClass('modal-content').append(json.block);
-    
+
     var id,label, description;
     $('input.form-text', $modal).each(function(i) {
       id = $(this).attr('id');
@@ -453,11 +453,16 @@ MaterioUser = function(){
 
     $("#user-register-form #edit-submit, #user-register-form #edit-submit--2", $modal).click(function(event){
       event.preventDefault();
+
+      // disable submit button to avoid duplicate user creation
+      // console.log('click', this);
+      $(this).attr('disabled', 'true');
+
       $.ajax({
         type: 'POST',
         dataType:'json',
         url: Drupal.settings.basePath+Drupal.settings.pathPrefix+"materio_user/register/submit",
-        data: $('#user-register-form', $modal).serialize(), 
+        data: $('#user-register-form', $modal).serialize(),
         success: function(data) { onUserLoginRegisterSubmit($('#user-register-form'), data, destination);},
         error: function() {trace('error');}
       });
@@ -470,14 +475,14 @@ MaterioUser = function(){
         type: 'POST',
         dataType:'json',
         url: Drupal.settings.basePath+Drupal.settings.pathPrefix+"materio_user/login/submit",
-        data: $('#user-login', $modal).serialize(), 
+        data: $('#user-login', $modal).serialize(),
         success: function(data){ onUserLoginRegisterSubmit($('#user-login'), data, destination); },
         error: function() { trace('error'); }
       });
       return false;
     });
 
-    // google analytics 
+    // google analytics
     // $.event.trigger({
     //   type : "record-stat",
     //   categorie : 'Search',
@@ -490,12 +495,21 @@ MaterioUser = function(){
   };
 
   function onUserLoginRegisterSubmit($form, data, destination){
+    // console.log('data', data);
     cleanModalErrors();
     if(data.errors != null){
       for(field in data.errors){
         $('input[name='+field+']', $form).addClass('error');
         $form.prepend($('<div>').addClass('message-error').html(data.errors[field]));
       }
+
+      (function($form){
+        setTimeout(function(){
+          console.log('enabled');
+          $('input[type=submit]', $form).removeAttr('disabled');
+        }, 0.5*1000);
+      })($form);
+
     }else{
       // trace('destination = '+destination);
       window.location.pathname = destination;
@@ -513,5 +527,5 @@ MaterioUser = function(){
 $(document).ready(function() {
   var materiouser = new MaterioUser();
 });
-  
+
 })(jQuery);

+ 20 - 20
materio_user.module

@@ -1,4 +1,4 @@
-<?php	
+<?php
 
 
 /**
@@ -131,9 +131,9 @@ function materio_user_block_view($delta = '') {
       if( (isset($user->roles[6]) || isset($user->roles[8])) && $user->created < strtotime('01-12-2012') ){
         // dsm($user, 'user');
         $block['subject'] = '';
-        
+
         $path = 'http://base.materio.com';
-        
+
         if($language->language == 'fr')
           $path .= '/index_fr.html';
 
@@ -157,7 +157,7 @@ function materio_user_form_alter(&$form, &$form_state, $form_id) {
     // dsm($form);
     $form['account']['pass']['#type'] = 'password';
     $form['account']['pass']['#title'] = t('Password');
-    
+
     $form['actions']['#type'] = "container";
     $form['actions']['submit']['#value'] = t('Join');
 
@@ -172,12 +172,12 @@ function materio_user_form_alter(&$form, &$form_state, $form_id) {
   }
   if($form_id == "user_login" ){
     // dsm($form);
-    
+
     $form['actions']['#type'] = "container";
     // $form['actions']['submit']['#value'] = t('Join');
 
     // if( $_GET['q'] == 'node/11187' ){
-    //   $form['#submit'][] = "materio_user_user_login_form_submit";  
+    //   $form['#submit'][] = "materio_user_user_login_form_submit";
     // }
 
   }
@@ -209,7 +209,7 @@ function materio_user_form_alter(&$form, &$form_state, $form_id) {
   //     'fragment' => $_GET['q'] == 'node/11187' ? 'content-bottom' : '', // if we register from the membership page, then go directly to the form
   //   )
   // );
-  
+
   // $frontlink = l('continue with basic', '<front>');
   // // drupal_get_messages('status');
   // drupal_set_message(t('Welcome, you just join materiO\'! now you can choose the membership that\'s right for you, or !link', array('!link'=>$frontlink)));
@@ -241,13 +241,13 @@ function materio_user_webform_client_111186_validate($form, &$form_state){
           // TODO : tester si les email ne sont pas deja inscrit sur le site
 
 
-          form_set_error($field_name, t('You must provide a value for the !name field.', array('!name'=>$human_field_name)));      
+          form_set_error($field_name, t('You must provide a value for the !name field.', array('!name'=>$human_field_name)));
         }
       }
     }
-    
 
-  } 
+
+  }
 }
 
 // function materio_user_webform_client_111186_submit($form, &$form_state){
@@ -263,7 +263,7 @@ function materio_user_webform_client_111186_validate($form, &$form_state){
 //       //     $field_name = 'submitted][collaborators]['.$coll_key.']['.$field_key;
 //       //     // dsm($field_name, 'field_name');
 
-//       //     form_set_error($field_name, t('You must provide a value for the !name field.', array('!name'=>$human_field_name)));      
+//       //     form_set_error($field_name, t('You must provide a value for the !name field.', array('!name'=>$human_field_name)));
 //       //   }
 //       // }
 //       $userinfo = array(
@@ -281,9 +281,9 @@ function materio_user_webform_client_111186_validate($form, &$form_state){
 //       // module_invoke_all('user_insert', $edit, $account);
 //       $i++;
 //     }
-    
 
-//   } 
+
+//   }
 
   // enregistrer le type d'adonnement chez les user
 
@@ -299,7 +299,7 @@ function materio_user_help($path, $arg) {
       if($arg[1] == 11187 ){
         global $user;
         // dsm($user, 'user');
-        
+
         if(isset($user->roles[1])){ // anonyme
           $message = t('Please create first a free account and join materio or log in with your existing account,<br />then we\'ll provide you our membership form.', array());
           $content = '<p>' . $message . '</p>';
@@ -340,16 +340,16 @@ function _materio_user_user_update(&$edit, $account, $category){
   // dsm($edit, 'edit');
   // dsm($account, 'account');
   // dsm($category, 'category');
-  
+
   // This is only fired when a user confirms their email address, logintoboggan style
-  if (isset($account->logintoboggan_email_validated) && $account->logintoboggan_email_validated == TRUE) {    
-    $confirmed_rid = materio_user_get_role_by_name(MATERIO_USER_CONFIRMED_USER_ROLE);    
+  if (isset($account->logintoboggan_email_validated) && $account->logintoboggan_email_validated == TRUE) {
+    $confirmed_rid = materio_user_get_role_by_name(MATERIO_USER_CONFIRMED_USER_ROLE);
     $roles = $account->roles + array($confirmed_rid => MATERIO_USER_CONFIRMED_USER_ROLE);
-    
+
     // we have to do this to stop an infinite loop, and also to allow lower weighted modules to possibly do something here
     $user = $account;
     unset($user->logintoboggan_email_validated);
-    
+
     user_save($user, array('roles' => $roles));
 
     drupal_go_to('user/'.$user->uid.'/edit');
@@ -367,5 +367,5 @@ function _materio_user_user_update(&$edit, $account, $category){
  */
 function materio_user_get_role_by_name($name) {
   return array_search($name, user_roles());
-} 
+}
 

+ 4 - 4
materio_user.pages.inc

@@ -1,4 +1,4 @@
-<?php 
+<?php
 
 function materio_user_registerblock(){
   $return = array();
@@ -28,14 +28,14 @@ function materio_user_register_submit(){
     unset ($_SESSION['messages']['error']);
   }else{
     $messages = drupal_get_messages('status');
-    // $return['messages'] = $messages; 
+    // $return['messages'] = $messages;
     drupal_set_message(t("Congratulations, you juste created your free materiO' account, welcome !"), 'status');
     foreach ($messages['status'] as $msg) {
       drupal_set_message($msg, 'status');
     }
   }
   // after registration user is automaticly logged in, thank's to login tobogan module
-  
+
   drupal_json_output($return);
 }
 
@@ -45,7 +45,7 @@ function materio_user_login_submit(){
 
   $form_state = array("values"=>$_POST);
   drupal_form_submit($_POST['form_id'], $form_state);
- 
+
   $return['errors'] = form_get_errors();
   if($return['errors'])
     unset ($_SESSION['messages']['error']);