Skip to content

Commit

Permalink
Show login button on 404 page. Add routes to show login and signup mo…
Browse files Browse the repository at this point in the history
…dals when page/route loads. If logged in and showing 404 page, load ember app.
  • Loading branch information
nlalonde committed Feb 18, 2014
1 parent 2a8734f commit 7f6b2e5
Show file tree
Hide file tree
Showing 9 changed files with 48 additions and 3 deletions.
4 changes: 4 additions & 0 deletions app/assets/javascripts/discourse/routes/application_routes.js
Expand Up @@ -8,6 +8,7 @@ Discourse.Route.buildRoutes(function() {
var router = this;

// Generate static page routes
// e.g., faq, tos, privacy, login
_.each(Discourse.StaticController.PAGES, function (page) {
router.route(page, { path: '/' + page });
});
Expand Down Expand Up @@ -90,4 +91,7 @@ Discourse.Route.buildRoutes(function() {

this.route('invited');
});

this.route('signup', {path: '/signup'});
this.route('login', {path: '/login'});
});
11 changes: 11 additions & 0 deletions app/assets/javascripts/discourse/routes/login_route.js
@@ -0,0 +1,11 @@
Discourse.LoginRoute = Discourse.Route.extend({
beforeModel: function() {
if (!Discourse.SiteSetting.login_required) {

This comment has been minimized.

Copy link
@vikhyat

vikhyat Apr 16, 2014

Contributor

Typo? Shouldn't this be "Discourse.SiteSettings.login_required"?

this.transitionTo('discovery.latest').then(function(e) {

This comment has been minimized.

Copy link
@eviltrout

eviltrout Feb 19, 2014

Contributor

What if they've made categories their default page?

Ember.run.next(function() {
e.send('showLogin');
});
});
}
}
});
9 changes: 9 additions & 0 deletions app/assets/javascripts/discourse/routes/signup_route.js
@@ -0,0 +1,9 @@
Discourse.SignupRoute = Discourse.Route.extend({
beforeModel: function() {
this.transitionTo('discovery.latest').then(function(e) {

This comment has been minimized.

Copy link
@eviltrout

eviltrout Feb 19, 2014

Contributor

this function pattern is used three times. maybe a helper would be good. You could say

this.transitionModal('route.name', 'showCreateAccount');

Ember.run.next(function() {
e.send('showCreateAccount');
});
});
}
});
12 changes: 12 additions & 0 deletions app/assets/javascripts/discourse/routes/static_route.js
Expand Up @@ -26,3 +26,15 @@ _.each(Discourse.StaticController.PAGES, function(page) {
});

});

Discourse.LoginRoute.reopen({
beforeModel: function() {
if (!Discourse.SiteSettings.login_required) {
this.transitionTo('discovery.latest').then(function(e) {
Ember.run.next(function() {
e.send('showLogin');
});
});
}
}
});
2 changes: 1 addition & 1 deletion app/controllers/application_controller.rb
Expand Up @@ -104,7 +104,7 @@ def rescue_discourse_actions(message, error)
# from the above rescue_from blocks will fail because that isn't valid json.
render status: error, layout: false, text: (error == 404) ? build_not_found_page(error) : message
else
render text: build_not_found_page(error, 'no_js')
render text: build_not_found_page(error, current_user ? 'application' : 'no_js')
end
end

Expand Down
5 changes: 5 additions & 0 deletions app/views/layouts/no_js.html.erb
Expand Up @@ -24,6 +24,11 @@
<div class="title span13">
<a href="/"><img src="<%=SiteSetting.logo_url%>" alt="<%=SiteSetting.title%>" id="site-logo"></a>
</div>
<% unless current_user %>
<div class='panel clearfix'>
<a href="/login" class='btn btn-primary btn-small'><%= I18n.t('log_in') %></a>
</div>
<% end %>
</div>
</div>
</div>
Expand Down
4 changes: 3 additions & 1 deletion app/views/static/login.html.erb
@@ -1 +1,3 @@
<%= markdown_content(:login_required_welcome_message) %>
<% if SiteSetting.login_required %>
<%= markdown_content(:login_required_welcome_message) %>
<% end %>
1 change: 1 addition & 0 deletions config/locales/server.en.yml
Expand Up @@ -20,6 +20,7 @@ en:
posts: "posts"
loading: "Loading"
powered_by_html: 'Powered by <a href="http://www.discourse.org">Discourse</a>, best viewed with JavaScript enabled'
log_in: "Log In"

via: "%{username} via %{site_name}"
is_reserved: "is reserved"
Expand Down
3 changes: 2 additions & 1 deletion config/routes.rb
Expand Up @@ -14,7 +14,7 @@
match "/404", to: "exceptions#not_found", via: [:get, :post]

mount Sidekiq::Web => "/sidekiq", constraints: AdminConstraint.new

get "site" => "site#index"

resources :forums
Expand Down Expand Up @@ -155,6 +155,7 @@
get "faq" => "static#show", id: "faq"
get "tos" => "static#show", id: "tos"
get "privacy" => "static#show", id: "privacy"
get "signup" => "list#latest"

get "users/search/users" => "users#search_users"
get "users/password-reset/:token" => "users#password_reset"
Expand Down

0 comments on commit 7f6b2e5

Please sign in to comment.