Class: User

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/user.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#skip_password_validationObject

Returns the value of attribute skip_password_validation.



11
12
13
# File 'app/models/user.rb', line 11

def skip_password_validation
  @skip_password_validation
end

Instance Method Details

#admin?Boolean

Returns:

  • (Boolean)


35
36
37
# File 'app/models/user.rb', line 35

def admin?
  admin
end

#content_editor?Boolean

Returns:

  • (Boolean)


43
44
45
# File 'app/models/user.rb', line 43

def content_editor?
  content_editor
end

#designer?Boolean

Returns:

  • (Boolean)


39
40
41
# File 'app/models/user.rb', line 39

def designer?
  designer
end

#localeObject



47
48
49
# File 'app/models/user.rb', line 47

def locale
  'en'
end

#nameObject



51
52
53
# File 'app/models/user.rb', line 51

def name
  "#{first_name} #{last_name}"
end

#password_complexityObject



61
62
63
64
65
# File 'app/models/user.rb', line 61

def password_complexity
  return false if password.blank? || password =~ /^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9])(?=.*?[#?!@$%^&*-]).{8,70}$/

  errors.add :password, 'Complexity requirement not met. Length should be 12 characters and include: 1 uppercase, 1 lowercase, 1 digit and 1 special character.'
end

#password_required?Boolean

Returns:

  • (Boolean)


55
56
57
58
59
# File 'app/models/user.rb', line 55

def password_required?
  return false if skip_password_validation

  super
end

#role?(role) ⇒ Boolean

Returns:

  • (Boolean)


22
23
24
25
26
27
28
29
30
31
32
33
# File 'app/models/user.rb', line 22

def role?(role)
  case role
  when :admin
    admin?
  when :designer
    designer?
  when :content_editor
    content_editor?
  else
    false
  end
end