Sha256: e71bce6fcf2d11898f56517845dabc7147c708d0a2560281ec43cf8b779b4f36

Contents?: true

Size: 606 Bytes

Versions: 7

Compression:

Stored size: 606 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(:client, 'invalid email or password') unless @client
      client
    rescue
      errors.add(:client, 'invalid email or password')
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
nyauth-0.2.2 app/services/nyauth/session_service.rb
nyauth-0.2.1 app/services/nyauth/session_service.rb
nyauth-0.2.0 app/services/nyauth/session_service.rb
nyauth-0.1.0 app/services/nyauth/session_service.rb
nyauth-0.0.3 app/services/nyauth/session_service.rb
nyauth-0.0.2 app/services/nyauth/session_service.rb
nyauth-0.0.1 app/services/nyauth/session_service.rb