-
-
Save vesan/5f2ceeaeb82929950cee68cd4c96d770 to your computer and use it in GitHub Desktop.
Implementing Devise groups in Rodauth
This file contains hidden or 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
class ApplicationController < ActionController:Base | |
extend ControllerMacros | |
end |
This file contains hidden or 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
module ControllerMacros | |
def rodauth_group(group_name, configuration_names) | |
define_method(:"authenticate_#{group_name}!") do | |
unless send(:"#{group_name}_authenticated?") | |
configuration_names.each do |name| | |
rodauth(name).require_authenication | |
end | |
end | |
end | |
define_method(:"#{group_name}_authenticated?") do | |
configuration_names.any? do |name| | |
rodauth(name).authenticated? | |
end | |
end | |
define_method(:"current_#{group_name}") do | |
send(:"current_#{group_name.to_s.pluralize}").first | |
end | |
define_method(:"current_#{group_name.to_s.pluralize}") do | |
configuration_names.map { |name| rodauth(name).rails_account }.compact | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment