class Miniauth

Constants

VERSION

Attributes

email[R]

Public Class Methods

new(params) click to toggle source
# File lib/miniauth.rb, line 7
def initialize(params)
  @params = params
  @email  = params[:email]
  @errors = []
end

Public Instance Methods

authenticate(user) click to toggle source
# File lib/miniauth.rb, line 20
def authenticate(user)
  user && BCrypt::Password.new(user[:password]) == @params[:password]
end
encrypted_password() click to toggle source
# File lib/miniauth.rb, line 24
def encrypted_password
  @encrypted_password ||= BCrypt::Password.create(@params[:password])
end
generate_token() click to toggle source
# File lib/miniauth.rb, line 28
def generate_token
  SecureRandom.hex(64)
end
valid?(params) click to toggle source
# File lib/miniauth.rb, line 13
def valid?(params)
  @errors << "Email is not valid." unless @params[:email] =~ /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/i
  @errors << "Email is blank." if @params[:email].blank?
  @errors << "Password is blank." if @params[:password].blank?
  @errors.empty?       
end