added AuthenticationToken model, updated some restrictions for the authentication token table, added dependent destroy to the user model for authentication tokens

This commit is contained in:
Janis4411
2022-08-02 13:57:44 +02:00
committed by Sebastian Serth
parent fe410a5306
commit d64daadd21
4 changed files with 39 additions and 1 deletions

View File

@ -0,0 +1,14 @@
# frozen_string_literal: true
require 'securerandom'
class AuthenticationToken < ApplicationRecord
include Creation
def self.generate!(user)
create!(
shared_secret: SecureRandom.hex(32),
user: user,
expire_at: 7.days.from_now
)
end
end

View File

@ -6,6 +6,7 @@ class User < ApplicationRecord
ROLES = %w[admin teacher learner].freeze
belongs_to :consumer
has_many :authentication_token, dependent: :destroy
has_many :study_group_memberships, as: :user
has_many :study_groups, through: :study_group_memberships, as: :user
has_many :exercises, as: :user