Sha256: 74feac73ac06802ff9f5acd35c8c5365923dc53d9354ca30aa4178dd96d47e81

Contents?: true

Size: 599 Bytes

Versions: 2

Compression:

Stored size: 599 Bytes

Contents

# -*- encoding : utf-8 -*-
module RademadeAdmin
  class Login
    def self.admin(params)
      params.require( :data ).permit([:email, :password])
      user = RademadeAdmin.user_class.where(:email => params[:data][:email]).first

      error('There is no users with such email', :email) unless user.is_a? RademadeAdmin.user_class
      error('Incorrect password', :password) unless user.valid_password? params[:data][:password]
      error('Access denied', :email) unless user.admin?

      user
    end

    def self.error(message, field)
      raise Error.new( message, field )
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
rademade_admin-0.0.3 app/services/login.rb
rademade_admin-0.0.2 app/services/login.rb