diff --git a/app/controllers/discourse_subscriptions/subscribe_controller.rb b/app/controllers/discourse_subscriptions/subscribe_controller.rb index 65973b6..476d551 100644 --- a/app/controllers/discourse_subscriptions/subscribe_controller.rb +++ b/app/controllers/discourse_subscriptions/subscribe_controller.rb @@ -5,7 +5,7 @@ module DiscourseSubscriptions include DiscourseSubscriptions::Stripe include DiscourseSubscriptions::Group before_action :set_api_key - requires_login + requires_login except: [:index, :show] def index begin diff --git a/assets/javascripts/discourse/components/login-required.js.es6 b/assets/javascripts/discourse/components/login-required.js.es6 new file mode 100644 index 0000000..fc7682d --- /dev/null +++ b/assets/javascripts/discourse/components/login-required.js.es6 @@ -0,0 +1,17 @@ +import Component from "@ember/component"; +import cookie from "discourse/lib/cookie"; +import DiscourseURL from "discourse/lib/url"; +import { default as getURL } from "discourse-common/lib/get-url"; + +export default Component.extend({ + classNames: ["login-required", "subscriptions"], + actions: { + createAccount() { + const destinationUrl = window.location.href; + const cookiePath = getURL("/"); + + cookie("destination_url", destinationUrl, { path: cookiePath }); + DiscourseURL.redirectTo("/login"); + }, + }, +}); diff --git a/assets/javascripts/discourse/components/product-list.js.es6 b/assets/javascripts/discourse/components/product-list.js.es6 index ac84099..11457ee 100644 --- a/assets/javascripts/discourse/components/product-list.js.es6 +++ b/assets/javascripts/discourse/components/product-list.js.es6 @@ -1,17 +1,12 @@ import discourseComputed from "discourse-common/utils/decorators"; -import User from "discourse/models/user"; import { isEmpty } from "@ember/utils"; import Component from "@ember/component"; export default Component.extend({ classNames: ["product-list"], + @discourseComputed("products") emptyProducts(products) { return isEmpty(products); }, - - @discourseComputed() - isLoggedIn() { - return User.current(); - }, }); diff --git a/assets/javascripts/discourse/controllers/s-index.js.es6 b/assets/javascripts/discourse/controllers/s-index.js.es6 index fa4ba1e..6a5f0ca 100644 --- a/assets/javascripts/discourse/controllers/s-index.js.es6 +++ b/assets/javascripts/discourse/controllers/s-index.js.es6 @@ -1,3 +1,10 @@ import Controller from "@ember/controller"; +import discourseComputed from "discourse-common/utils/decorators"; +import User from "discourse/models/user"; -export default Controller.extend({}); +export default Controller.extend({ + @discourseComputed() + isLoggedIn() { + return User.current(); + }, +}); diff --git a/assets/javascripts/discourse/controllers/s-show.js.es6 b/assets/javascripts/discourse/controllers/s-show.js.es6 index 315a7f8..73755af 100644 --- a/assets/javascripts/discourse/controllers/s-show.js.es6 +++ b/assets/javascripts/discourse/controllers/s-show.js.es6 @@ -5,6 +5,7 @@ import I18n from "I18n"; export default Controller.extend({ selectedPlan: null, + isAnonymous: Ember.computed.not("currentUser"), init() { this._super(...arguments); diff --git a/assets/javascripts/discourse/templates/components/login-required.hbs b/assets/javascripts/discourse/templates/components/login-required.hbs new file mode 100644 index 0000000..6358ebc --- /dev/null +++ b/assets/javascripts/discourse/templates/components/login-required.hbs @@ -0,0 +1,2 @@ +
- {{i18n 'discourse_subscriptions.subscribe.unauthenticated'}} -
- {{/unless}} {{/if}} diff --git a/assets/javascripts/discourse/templates/s/index.hbs b/assets/javascripts/discourse/templates/s/index.hbs index c152336..e0cd9c7 100644 --- a/assets/javascripts/discourse/templates/s/index.hbs +++ b/assets/javascripts/discourse/templates/s/index.hbs @@ -1 +1,4 @@ -{{product-list products=model}} +{{#unless isLoggedIn}} + {{login-required}} +{{/unless}} +{{product-list products=model isLoggedIn=isLoggedIn}} diff --git a/assets/javascripts/discourse/templates/s/show.hbs b/assets/javascripts/discourse/templates/s/show.hbs index 17ddaa8..c6e1b47 100644 --- a/assets/javascripts/discourse/templates/s/show.hbs +++ b/assets/javascripts/discourse/templates/s/show.hbs @@ -26,11 +26,13 @@