Last active
June 28, 2021 11:54
-
-
Save nataliaconde/4693733298cd333d009d9328ce6eee2e to your computer and use it in GitHub Desktop.
authentication logic
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
# login_form.rb | |
class LoginForm < BaseForm | |
attr_accessor :email, :password, :incognia_installation_id | |
validates :email, :password, presence: true | |
validate :device_risk | |
# Other validations... | |
def submit | |
return nil if invalid? | |
user&.authenticate(password) | |
end | |
private | |
def user | |
@user ||= User.find_by(email: email.downcase) | |
end | |
def device_risk | |
return unless user | |
api = Incognia::Api.instance | |
risk_assessment = api.register_login( | |
installation_id: incognia_installation_id, | |
account_id: user.id | |
) | |
# Automatically denies if Incognia gives high risk! | |
if risk_assessment == 'high_risk' | |
errors.add(:incognia_installation_id, 'considered unsafe!') | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment