Created
March 15, 2017 16:23
-
-
Save nomasprime/fcb822c72caeef738e7ac04335c43e06 to your computer and use it in GitHub Desktop.
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
class SomeClass | |
def initialize(current_account, form, request) | |
@form = form | |
@request = request | |
end | |
def call | |
return broadcast(:invalid, form) if invalid? | |
auth_header ||= user.create_new_auth_token | |
user.update_tracked_fields!(request) | |
broadcast(:ok, auth_header, user) | |
end | |
private | |
attr_reader :form, :request | |
def invalid? | |
form.invalid? || invalid_credentials? | |
end | |
def invalid_credentials? | |
return false if user.present? | |
form.errors.add(:credentials, :invalid) | |
end | |
def user | |
@user ||= ::User.authenticate(:email => form.email, :password => form.password) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment