Merge pull request #781 from metamaps/fix/registration

clean up and fix devise code
This commit is contained in:
Devin Howard 2016-10-19 14:36:39 +08:00 committed by GitHub
commit f75d5253b3
7 changed files with 25 additions and 25 deletions

View file

@ -21,20 +21,6 @@ class ApplicationController < ActionController::Base
helper_method :authenticated?
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
if authenticated? and params[:controller] == 'maps' and params[:action] == 'show'
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."
else
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
@ -60,7 +46,7 @@ class ApplicationController < ActionController::Base
def require_user
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
end

View file

@ -7,6 +7,6 @@ class Users::PasswordsController < Devise::PasswordsController
end
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

View file

@ -10,6 +10,18 @@ class Users::RegistrationsController < Devise::RegistrationsController
signed_in_root_path(resource)
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
def store_location

View file

@ -0,0 +1,2 @@
class Users::SessionsController < Devise::SessionsController
end

View file

@ -42,7 +42,7 @@
<%= link_to "Request Invite", request_path %>
</li>
<li>
<%= link_to "Login", new_user_session_path %>
<%= link_to "Login", sign_in_path %>
</li>
<% end %>
<% if current_user %>

View file

@ -5,13 +5,13 @@ Doorkeeper.configure do
# This block will be called to check whether the resource owner is authenticated or not.
resource_owner_authenticator do
current_user || redirect_to(new_user_session_url)
current_user || redirect_to(sign_in_url)
end
# If you want to restrict access to the web interface for adding oauth authorized applications,
# you need to declare the block below.
admin_authenticator do
current_user || redirect_to(new_user_session_url)
current_user || redirect_to(sign_in_url)
end
# Authorization Code expiration time (default 10 minutes).

View file

@ -65,14 +65,14 @@ Metamaps::Application.routes.draw do
devise_for :users, skip: :sessions, controllers: {
registrations: 'users/registrations',
passwords: 'users/passwords',
sessions: 'devise/sessions'
sessions: 'users/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_path
get 'login' => 'users/sessions#new', :as => :sign_in
post 'login' => 'users/sessions#create', :as => :user_session
get 'logout' => 'users/sessions#destroy', :as => :destroy_user_session
get 'join' => 'users/registrations#new', :as => :sign_up
end
resources :users, except: [:index, :destroy] do