Skip to content

Commit

Permalink
Merge pull request #76 from prinzdezibel/development
Browse files Browse the repository at this point in the history
Allow checkout as guest (without user account)
  • Loading branch information
Aaron Judd committed Jan 22, 2015
2 parents e496213 + bc1e543 commit 9fc59ec
Show file tree
Hide file tree
Showing 18 changed files with 150 additions and 27 deletions.
3 changes: 1 addition & 2 deletions packages/reaction-core/client/app.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,5 @@ _.extend ReactionCore,
getShopId: ->
return @shopId


Meteor.startup ->
ReactionCore.init()
ReactionCore.init()
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@ Template.core_loginButtonsChangePassword.replaces("_loginButtonsChangePassword")
# extend login_buttons_single.html to use Reaction specific templates
Template.core_loginButtonsLoggedOutSingleLoginButton.replaces("_loginButtonsLoggedOutSingleLoginButton")
Template.core_loginButtonsLoggingInSingleLoginButton.replaces("_loginButtonsLoggingInSingleLoginButton")
Template.core_loginButtonsLoggedInSingleLogoutButton.replaces("_loginButtonsLoggedInSingleLogoutButton")
Template.core_loginButtonsLoggedInSingleLogoutButton.replaces("_loginButtonsLoggedInSingleLogoutButton")
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
loginButtonsSession = Accounts._loginButtonsSession

Template._loginButtonsLoggedOutPasswordService.helpers
# Build a decorator to wrap the original function from Accounts package. When called,
# just modify the visible property of the password field.
fields: ((func) ->
->
fields = func()
unless loginButtonsSession.get("inSignupFlow")
fields.forEach (item, i) ->
if item.fieldName is "password"
item.visible = ->
not Session.get("Reactioncommerce.Core.loginButtons.inLoginAsGuestFlow")
return
return fields
)(Blaze._getTemplateHelper(Template._loginButtonsLoggedOutPasswordService, "fields"))

inLoginAsGuestFlow: ->
return Session.get "Reactioncommerce.Core.loginButtons.inLoginAsGuestFlow"

inLoginFlow: ->
return not Session.get("Reactioncommerce.Core.loginButtons.inLoginAsGuestFlow") and
not loginButtonsSession.get("inSignupFlow") and
not loginButtonsSession.get("inForgotPasswordFlow")

resetLoginFlow: ->
Session.set 'Reactioncommerce.Core.loginButtons.inLoginAsGuestFlow', false
loginButtonsSession.set "inSignupFlow", false
loginButtonsSession.set 'inForgotPasswordFlow', false

