Class: CargoWiki::User

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

Constant Summary collapse

ROLES =
%w(editor admin)

Instance Method Summary collapse

Instance Method Details

#admin?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'app/models/cargo_wiki/user.rb', line 22

def admin?
  self.role == "admin"
end

#generate_token(column) ⇒ Object



16
17
18
19
20
# File 'app/models/cargo_wiki/user.rb', line 16

def generate_token(column)
  begin
    self[column] = SecureRandom.urlsafe_base64
  end while User.exists?(column => self[column])
end

#valid_password?(password) ⇒ Boolean

Returns:

  • (Boolean)


26
27
28
# File 'app/models/cargo_wiki/user.rb', line 26

def valid_password?(password)
  self.authenticate(password) == self
end