Skip to content

Instantly share code, notes, and snippets.

@fudanchii
Created May 14, 2010 09:32
Show Gist options
  • Save fudanchii/400984 to your computer and use it in GitHub Desktop.
Save fudanchii/400984 to your computer and use it in GitHub Desktop.
require 'bcrypt'
module Gencore
class User < Sequel::Model
set_schema do
primary_key :id
varchar :username
text :passwd, :default => '*'
end
one_to_one :biodata, :class => 'Gencore::Biodata'
one_to_many :ftp_logs, :class => 'Gencore::Ftp_log'
include BCrypt
def password
@password ||= Password.new(passwd)
end
def password=(new_password)
@password = Password.create(new_password)
self.passwd = @password
end
create_table unless table_exists?
##### test case, TODO move this to spec file
if empty?
user = create(:username => 'fudanchii',
:password => 'testest')
puts user.password
puts user.password == 'testest'
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment