Skip to content

Instantly share code, notes, and snippets.

@Exact1990
Created February 8, 2016 06:43
Show Gist options
  • Save Exact1990/b1299acfd230198d853a to your computer and use it in GitHub Desktop.
Save Exact1990/b1299acfd230198d853a to your computer and use it in GitHub Desktop.
class UserSignInType
include ApplicationTypeWithoutActiveRecord
attribute :login, String
attribute :password, String
validates :login, :password, presence: true
validate :check_authenticate
def user
User.actual.find_by(login: login)
end
private
def check_authenticate
if login.present? && password.present?
errors.add(:base, :login_or_password_invalid) if !user.try(:authenticate, password)
end
end
end
module ApplicationTypeWithoutActiveRecord
extend ActiveSupport::Concern
included do
include ActiveModel::Validations
include ActiveModel::Conversion
include ActiveModel::Translation
include Virtus.model
end
def persisted?
false
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment