Skip to content

Instantly share code, notes, and snippets.

@hxegon
Forked from nomasprime/some_class.rb
Last active March 15, 2017 16:32
Show Gist options
  • Save hxegon/2a613ce0838143d41fbea2ee51125991 to your computer and use it in GitHub Desktop.
Save hxegon/2a613ce0838143d41fbea2ee51125991 to your computer and use it in GitHub Desktop.
class SomeClass
def initialize(current_account, form, request)
@form = form
@request = request
end
def call
if invalid?
form.errors.add(:credentials, :invalid)
return broadcast(:invalid, form)
end
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?
false if user.present?
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