Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
authentication logic
# 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