diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index a29a2360..f9cef729 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -8,12 +8,12 @@ class ApplicationController < ActionController::Base helper_method :authenticated? helper_method :admin? - after_filter :store_location - - def store_location - # store last url - this is needed for post-login redirect to whatever the user last visited. - if (!request.fullpath.match("/users/") && !request.xhr?) # don't store ajax calls - session[:previous_url] = request.fullpath + def after_sign_in_path_for(resource) + sign_in_url = url_for(:action => 'new', :controller => 'sessions', :only_path => false, :protocol => 'http') + if request.referer == sign_in_url + super + else + stored_location_for(resource) || request.referer || root_path end end diff --git a/app/controllers/registrations_controller.rb b/app/controllers/registrations_controller.rb index 7062ead0..0f0be9ba 100644 --- a/app/controllers/registrations_controller.rb +++ b/app/controllers/registrations_controller.rb @@ -1,12 +1,10 @@ -class RegistrationsController < Devise::RegistrationsController +class Users::RegistrationsController < Devise::RegistrationsController protected - - def after_sign_in_path_for(resource) - session[:previous_url] || root_path - end - - def after_sign_up_path_for(resource) - root_path - end - -end + def after_sign_up_path_for(resource) + signed_in_root_path(resource) + end + + def after_update_path_for(resource) + signed_in_root_path(resource) + end +end \ No newline at end of file diff --git a/app/controllers/users/passwords_controller.rb b/app/controllers/users/passwords_controller.rb new file mode 100644 index 00000000..d1405f6a --- /dev/null +++ b/app/controllers/users/passwords_controller.rb @@ -0,0 +1,6 @@ +class Users::PasswordsController < Devise::PasswordsController + protected + def after_resetting_password_path_for(resource) + signed_in_root_path(resource) + end +end \ No newline at end of file diff --git a/app/controllers/users/registrations_controller.rb b/app/controllers/users/registrations_controller.rb new file mode 100644 index 00000000..5fff2f1c --- /dev/null +++ b/app/controllers/users/registrations_controller.rb @@ -0,0 +1,10 @@ +class Users::RegistrationsController < Devise::RegistrationsController + protected + def after_sign_up_path_for(resource) + signed_in_root_path(resource) + end + + def after_update_path_for(resource) + signed_in_root_path(resource) + end +end diff --git a/app/views/layouts/_account.html.erb b/app/views/layouts/_account.html.erb index 0cee5c7f..ffe69b7e 100644 --- a/app/views/layouts/_account.html.erb +++ b/app/views/layouts/_account.html.erb @@ -24,7 +24,7 @@
  • - <%= link_to "Sign Out", "/sign_out", id: "Logout", :data => { :bypass => 'true'} %> + <%= link_to "Sign Out", "/logout", id: "Logout", :data => { :bypass => 'true'} %>
  • <% else %> @@ -53,3 +53,5 @@ <% end %> <% end %> + +<% # Rails.logger.info(stored_location_for(:user)) %> diff --git a/app/views/layouts/_upperelements.html.erb b/app/views/layouts/_upperelements.html.erb index 25b25301..07aea898 100644 --- a/app/views/layouts/_upperelements.html.erb +++ b/app/views/layouts/_upperelements.html.erb @@ -66,6 +66,7 @@ <% end %> + <% if !(controller_name == "sessions" && action_name == "new") %>
    <% if user && user.image %> @@ -79,5 +80,6 @@ <%= render :partial => 'layouts/account' %>
    + <% end %>
    \ No newline at end of file diff --git a/config/initializers/uservoice.rb b/config/initializers/uservoice.rb index 3b010613..32fdf9e9 100644 --- a/config/initializers/uservoice.rb +++ b/config/initializers/uservoice.rb @@ -1,7 +1,11 @@ require 'uservoice-ruby' def current_sso_token - @current_sso_token ||= UserVoice.generate_sso_token('metamapscc', ENV['SSO_KEY'], { - :email => current_user.email - }, 300) # Default expiry time is 5 minutes = 300 seconds + if ENV['SSO_KEY'] + @current_sso_token ||= UserVoice.generate_sso_token('metamapscc', ENV['SSO_KEY'], { + :email => current_user.email + }, 300) # Default expiry time is 5 minutes = 300 seconds + else + @current_sso_token = '' + end end \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index ef03d2e8..4a525575 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,10 +1,6 @@ Metamaps::Application.routes.draw do root to: 'main#home', via: :get - - devise_scope :user do - get "join" => "devise/registrations#new" - end match 'request', to: 'main#requestinvite', via: :get, as: :request @@ -31,10 +27,15 @@ Metamaps::Application.routes.draw do match 'maps/:id/embed', to: 'maps#embed', via: :get, as: :embed match 'maps/:id/contains', to: 'maps#contains', via: :get, as: :contains - devise_for :users, :controllers => { :registrations => "registrations" }, :path_names => { :sign_in => 'login', :sign_out => 'logout' } - devise_scope :user do - get "sign_out", :to => "devise/sessions#destroy" + devise_for :users, controllers: { registrations: 'users/registrations', passwords: 'users/passwords', sessions: 'devise/sessions' }, :skip => [:sessions] + + devise_scope :user do + get 'login' => 'devise/sessions#new', :as => :new_user_session + post 'login' => 'devise/sessions#create', :as => :user_session + get 'logout' => 'devise/sessions#destroy', :as => :destroy_user_session + get 'join' => 'devise/registrations#new', :as => :new_user_registration end + match 'user/updatemetacodes', to: 'users#updatemetacodes', via: :post, as: :updatemetacodes resources :users, except: [:index, :destroy] end