Skip to content

Instantly share code, notes, and snippets.

@smathy
Created April 12, 2016 16:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save smathy/e29e0b531a7a7b9a0e3b5cbff9f57139 to your computer and use it in GitHub Desktop.
Save smathy/e29e0b531a7a7b9a0e3b5cbff9f57139 to your computer and use it in GitHub Desktop.
User # autoload
class User
class Twin
class Authentication < ::Disposable::Twin
include Sync
include Save
property :state
property :password_digest
include States
def has_password?
password_digest.present?
end
def authenticated? plain_password
active? && password_digest && password == plain_password
end
def password= plain_password
self.password_digest = BCrypt::Password.create plain_password
sync
end
def password
BCrypt::Password.new password_digest
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment