Class: Entrance::Fields

Inherits:
Object
  • Object
show all
Defined in:
lib/entrance/fields.rb

Instance Method Summary collapse

Constructor Details

#initializeFields

Returns a new instance of Fields.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/entrance/fields.rb', line 11

def initialize
  @unique_key            = 'id'
  @salt                  = nil
  @username              = 'email'
  @password              = 'password_hash'

  # remember and reset
  @remember_token        = 'remember_token' # set to nil to disable 'remember me' option
  @remember_until        = 'remember_token_expires_at'
  @reset_token           = 'reset_token'    # set to nil to disable 'reset password' option
  @reset_until           = 'reset_token_expires_at'

  # omniauth
  @name                  = 'name'
  @auth_provider         = 'auth_provider'
  @auth_uid              = 'auth_uid'
end

Instance Method Details

#validate(*attrs) ⇒ Object



29
30
31
32
33
34
35
36
# File 'lib/entrance/fields.rb', line 29

def validate(*attrs)
  attrs.each do |attr|
    field = send(attr)
    unless fields.include?(field.to_sym)
      raise "Couldn't find '#{field}' in the #{Entrance.model.name} model."
    end
  end
end

#validate_option(what) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/entrance/fields.rb', line 38

def validate_option(what)
  if field = send("#{what}_token")
    until_field = send("#{what}_until")

    unless fields.include?(field.to_sym)
      raise "No #{field} field found. \
             Set the fields.#{what}_token option to nil to disable the #{what} option."
    end

    if until_field
      unless fields.include?(until_field.to_sym)
        raise "Couldn't find a #{until_field} field. Cannot continue."
      end
    else
      puts "Disabling expiration timestamp for the #{what} option. This is a VERY bad idea."
    end

    Entrance.config.can?(what, true)
  end
end