Skip to content
Snippets Groups Projects
Select Git revision
  • f912b36ad0ca8e6c5a945f9a43eb4b1323b7e8f3
  • develop default protected
  • ical-export
  • feature/audit_log
  • fix/index
  • badge-redeem-404
  • 720-schedule_source
  • room-docu
  • chore/event-views
  • 511-schedule-foo-fixed
  • 607-schedule-versions
  • deploy/curl-verbose
  • fix/public-badge-access-rights
  • 445-schedule-redirects
  • 623-wiki-im-baustellenmodus-sollte-mal-als-wiki-admin-trotzdem-seiten-anlegen-bearbeiten-konnen
  • fix/registration_mail_subject
  • feature/conference-query-set
  • feature/568-habitatmanagement
  • feat/unit-integration-tests
  • camp23-prod
  • production
  • prod-2024-12-27_20-15
  • prod-2024-12-27_16-37
  • prod-2024-12-27_16-01
  • prod-2024-12-27_13-29
  • prod-2024-12-27_00-34
  • prod-2024-12-26_21-45
  • prod-2024-12-26_13-12
  • prod-2024-12-26_00-21
  • prod-2024-12-25_21-04
  • prod-2024-12-25_15-54
  • prod-2024-12-25_01-29
  • prod-2024-12-24_14-48
  • prod-2024-12-23_23-39
  • prod-2024-12-22_21-12
  • prod-2024-12-22_17-25
  • prod-2024-12-22_01-34
  • prod-2024-12-22_00-55
  • prod-2024-12-21_13-42
  • prod-2024-12-21_10-44
  • prod-2024-12-20_12-25
41 results

Dockerfile

Blame
  • Forked from hub / hub
    Source project has a limited visibility.
    user.rb 1.11 KiB
    class User < ApplicationRecord
      has_many :assignments
    
      has_secure_password
    
      validates :password, presence: true, length: { minimum: 6 }, allow_nil: true
      validates :email, uniqueness: { case_sensitive: false, message: "already in use" }
    
      after_initialize :set_avatar_color
    
      def errors
        super.tap { |errors| errors.delete(:password, :blank) if password.nil? }
      end
    
      def has_password?
        !password.nil?
      end
    
      def text_color
        r, g, b = avatar_color.delete_prefix('#').chars.each_slice(2).map { |hex| hex.join.to_i(16) }
    
        # Calculate relative luminance (WCAG 2.0 formula)
        luminance = (0.2126 * r + 0.7152 * g + 0.0722 * b) / 255
    
        # Choose text color based on luminance threshold
        luminance > 0.5 ? "#000000" : "#ffffff"
      end
    
      def initials
        name.split(/\s+/).map(&:first).join('')
      end
    
      def set_avatar_color
        return unless self.avatar_color.nil?
    
        r = rand(256)
        g = rand(256)
        b = rand(256)
    
        # r = [r, 128].max
        # g = [g, 128].max
        # b = [b, 128].max
    
        self.avatar_color = "##{r.to_s(16).rjust(2, '0')}#{g.to_s(16).rjust(2, '0')}#{b.to_s(16).rjust(2, '0')}"
      end
    end