Skip to content

Instantly share code, notes, and snippets.

@nomasprime
Created March 15, 2017 16:23
Show Gist options
  • Save nomasprime/fcb822c72caeef738e7ac04335c43e06 to your computer and use it in GitHub Desktop.
Save nomasprime/fcb822c72caeef738e7ac04335c43e06 to your computer and use it in GitHub Desktop.
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