From 69c0dff574cbe13bd3b9c23bde10a685dce16b2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Ankarstro=CC=88m?= Date: Sat, 13 Mar 2021 22:05:55 +0100 Subject: Add sessions --- interfaces/ruby/models/user.rb | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'interfaces/ruby/models') 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] -- cgit v1.2.3