Sha256: 377e38cca45a976b6163841fb0c1b486518711c1ebd8dbc74f285bab3e9c6f57

Contents?: true

Size: 601 Bytes

Versions: 3

Compression:

Stored size: 601 Bytes

Contents

# frozen_string_literal: true

class Tramway::SessionForm < Tramway::ApplicationForm
  properties :email
  attr_accessor :password

  def initialize(object)
    object = Tramway::User.new unless object.present?

    super
  end

  def validate(params)
    (add_wrong_email_or_password_error && return) if model.new_record?

    (!model.new_record? && model.authenticate(params[:password])).tap do |result|
      add_wrong_email_or_password_error unless result
    end
  end

  private

  def add_wrong_email_or_password_error
    errors.add(:email, I18n.t('errors.wrong_email_or_password'))
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
tramway-0.1.2 app/forms/tramway/session_form.rb
tramway-0.1.1.1 app/forms/tramway/session_form.rb
tramway-0.1.1 app/forms/tramway/session_form.rb