Class: Keyper::Authentication

Inherits:
Object
  • Object
show all
Includes:
ActiveModel::Model
Defined in:
app/models/keyper/authentication.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#passwordObject

Returns the value of attribute password.



5
6
7
# File 'app/models/keyper/authentication.rb', line 5

def password
  @password
end

#userObject

Returns the value of attribute user.



5
6
7
# File 'app/models/keyper/authentication.rb', line 5

def user
  @user
end

#usernameObject

Returns the value of attribute username.



5
6
7
# File 'app/models/keyper/authentication.rb', line 5

def username
  @username
end

Instance Method Details

#user_authenticated?(user, password) ⇒ Boolean

Returns:

  • (Boolean)


20
21
22
23
24
25
26
27
28
# File 'app/models/keyper/authentication.rb', line 20

def user_authenticated?(user, password)
  method_candidates = [
    :valid_password?, :authenticate
  ]
  method_candidates.each do |method|
    return true if user.respond_to?(method) && user.send(method, password)
  end
  return false
end

#username_and_password_are_correctObject



9
10
11
12
13
14
15
16
17
18
# File 'app/models/keyper/authentication.rb', line 9

def username_and_password_are_correct
  user_class = Object.const_get(Keyper.user_class_name)
  @user = user_class.find_by(
    Keyper.user_finder_field => @username
  )
  unless @user && user_authenticated?(@user, password)
    errors.add(:base, I18n.t(:login_failed, scope: [:keyper, :errors]))
    false
  end
end