canCheckoutAsGuest: ->
!!ReactionCore.canCheckoutAsGuest()
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
{{#if hasOtherServices}} {{! the password service will always come last }}
{{> _loginButtonsLoggedOutPasswordServiceSeparator}}
{{/if}}
{{> _loginButtonsLoggedOutPasswordService}}
{{> _loginButtonsLoggedOutPasswordService inline=../inline }}
{{else}}
{{> _loginButtonsLoggedOutSingleLoginButton}}
{{/if}}
Expand All @@ -94,6 +94,9 @@
</template>

<template name="core_loginButtonsLoggedOutPasswordService">
{{#unless inline }}
{{resetLoginFlow}}
{{/unless}}
{{#if inForgotPasswordFlow}}
{{> _forgotPasswordForm}}
{{else}}
Expand All @@ -107,18 +110,22 @@
<div class="login-button login-button-form-submit" id="login-buttons-password">
{{#if inSignupFlow}}
<span data-i18n="accountsUI.createAccount">{{i18n "accountsUI.createAccount"}}</span>
{{else}}
{{/if}}
{{#if inLoginFlow}}
<span data-i18n="accountsUI.signIn">{{i18n "accountsUI.signIn"}}</span>
{{/if}}
{{#if inline }}
{{#if canCheckoutAsGuest}}
{{#if inLoginAsGuestFlow}}
<span data-i18n="accountsUI.checkoutAsGuest">{{i18n "accountsUI.checkoutAsGuest"}}</span>
{{/if}}
{{/if}}
{{/if}}
</div>

{{#if inLoginFlow}}
{{#if showCreateAccountLink}}
<div class="additional-link-container">
<a id="signup-link" class="additional-link">
<span data-i18n="accountsUI.createAccount">{{i18n "accountsUI.createAccount"}}</span>
</a>
</div>
{{> _loginButtonsBackToSignUpLink}}
{{/if}}

{{#if showForgotPasswordLink}}
Expand All @@ -128,10 +135,25 @@
</a>
</div>
{{/if}}
{{#if inline }}
{{#if canCheckoutAsGuest }}
{{> core_loginButtonsBackToGuestLoginLink}}
{{/if}}
{{/if}}
{{/if}}

{{#if inSignupFlow}}
{{> _loginButtonsBackToLoginLink}}
{{#if canCheckoutAsGuest }}
{{#if inline }}
{{> core_loginButtonsBackToGuestLoginLink}}
{{/if}}
{{/if}}
{{/if}}
{{#if canCheckoutAsGuest }}
{{#if inLoginAsGuestFlow}}
{{> _loginButtonsBackToLoginLink}}
{{> _loginButtonsBackToSignUpLink}}
{{/if}}
{{/if}}
</div>
{{/if}}
Expand All @@ -154,12 +176,25 @@
</div>
</template>

<template name="_loginButtonsBackToSignUpLink">
<div class="additional-link-container">
<a id="signup-link" class="additional-link">
<span data-i18n="accountsUI.createAccount">{{i18n "accountsUI.createAccount"}}</span>
</a>
</div>
</template>

<template name="core_loginButtonsBackToLoginLink">
<div class="additional-link-container">
<a id="back-to-login-link" class="additional-link" data-i18n="accountsUI.signIn">{{i18n "accountsUI.signIn"}}</a>
</div>
</template>

<template name="core_loginButtonsBackToGuestLoginLink">
<div class="additional-link-container">
<a id="back-to-guest-login-link" class="additional-link" data-i18n="accountsUI.checkoutAsGuest">{{i18n "accountsUI.checkoutAsGuest"}}</a>
</div>
</template>

<!--
This strategy for login forms means that browsers' "Remember password"
Expand Down
35 changes: 34 additions & 1 deletion packages/reaction-core/client/templates/accounts/accounts.coffee
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
loginButtonsSession = Accounts._loginButtonsSession


Template.accounts.helpers
chooseTemplate: (name) ->
name = this.valueOf()
Expand Down Expand Up @@ -30,6 +31,7 @@ Template.accounts.events
password = elementValueById("login-password")
loginButtonsSession.set "inSignupFlow", true
loginButtonsSession.set "inForgotPasswordFlow", false
Session.set "Reactioncommerce.Core.loginButtons.inLoginAsGuestFlow", false

# force the ui to update so that we have the approprate fields to fill in
Tracker.flush()
Expand Down Expand Up @@ -68,6 +70,7 @@ Template.accounts.events
usernameOrEmail = trimmedElementValueById("login-username-or-email")
loginButtonsSession.set "inSignupFlow", false
loginButtonsSession.set "inForgotPasswordFlow", true
Session.set "Reactioncommerce.Core.loginButtons.inLoginAsGuestFlow", false

# force the ui to update so that we have the approprate fields to fill in
Tracker.flush()
Expand All @@ -78,6 +81,21 @@ Template.accounts.events
else document.getElementById("forgot-password-email").value = usernameOrEmail if usernameOrEmail.indexOf("@") isnt -1 if usernameOrEmail isnt null
return

"click #back-to-guest-login-link": ->
loginButtonsSession.resetMessages()

email = trimmedElementValueById("login-email") or trimmedElementValueById("forgot-password-email") # Ughh. Standardize on names?

loginButtonsSession.set 'inSignupFlow', false
loginButtonsSession.set 'inForgotPasswordFlow', false
Session.set "Reactioncommerce.Core.loginButtons.inLoginAsGuestFlow", true

# force the ui to update so that we have the approprate fields to fill in
Tracker.flush()

document.getElementById("login-email").value = email if document.getElementById("login-email")
document.getElementById("login-username-or-email").value = email or username if document.getElementById("login-username-or-email")

"click #back-to-login-link": ->
loginButtonsSession.resetMessages()
username = trimmedElementValueById("login-username")
Expand All @@ -86,6 +104,7 @@ Template.accounts.events
password = elementValueById("login-password")
loginButtonsSession.set "inSignupFlow", false
loginButtonsSession.set "inForgotPasswordFlow", false
Session.set "Reactioncommerce.Core.loginButtons.inLoginAsGuestFlow", false

# force the ui to update so that we have the approprate fields to fill in
Tracker.flush()
Expand Down Expand Up @@ -148,8 +167,11 @@ trimmedElementValueById = (id) ->
element.value.replace /^\s*|\s*$/g, ""

loginOrSignup = ->

if loginButtonsSession.get("inSignupFlow")
signup()
else if Session.get('Reactioncommerce.Core.loginButtons.inLoginAsGuestFlow')
loginAsGuest()
else
login()
return
Expand Down Expand Up @@ -189,7 +211,18 @@ login = ->
else
loginButtonsSession.closeDropdown()
return
return

loginAsGuest = ->
email = trimmedElementValueById("login-email")
if email isnt null
unless validateEmail(email)
return
Meteor.loginAsGuest email, (error, result) ->
if error
loginButtonsSession.errorMessage error
else
loginButtonsSession.closeDropdown()
return

signup = ->
Expand Down Expand Up @@ -291,4 +324,4 @@ correctDropdownZIndexes = ->
while n.nodeName isnt "BODY"
n.style.zIndex = 1 if n.style.zIndex is 0
n = n.parentNode
return
return
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
{{else}}
<a href="#" class="dropdown-toggle" data-toggle="dropdown"><span data-i18n="accountsUI.signIn">Sign In</span><b class="caret"></b></a>
<div class="accounts-dialog accounts-inline dropdown-menu pull-right">
{{>_loginButtonsLoggedOutAllServices}}
{{> _loginButtonsLoggedOutAllServices}}
</div>
{{/if}}
</div>
Expand All @@ -29,4 +29,4 @@
<div class="btn btn-primary btn-block" id="logout" data-i18n="accountsUI.signOut">Sign Out</div>
</div>

</template>
</template>
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template name="loginInline">
<div class="accounts-dialog accounts-inline">
{{>_loginButtonsLoggedOutAllServices}}
{{>_loginButtonsLoggedOutAllServices inline="inline"}}
</div>
</template>
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,11 @@
.hline { text-decoration: line-through; color: lightgrey; }
.or-text { font-weight: bold; }

#signup-link { float: right; }
#forgot-password-link { float: left; }
#back-to-login-link { float: right; }
.additional-link {
float: right;
margin-left: 15px;
}

#forgot-password-link { margin-left:0; float: left; }

}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Template.cartCheckout.helpers
loginStatus: () ->
unless Meteor.userId()?
status = "checkout-step-badge"
status = false
else if Meteor.user()
status = "checkout-step-badge-completed"
status
Expand Down Expand Up @@ -34,4 +34,4 @@ Template.cartCheckout.rendered = ->

Template.cartCheckout.events
'click #checkout-step-payment-methods': () ->
# Set review to complete
# Set review to complete
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<div class="row cart-checkout-steps">
<div class="col-md-8">
<div class="row">
{{#if currentUser}}
{{#if loginStatus}}
<div class="col-md-12"><i class="{{loginStatus}}">1</i>
<div class="panel panel-default">
<div class="panel-heading">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
loginButtonsSession = Accounts._loginButtonsSession

Template.checkoutLogin.rendered = ->
# initial screen in checkout should be to create an account
loginButtonsSession = Accounts._loginButtonsSession
loginButtonsSession.set "inSignupFlow", true
if !!ReactionCore.canCheckoutAsGuest()
Session.set 'Reactioncommerce.Core.loginButtons.inLoginAsGuestFlow', true
loginButtonsSession.set "inSignupFlow", false
else
loginButtonsSession.set "inSignupFlow", true
Session.set 'Reactioncommerce.Core.loginButtons.inLoginAsGuestFlow', false

3 changes: 3 additions & 0 deletions packages/reaction-core/common/reaction-core.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
ReactionCore.canCheckoutAsGuest = () ->
return Meteor.settings?.public?.CHECKOUT_AS_GUEST || false

2 changes: 1 addition & 1 deletion packages/reaction-core/common/register.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,4 @@ ReactionCore.registerPackage
permission: "dashboard/settings/account"
group: "Shop Settings"
}
]
]
3 changes: 3 additions & 0 deletions packages/reaction-core/package.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ Package.onUse(function (api) {
api.use("aldeed:[email protected]");
api.use("aldeed:[email protected]","client");
api.use("iron:[email protected]");
api.use("prinzdezibel:[email protected]");
api.use("ongoworks:[email protected]");
api.use("ongoworks:[email protected]");
api.use("ongoworks:[email protected]");
Expand Down Expand Up @@ -105,6 +106,7 @@ Package.onUse(function (api) {
"lib/statemachine/state-machine.js",
"common/packageGlobals.js",
"common/common.coffee",
"common/reaction-core.coffee",
"common/register.coffee",
"common/routing.coffee",
"common/schemas/packages.coffee",
Expand Down Expand Up @@ -198,6 +200,7 @@ Package.onUse(function (api) {
"client/templates/accounts/accounts-ui/login_buttons.html",
"client/templates/accounts/accounts-ui/login_buttons_dialogs.html",
"client/templates/accounts/accounts-ui/login_buttons_dropdown.html",
"client/templates/accounts/accounts-ui/login_buttons_dropdown.coffee",
"client/templates/accounts/accounts-ui/login_buttons_single.html",
"client/templates/accounts/accounts-ui/accounts-ui.coffee",

Expand Down
3 changes: 2 additions & 1 deletion packages/reaction-core/private/data/i18n/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
"username": "Benutzername",
"usernameOrEmail": "Benutzername oder E-Mail",
"with": "mit",
"checkoutAsGuest": "Ohne Benutzerkonto bestellen",
"info": {
"emailSent": "E-Mail gesendet",
"emailVerified": "E-Mail verifiziert",
Expand Down Expand Up @@ -78,7 +79,7 @@
"userHasNoPasswordSet": "Kein Passwort für den Benutzer angegeben",
"userNotFound": "Benutzer nicht gefunden",
"verifyEmailLinkExpired": "Das Token zur Verifizierung der E-Mail ist abgelaufen",
"verifyEmailLinkIsForUnknownAddress": "Verifizierung des Tokens fehlgeschlagen. (Das Token gehört zu einer unbekannten E-Mail-Adresse."
"verifyEmailLinkIsForUnknownAddress": "Verifizierung des Tokens fehlgeschlagen. (Das Token gehört zu einer unbekannten E-Mail-Adresse.)"
}
}
}
Expand Down
1 change: 1 addition & 0 deletions packages/reaction-core/private/data/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@
"username": "Username",
"usernameOrEmail": "Username or email",
"with": "with",
"checkoutAsGuest": "Checkout without user account",
"info": {
"emailSent": "Email Sent",
"emailVerified": "Email verified",
Expand Down
1 change: 0 additions & 1 deletion packages/reaction-core/server/app.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ ReactionCore.Events = logger.bunyan.createLogger(
# set bunyan logging level
ReactionCore.Events.level(isDebug)


###
# Global reaction shop permissions methods
###
Expand Down
Loading

0 comments on commit 9fc59ec

Please sign in to comment.