From 0c711448333575dbdff797a2ef8339cc07f500b9 Mon Sep 17 00:00:00 2001 From: Bachir Soussi Chiadmi Date: Thu, 3 Jul 2014 17:27:36 +0200 Subject: [PATCH] disabled submit on registration to avoid duplicate account creation --- js/materio_user.js | 30 ++++++++++++++++++++++-------- js/materio_user.min.js | 30 ++++++++++++++++++++++-------- materio_user.module | 40 ++++++++++++++++++++-------------------- materio_user.pages.inc | 8 ++++---- 4 files changed, 68 insertions(+), 40 deletions(-) diff --git a/js/materio_user.js b/js/materio_user.js index f7f92c40..c83806b1 100755 --- a/js/materio_user.js +++ b/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 = $('
').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($('
').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); \ No newline at end of file diff --git a/js/materio_user.min.js b/js/materio_user.min.js index 400f414a..fa4344c0 100755 --- a/js/materio_user.min.js +++ b/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 = $('
').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($('
').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); \ No newline at end of file diff --git a/materio_user.module b/materio_user.module index 499fcd7a..0a2f5ece 100755 --- a/materio_user.module +++ b/materio_user.module @@ -1,4 +1,4 @@ -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', ''); // // 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,
then we\'ll provide you our membership form.', array()); $content = '

' . $message . '

'; @@ -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()); -} +} diff --git a/materio_user.pages.inc b/materio_user.pages.inc index 5ca522a5..9cc11058 100644 --- a/materio_user.pages.inc +++ b/materio_user.pages.inc @@ -1,4 +1,4 @@ -$_POST); drupal_form_submit($_POST['form_id'], $form_state); - + $return['errors'] = form_get_errors(); if($return['errors']) unset ($_SESSION['messages']['error']);