v0.3 -- name change

This commit is contained in:
dsainty 2024-06-11 15:28:46 +10:00
parent 744484870e
commit b4707d53dd

View File

@ -1,17 +1,15 @@
# plugins/md5_authentication/plugin.rb # plugins/discourse-md5_authentication/plugin.rb
# frozen_string_literal: true # frozen_string_literal: true
# name: md5_authentication # name: discourse-md5_authentication
# about: A plugin to authenticate users with MD5 passwords from legacy systems # about: A plugin to authenticate users with MD5 passwords from legacy systems
# version: 0.2 # version: 0.3
# authors: saint # authors: saint
# url: https://gitea.federated.computer/saint/discourse-md5_authentication.git # url: https://gitea.federated.computer/saint/discourse-md5_authentication.git
# plugins/md5_authentication/plugin.rb
after_initialize do after_initialize do
Rails.logger.info("MD5 Authentication Plugin: Initialized") Rails.logger.error("MD5 Authentication Plugin: Initialized")
class ::User class ::User
module LegacyMd5Authentication module LegacyMd5Authentication
def self.included(base) def self.included(base)
@ -20,7 +18,7 @@ after_initialize do
module ClassMethods module ClassMethods
def authenticate(login, password) def authenticate(login, password)
Rails.logger.info("LegacyMd5Authentication: Trying to authenticate user with login #{login}") Rails.logger.error("LegacyMd5Authentication: Trying to authenticate user with login #{login}")
user = nil user = nil
@ -34,18 +32,18 @@ after_initialize do
end end
if user if user
Rails.logger.info("LegacyMd5Authentication: User found: #{user.username}") Rails.logger.error("LegacyMd5Authentication: User found: #{user.username}")
if user.custom_fields['md5_password'] && user.custom_fields['md5_password'] == Digest::MD5.hexdigest(password) if user.custom_fields['md5_password'] && user.custom_fields['md5_password'] == Digest::MD5.hexdigest(password)
Rails.logger.info("LegacyMd5Authentication: MD5 password match for user: #{user.username}") Rails.logger.error("LegacyMd5Authentication: MD5 password match for user: #{user.username}")
user.update!(password: password) user.update!(password: password)
user.custom_fields['md5_password'] = nil user.custom_fields['md5_password'] = nil
user.save_custom_fields user.save_custom_fields
return user return user
else else
Rails.logger.info("LegacyMd5Authentication: MD5 password did not match for user: #{user.username}") Rails.logger.error("LegacyMd5Authentication: MD5 password did not match for user: #{user.username}")
end end
else else
Rails.logger.info("LegacyMd5Authentication: No user found with login #{login}") Rails.logger.error("LegacyMd5Authentication: No user found with login #{login}")
end end
super(login, password) super(login, password)