Last active
June 19, 2023 08:16
-
-
Save kjellberg/4e5df9404554b156d1ccc981eb34dc7c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Obs inte testat såklart. | |
class BankidAuthController | |
def callback # omniauth? callback | |
personnummer = params[:personnummer] # from bankid callback | |
bankid_user = BankidUser.first_or_create(personnummer: personnummer) | |
if bankid.user.present? | |
sign_in_and_redirect bankid_user.user # Devise method | |
else | |
session[:bankid_user_id] = bankid_user.id | |
redirect_to custom_registration_path | |
end | |
end | |
end | |
class CustomRegistrationController | |
before_action do | |
# Redirecta till vanlig signup om det inte finns bankid_user_id i session | |
redirect_to new_user_session_path unless session[:bankid_user_id].present? | |
end | |
def new | |
@user = User.new | |
end | |
def create | |
user = current_bankid_user.user.create(user_params) | |
sign_in_and_redirect user # Devise method | |
end | |
private | |
def current_bankid_user | |
@current_bankid_user ||= BankidUser.find(session[:bankid_user_id]) | |
end | |
def user_params | |
# ... | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment