diff --git a/app/models/user.rb b/app/models/user.rb index a20c75e..0148259 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -36,6 +36,9 @@ class User < ApplicationRecord validates :name, presence: true + before_validation :set_random_password, on: :create + + roles.values.each do |role| define_method "#{role}?" do roles.include?(role) @@ -47,4 +50,10 @@ class User < ApplicationRecord user.update(avatar_url: avatar_url) unless user.nil? end end + + private + + def set_random_password + self.password = SecureRandom.alphanumeric + end end