Class: Yauth::User

Inherits:
Object
  • Object
show all
Includes:
BCrypt
Defined in:
lib/yauth/user.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hash = {}) ⇒ User

Returns a new instance of User.



9
10
11
12
13
14
15
# File 'lib/yauth/user.rb', line 9

def initialize(hash={})
  hash = hash[:user] if hash[:user]
  hash = hash["user"] if hash["user"]

  self.username = hash[:username] || hash["username"]
  self.password = hash[:password] || hash["password"]
end

Instance Attribute Details

#passwordObject

Returns the value of attribute password.



6
7
8
# File 'lib/yauth/user.rb', line 6

def password
  @password
end

#plain_passwordObject

Returns the value of attribute plain_password.



7
8
9
# File 'lib/yauth/user.rb', line 7

def plain_password
  @plain_password
end

#usernameObject

Returns the value of attribute username.



6
7
8
# File 'lib/yauth/user.rb', line 6

def username
  @username
end

Instance Method Details

#authenticate(password) ⇒ Object



30
31
32
33
# File 'lib/yauth/user.rb', line 30

def authenticate(password)
  return false if password.to_s == "" 
  self.password == password
end

#to_hashObject



22
23
24
# File 'lib/yauth/user.rb', line 22

def to_hash
  { "user" => { "username" => username, "password" => password } }
end

#to_yaml(opts = {}) ⇒ Object



26
27
28
# File 'lib/yauth/user.rb', line 26

def to_yaml(opts={})
  to_hash.to_yaml(opts)
end