aboutsummaryrefslogtreecommitdiff
path: root/interfaces/ruby/models/user.rb
diff options
context:
space:
mode:
authorJohn Ankarström <john@ankarstrom.se>2021-03-13 22:05:55 +0100
committerJohn Ankarström <john@ankarstrom.se>2021-03-13 22:05:55 +0100
commit69c0dff574cbe13bd3b9c23bde10a685dce16b2a (patch)
tree92a264e8e1b53afe4832572b79093da599722dea /interfaces/ruby/models/user.rb
parentedd1b21f926f0bcec0033b4b481fe12f54029224 (diff)
downloadcomb-69c0dff574cbe13bd3b9c23bde10a685dce16b2a.tar.gz
Add sessionsHEADmaster
Diffstat (limited to 'interfaces/ruby/models/user.rb')
-rw-r--r--interfaces/ruby/models/user.rb11
1 files changed, 11 insertions, 0 deletions
diff --git a/interfaces/ruby/models/user.rb b/interfaces/ruby/models/user.rb
index 8b88b4a..a251dec 100644
--- a/interfaces/ruby/models/user.rb
+++ b/interfaces/ruby/models/user.rb
@@ -1,8 +1,19 @@
+require 'bcrypt'
+
class User < ActiveRecord::Base
has_many :posts
+ has_many :sessions
validates_presence_of :username
validates_presence_of :password_hash
+
+ def hash(password)
+ BCrypt::Password.create(password)
+ end
+
+ def authenticate(password)
+ BCrypt::Password.new(@password) == password
+ end
end
class CreateUserTable < ActiveRecord::Migration[6.0]