mirror of
https://github.com/internetee/registry.git
synced 2025-06-11 07:04:47 +02:00
Refactor Devise integration
- Use scoped users - Use the named route helpers instead of hardcoded paths
This commit is contained in:
parent
c31f507c25
commit
9684c8e59f
52 changed files with 313 additions and 280 deletions
|
@ -1,7 +1,7 @@
|
|||
class Registrant::SessionsController < Devise::SessionsController
|
||||
layout 'registrant/application'
|
||||
|
||||
def login
|
||||
def new
|
||||
end
|
||||
|
||||
def id
|
||||
|
@ -10,11 +10,10 @@ class Registrant::SessionsController < Devise::SessionsController
|
|||
|
||||
@user = RegistrantUser.find_or_create_by_idc_data(id_code, id_issuer)
|
||||
if @user
|
||||
sign_in(@user, event: :authentication)
|
||||
redirect_to registrant_root_url
|
||||
sign_in_and_redirect(:registrant_user, @user, event: :authentication)
|
||||
else
|
||||
flash[:alert] = t('login_failed_check_id_card')
|
||||
redirect_to registrant_login_url
|
||||
redirect_to new_registrant_user_session_url
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -68,7 +67,7 @@ class Registrant::SessionsController < Devise::SessionsController
|
|||
when 'USER_AUTHENTICATED'
|
||||
@user = RegistrantUser.find_by(registrant_ident: "#{session[:user_country]}-#{session[:user_id_code]}")
|
||||
|
||||
sign_in @user
|
||||
sign_in(:registrant_user, @user)
|
||||
flash[:notice] = t(:welcome)
|
||||
flash.keep(:notice)
|
||||
render js: "window.location = '#{registrant_root_path}'"
|
||||
|
@ -97,4 +96,14 @@ class Registrant::SessionsController < Devise::SessionsController
|
|||
return User.new unless idc
|
||||
ApiUser.find_by(identity_code: idc) || User.new
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def after_sign_in_path_for(resource_or_scope)
|
||||
registrant_root_path
|
||||
end
|
||||
|
||||
def after_sign_out_path_for(resource_or_scope)
|
||||
new_registrant_user_session_path
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue