Class: Nyauth::Session

Inherits:
Object
  • Object
show all
Includes:
ActiveModel::Model
Defined in:
app/services/nyauth/session.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(service_params = {}) ⇒ Session

Returns a new instance of Session.



6
7
8
9
# File 'app/services/nyauth/session.rb', line 6

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

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



4
5
6
# File 'app/services/nyauth/session.rb', line 4

def client
  @client
end

#emailObject (readonly)

Returns the value of attribute email.



4
5
6
# File 'app/services/nyauth/session.rb', line 4

def email
  @email
end

#passwordObject (readonly)

Returns the value of attribute password.



4
5
6
# File 'app/services/nyauth/session.rb', line 4

def password
  @password
end

Instance Method Details

#save(options = {}) ⇒ Object



11
12
13
14
15
16
17
18
19
# File 'app/services/nyauth/session.rb', line 11

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