Class: ROM::Auth::Plugins::AuthenticationCredentialsPlugin
- Inherits:
-
Plugin
- Object
- Plugin
- ROM::Auth::Plugins::AuthenticationCredentialsPlugin
show all
- Defined in:
- lib/rom/auth/plugins/authentication_credentials_plugin.rb
Defined Under Namespace
Modules: CallbackOverrides
Classes: AuthenticationCredential, AuthenticationCredentialsMigration, Configuration
Instance Attribute Summary
Attributes inherited from Plugin
#configuration, #system
Instance Method Summary
collapse
Methods inherited from Plugin
#initialize
Instance Method Details
#authenticate(credentials) ⇒ Object
48
49
50
51
52
|
# File 'lib/rom/auth/plugins/authentication_credentials_plugin.rb', line 48
def authenticate(credentials)
cred = find_credential_entry(credentials)
cred.verifier.verifies?(credentials.password)
end
|
#find_credential_entry(credentials) ⇒ Object
39
40
41
|
# File 'lib/rom/auth/plugins/authentication_credentials_plugin.rb', line 39
def find_credential_entry(credentials)
ROM.env.relation(configuration.table_name).find_record(credentials).as(:rom_auth_credential).first
end
|
#identify_user(credentials) ⇒ Object
43
44
45
46
|
# File 'lib/rom/auth/plugins/authentication_credentials_plugin.rb', line 43
def identify_user(credentials)
cred = find_credential_entry(credentials)
ROM.env.relation(system.configuration.users_table_name).by_id(cred.user_id).first if cred
end
|
#install ⇒ Object
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
# File 'lib/rom/auth/plugins/authentication_credentials_plugin.rb', line 11
def install
system.extend(CallbackOverrides)
config = configuration
@mapper_cls = Class.new(ROM::Mapper) do
relation(config.table_name)
model(AuthenticationCredential)
register_as :rom_auth_credential
end
@relation_cls = Class.new(ROM::Relation[:sql]) do
dataset(config.table_name)
def find_record(credentials)
raise if !credentials.respond_to?(:type) || !credentials.respond_to?(:identifier)
where(
type: credentials.type,
identifier: credentials.identifier
)
end
end
end
|