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(),
redirectIfLoginRequired: function(route) {
if(this.get('loginRequired')) { route.transitionTo('login'); }
},
/**
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

View file

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

View file

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

View file

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

View file

@ -8,6 +8,8 @@
**/
Discourse.TopicRoute = Discourse.Route.extend({
redirect: function() { Discourse.redirectIfLoginRequired(this); },
events: {
// 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
post 'login' => 'static#enter'
get 'login' => 'static#show', id: 'login'
get 'faq' => 'static#show', id: 'faq'
get 'tos' => 'static#show', id: 'tos'
get 'privacy' => 'static#show', id: 'privacy'