Sha256: 5a798e5e5e289bd595ce5748ebd472d9c081353557ddbc2ed7b4cf8f6bfcfb84

Contents?: true

Size: 600 Bytes

Versions: 7

Compression:

Stored size: 600 Bytes

Contents

module Nyauth
  class SessionService
    include ActiveModel::Model
    attr_reader :email, :password, :client

    def initialize(session_service_params = {})
      @email = session_service_params[:email]
      @password = session_service_params[:password]
    end

    def save(options = {})
      options.reverse_merge!(as: :user)
      klass = options[:as].to_s.classify.constantize
      @client = klass.authenticate(email, password)
      errors.add(:base, :invalid_email_or_password) unless @client
      client
    rescue
      errors.add(:base, :invalid_email_or_password)
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
nyauth-0.3.0 app/services/nyauth/session_service.rb
nyauth-0.2.8 app/services/nyauth/session_service.rb
nyauth-0.2.7 app/services/nyauth/session_service.rb
nyauth-0.2.6 app/services/nyauth/session_service.rb
nyauth-0.2.5 app/services/nyauth/session_service.rb
nyauth-0.2.4 app/services/nyauth/session_service.rb
nyauth-0.2.3 app/services/nyauth/session_service.rb