This commit is contained in:
Christoph Haas 2025-05-02 00:38:59 +02:00
parent fa8a7fc77a
commit 3f4266d19b

View file

@ -4,28 +4,28 @@ class User < ApplicationRecord
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable,
# :registerable,
# :recoverable,
# :rememberable,
:trackable,
# :validatable,
:timeoutable,
# :lockable,
:omniauthable, omniauth_providers: [
:salsa,
# :launchpad,
# :stackexchange,
# :google_oauth2,
# :amazon,
# :github
]
# :registerable,
# :recoverable,
# :rememberable,
:trackable,
# :validatable,
:timeoutable,
# :lockable,
:omniauthable, omniauth_providers: [
:salsa
# :launchpad,
# :stackexchange,
# :google_oauth2,
# :amazon,
# :github
]
include Gravtastic
gravtastic size: 120
# Return a human-friendly string describing the user's SSO provider
def pretty_provider
case self.provider
case provider
# when 'launchpad'
# 'Ubuntu One/Launchpad'
# when 'stackexchange'
@ -44,21 +44,21 @@ class User < ApplicationRecord
end
def pretty_name
if self.pseudo
if pseudo
'Anonymous'
elsif self.name?
self.name
elsif name?
name
else
'Dr. Who'
end
end
def pretty_role
if self.pseudo
if pseudo
'Contributor'
elsif self.moderator_role
elsif moderator_role
'Moderator'
elsif self.admin_role
elsif admin_role
'Admin'
end
end
@ -70,12 +70,10 @@ class User < ApplicationRecord
user.email = auth.info.email
user.name = auth.info.name
# Set a random password
user.password = Devise.friendly_token[0,20]
user.password = Devise.friendly_token[0, 20]
# Users coming through salsa.debian.net/OpenID-Connect will get moderator role
if user.email.end_with?('@debian.org') && user.provider=='salsa'
user.moderator_role = true
end
user.moderator_role = true if user.email.end_with?('@debian.org') && user.provider == 'salsa'
end
end
@ -85,19 +83,18 @@ class User < ApplicationRecord
# TODO: The user can later decide to use a real account and get their screenshots transferred to that.
def self.create_pseudo_user
generated_password = Devise.friendly_token.first(8)
new_user = User.create(
User.create(
name: 'Anonymous',
password: generated_password,
pseudo: true
)
return new_user
end
def to_s
if self.pseudo
"Pseudo user #{self.id}"
if pseudo
"Pseudo user #{id}"
else
"#{self.email} (#{self.provider})"
"#{email} (#{provider})"
end
end
end