From 3d461d59956a8ad69b1060703d9ba523d10961b6 Mon Sep 17 00:00:00 2001 From: poupotte Date: Wed, 7 Oct 2015 17:44:38 +0200 Subject: [PATCH 1/2] Don't submit register request multiple times, refs #174 --- client/app/states/registration.coffee | 30 ++++++++++++++++----------- server/views/index.jade | 2 +- 2 files changed, 19 insertions(+), 13 deletions(-) diff --git a/client/app/states/registration.coffee b/client/app/states/registration.coffee index b5c9834d..ce11feb5 100644 --- a/client/app/states/registration.coffee +++ b/client/app/states/registration.coffee @@ -124,6 +124,7 @@ module.exports = class Registration extends StateModel initSignup: -> # Declares a stream to receive the form submission @signup = new Bacon.Bus() + @isSignup = false # If the current step is `preset`, set the valve to block the step flow: # it will resume when the sign up form request returns a success. @@ -141,18 +142,23 @@ module.exports = class Registration extends StateModel - data: an object containing the form input entries as key/values pairs ### signupSubmit: (data) => - # Submit the form content to the register endpoint and creates a stream - # with the ajax promise - req = Bacon.fromPromise $.post '/register', JSON.stringify data - # If the request is successful, we stores the username in the global - # scope to prepare the login view. - req.subscribe -> window.username = data['public_name'] - # Unblock the step flow valve when the response is successful - @stepValve.plug req.map false - # Map request errors in the `errors` stream - @errors.plug req.errors().mapError '.responseJSON.errors' - # Map the request end to the next button busy state - @nextBusy.plug req.mapEnd false + if @isSignup + # Map the request end to the next button busy state + @nextBusy.push new Bacon.Next(false) + else + @isSignup = true + # Submit the form content to the register endpoint and creates a stream + # with the ajax promise + req = Bacon.fromPromise $.post '/register', JSON.stringify data + # If the request is successful, we stores the username in the global + # scope to prepare the login view. + req.subscribe -> window.username = data['public_name'] + # Unblock the step flow valve when the response is successful + @stepValve.plug req.map false + # Map request errors in the `errors` stream + @errors.plug req.errors().mapError '.responseJSON.errors' + # Map the request end to the next button busy state + @nextBusy.plug req.mapEnd false ### diff --git a/server/views/index.jade b/server/views/index.jade index b50c99c8..e0dba1b5 100644 --- a/server/views/index.jade +++ b/server/views/index.jade @@ -2,7 +2,7 @@ extends layouts/_base block title title Cozy - Your Private Personal Cloud - meta(name="description", content="Cozy is an app-based personal cloud you can host at home. It allows you to own and connect your data. It turns a low-cost piece of hardware like a Raspberry Pi 2 or an online VPS into a powerful app platform. It comes with common applications like a contacts manager, calendar, webmail and filebox." + meta(name="description", content="Cozy is an app-based personal cloud you can host at home. It allows you to own and connect your data. It turns a low-cost piece of hardware like a Raspberry Pi 2 or an online VPS into a powerful app platform. It comes with common applications like a contacts manager, calendar, webmail and filebox.") block content From 29d91aff97c718e9fd32a122ef2bf7746149747d Mon Sep 17 00:00:00 2001 From: poupotte Date: Fri, 16 Oct 2015 11:20:51 +0200 Subject: [PATCH 2/2] fix multiple registration --- client/app/states/registration.coffee | 30 ++++++++++--------------- client/app/views/register/preset.coffee | 8 ++++++- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/client/app/states/registration.coffee b/client/app/states/registration.coffee index ce11feb5..b5c9834d 100644 --- a/client/app/states/registration.coffee +++ b/client/app/states/registration.coffee @@ -124,7 +124,6 @@ module.exports = class Registration extends StateModel initSignup: -> # Declares a stream to receive the form submission @signup = new Bacon.Bus() - @isSignup = false # If the current step is `preset`, set the valve to block the step flow: # it will resume when the sign up form request returns a success. @@ -142,23 +141,18 @@ module.exports = class Registration extends StateModel - data: an object containing the form input entries as key/values pairs ### signupSubmit: (data) => - if @isSignup - # Map the request end to the next button busy state - @nextBusy.push new Bacon.Next(false) - else - @isSignup = true - # Submit the form content to the register endpoint and creates a stream - # with the ajax promise - req = Bacon.fromPromise $.post '/register', JSON.stringify data - # If the request is successful, we stores the username in the global - # scope to prepare the login view. - req.subscribe -> window.username = data['public_name'] - # Unblock the step flow valve when the response is successful - @stepValve.plug req.map false - # Map request errors in the `errors` stream - @errors.plug req.errors().mapError '.responseJSON.errors' - # Map the request end to the next button busy state - @nextBusy.plug req.mapEnd false + # Submit the form content to the register endpoint and creates a stream + # with the ajax promise + req = Bacon.fromPromise $.post '/register', JSON.stringify data + # If the request is successful, we stores the username in the global + # scope to prepare the login view. + req.subscribe -> window.username = data['public_name'] + # Unblock the step flow valve when the response is successful + @stepValve.plug req.map false + # Map request errors in the `errors` stream + @errors.plug req.errors().mapError '.responseJSON.errors' + # Map the request end to the next button busy state + @nextBusy.plug req.mapEnd false ### diff --git a/client/app/views/register/preset.coffee b/client/app/views/register/preset.coffee index b2f26b4c..52cc16b8 100644 --- a/client/app/views/register/preset.coffee +++ b/client/app/views/register/preset.coffee @@ -47,12 +47,18 @@ module.exports = class RegisterPresetView extends FormView @initForm() @initErrors() + # Step valve + @onStep = @model.get('step').sampledBy(@form).map (step) -> + step is 'preset' + .toProperty() + + # Set the next button enable state when all required fields are filled @model.nextEnabled.plug @required.changes() # Create a new stream from the submit one that is filtered onto the step # (e.g. the form will not be submitted if we're already not in the step) - submit = @form.filter => @model.get('step').map (cur) -> cur is 'preset' + submit = @form.filter @onStep # We plug it to the signup stream and to the next button busy state (e.g # the busy state is enable when the form is submitted) @model.signup.plug submit