Skip to content

Commit

Permalink
Don't submit register request multiple times, refs cozy#174
Browse files Browse the repository at this point in the history
  • Loading branch information
poupotte committed Oct 7, 2015
1 parent 568672b commit 3d461d5
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 13 deletions.
30 changes: 18 additions & 12 deletions client/app/states/registration.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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


###
Expand Down
2 changes: 1 addition & 1 deletion server/views/index.jade
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 3d461d5

Please sign in to comment.