clean up and fix devise code
This commit is contained in:
parent
139837e997
commit
bb6566a45e
7 changed files with 25 additions and 25 deletions
|
@ -21,20 +21,6 @@ class ApplicationController < ActionController::Base
|
||||||
helper_method :authenticated?
|
helper_method :authenticated?
|
||||||
helper_method :admin?
|
helper_method :admin?
|
||||||
|
|
||||||
def after_sign_in_path_for(resource)
|
|
||||||
sign_in_url = new_user_session_url
|
|
||||||
sign_up_url = new_user_registration_url
|
|
||||||
stored = stored_location_for(User)
|
|
||||||
|
|
||||||
if stored
|
|
||||||
stored
|
|
||||||
elsif request.referer.include?(sign_in_url) || request.referer.include?(sign_up_url)
|
|
||||||
super
|
|
||||||
else
|
|
||||||
request.referer || root_path
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def handle_unauthorized
|
def handle_unauthorized
|
||||||
if authenticated? and params[:controller] == 'maps' and params[:action] == 'show'
|
if authenticated? and params[:controller] == 'maps' and params[:action] == 'show'
|
||||||
redirect_to request_access_map_path(params[:id])
|
redirect_to request_access_map_path(params[:id])
|
||||||
|
@ -42,7 +28,7 @@ class ApplicationController < ActionController::Base
|
||||||
redirect_to root_path, notice: "You don't have permission to see that page."
|
redirect_to root_path, notice: "You don't have permission to see that page."
|
||||||
else
|
else
|
||||||
store_location_for(resource, request.fullpath)
|
store_location_for(resource, request.fullpath)
|
||||||
redirect_to new_user_session_path, notice: 'Try signing in to do that.'
|
redirect_to sign_in_path, notice: 'Try signing in to do that.'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -60,7 +46,7 @@ class ApplicationController < ActionController::Base
|
||||||
|
|
||||||
def require_user
|
def require_user
|
||||||
return true if authenticated?
|
return true if authenticated?
|
||||||
redirect_to new_user_session_path, notice: 'You must be logged in.'
|
redirect_to sign_in_path, notice: 'You must be logged in.'
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -7,6 +7,6 @@ class Users::PasswordsController < Devise::PasswordsController
|
||||||
end
|
end
|
||||||
|
|
||||||
def after_sending_reset_password_instructions_path_for(_resource_name)
|
def after_sending_reset_password_instructions_path_for(_resource_name)
|
||||||
new_user_session_path if is_navigational_format?
|
sign_in_path if is_navigational_format?
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -10,6 +10,18 @@ class Users::RegistrationsController < Devise::RegistrationsController
|
||||||
signed_in_root_path(resource)
|
signed_in_root_path(resource)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def after_sign_in_path_for(resource)
|
||||||
|
stored = stored_location_for(User)
|
||||||
|
return stored if stored
|
||||||
|
|
||||||
|
if request.referer&.match(sign_in_url) || request.referer&.match(sign_up_url)
|
||||||
|
super
|
||||||
|
else
|
||||||
|
request.referer || root_path
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def store_location
|
def store_location
|
||||||
|
|
2
app/controllers/users/sessions_controller.rb
Normal file
2
app/controllers/users/sessions_controller.rb
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
class Users::SessionsController < Devise::SessionsController
|
||||||
|
end
|
|
@ -42,7 +42,7 @@
|
||||||
<%= link_to "Request Invite", request_path %>
|
<%= link_to "Request Invite", request_path %>
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li>
|
||||||
<%= link_to "Login", new_user_session_path %>
|
<%= link_to "Login", sign_in_path %>
|
||||||
</li>
|
</li>
|
||||||
<% end %>
|
<% end %>
|
||||||
<% if current_user %>
|
<% if current_user %>
|
||||||
|
|
|
@ -5,13 +5,13 @@ Doorkeeper.configure do
|
||||||
|
|
||||||
# This block will be called to check whether the resource owner is authenticated or not.
|
# This block will be called to check whether the resource owner is authenticated or not.
|
||||||
resource_owner_authenticator do
|
resource_owner_authenticator do
|
||||||
current_user || redirect_to(new_user_session_url)
|
current_user || redirect_to(sign_in_url)
|
||||||
end
|
end
|
||||||
|
|
||||||
# If you want to restrict access to the web interface for adding oauth authorized applications,
|
# If you want to restrict access to the web interface for adding oauth authorized applications,
|
||||||
# you need to declare the block below.
|
# you need to declare the block below.
|
||||||
admin_authenticator do
|
admin_authenticator do
|
||||||
current_user || redirect_to(new_user_session_url)
|
current_user || redirect_to(sign_in_url)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Authorization Code expiration time (default 10 minutes).
|
# Authorization Code expiration time (default 10 minutes).
|
||||||
|
|
|
@ -65,14 +65,14 @@ Metamaps::Application.routes.draw do
|
||||||
devise_for :users, skip: :sessions, controllers: {
|
devise_for :users, skip: :sessions, controllers: {
|
||||||
registrations: 'users/registrations',
|
registrations: 'users/registrations',
|
||||||
passwords: 'users/passwords',
|
passwords: 'users/passwords',
|
||||||
sessions: 'devise/sessions'
|
sessions: 'users/sessions'
|
||||||
}
|
}
|
||||||
|
|
||||||
devise_scope :user do
|
devise_scope :user do
|
||||||
get 'login' => 'devise/sessions#new', :as => :new_user_session
|
get 'login' => 'users/sessions#new', :as => :sign_in
|
||||||
post 'login' => 'devise/sessions#create', :as => :user_session
|
post 'login' => 'users/sessions#create', :as => :user_session
|
||||||
get 'logout' => 'devise/sessions#destroy', :as => :destroy_user_session
|
get 'logout' => 'users/sessions#destroy', :as => :destroy_user_session
|
||||||
get 'join' => 'devise/registrations#new', :as => :new_user_registration_path
|
get 'join' => 'users/registrations#new', :as => :sign_up
|
||||||
end
|
end
|
||||||
|
|
||||||
resources :users, except: [:index, :destroy] do
|
resources :users, except: [:index, :destroy] do
|
||||||
|
|
Loading…
Reference in a new issue