Redirect Ember routes to login if login required

This commit is contained in:
Chris Hunt 2013-06-04 15:39:35 -07:00
parent 789289a290
commit 122f9188c9
7 changed files with 25 additions and 1 deletions

View File

@ -168,6 +168,10 @@ Discourse = Ember.Application.createWithMixins({
); );
}.property(), }.property(),
redirectIfLoginRequired: function(route) {
if(this.get('loginRequired')) { route.transitionTo('login'); }
},
/** /**
Our own $.ajax method. Makes sure the .then method executes in an Ember runloop Our own $.ajax method. Makes sure the .then method executes in an Ember runloop
for performance reasons. Also automatically adjusts the URL to support installs for performance reasons. Also automatically adjusts the URL to support installs

View File

@ -28,7 +28,7 @@ Discourse.StaticController = Discourse.Controller.extend({
}); });
Discourse.StaticController.reopenClass({ Discourse.StaticController.reopenClass({
pages: ['faq', 'tos', 'privacy'] pages: ['faq', 'tos', 'privacy', 'login']
}); });

View File

@ -8,6 +8,8 @@
**/ **/
Discourse.FilteredListRoute = Discourse.Route.extend({ Discourse.FilteredListRoute = Discourse.Route.extend({
redirect: function() { Discourse.redirectIfLoginRequired(this); },
exit: function() { exit: function() {
this._super(); this._super();

View File

@ -8,6 +8,8 @@
**/ **/
Discourse.ListCategoriesRoute = Discourse.Route.extend({ Discourse.ListCategoriesRoute = Discourse.Route.extend({
redirect: function() { Discourse.redirectIfLoginRequired(this); },
events: { events: {
createCategory: function() { createCategory: function() {

View File

@ -8,6 +8,8 @@
**/ **/
Discourse.TopicRoute = Discourse.Route.extend({ Discourse.TopicRoute = Discourse.Route.extend({
redirect: function() { Discourse.redirectIfLoginRequired(this); },
events: { events: {
// Modals that can pop up within a topic // Modals that can pop up within a topic

View File

@ -0,0 +1,13 @@
<ul class="nav-pills">
<li><a class='active' href="<%=login_path%>">Welcome</a></li>
<li><a href="<%=faq_path%>">FAQ</a></li>
<li><a href="<%=tos_path%>">Terms of Service</a></li>
<li><a href="<%=privacy_path%>">Privacy</a></li>
</ul>
<h2><a href="#welcome">Welcome to <%= SiteSetting.title %></a></h2>
<p>
We are excited to have you participate in <%= SiteSetting.title %>. Please
create an account or login to continue.
</p>

View File

@ -103,6 +103,7 @@ Discourse::Application.routes.draw do
resources :static resources :static
post 'login' => 'static#enter' post 'login' => 'static#enter'
get 'login' => 'static#show', id: 'login'
get 'faq' => 'static#show', id: 'faq' get 'faq' => 'static#show', id: 'faq'
get 'tos' => 'static#show', id: 'tos' get 'tos' => 'static#show', id: 'tos'
get 'privacy' => 'static#show', id: 'privacy' get 'privacy' => 'static#show', id: 'privacy'