From 9a9c510d575cdf7595e77d1ea396fbd4f4d05505 Mon Sep 17 00:00:00 2001 From: saint Date: Wed, 9 Oct 2024 03:11:04 +1100 Subject: [PATCH] goss-resetpw.rb v0.1 -- for Lance, etc to reset passwords --- goss-resetpw.rb | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 goss-resetpw.rb diff --git a/goss-resetpw.rb b/goss-resetpw.rb new file mode 100644 index 0000000..c07dc8c --- /dev/null +++ b/goss-resetpw.rb @@ -0,0 +1,43 @@ +# Federated Computer, Inc. +# David Sainty 2024 A.D. +# Gossamer Threads to Discourse -- Reset Discourse Password and Clear Gossamer Password +# v0.1 Initial + +require File.expand_path("../../../../config/environment", __FILE__) + +class GossamerResetPassword + def reset_password(discourse_username, new_password) + puts "Resetting password for Discourse username: '#{discourse_username}'" + + user = User.find_by(username: discourse_username) + if user + puts "New password: #{new_password} ..." + + # Delete Gossamer MD5 Password + user.custom_fields.delete('md5_password') # This removes the field completely + user.save! + puts " STEP 1 COMPLETED: Gossamer MD5 Password custom field removed for username: #{username}" + + # Set the Discourse password with the `password=` method to properly hash the password + user.password = new_password + user.save! + puts " STEP 2 COMPLETED: Discourse Password updated for user: #{username}" + + else + puts "User not found: #{username}" + end + end +end + +# Main execution +if ARGV.length != 2 + puts "Usage: #{$0} discourse_username n3w_p4ssword." + exit 1 +end + +discourse_username = ARGV[0] +discourse_username = ARGV[1] +# search_topic_by_title(search_string) + +GossamerResetPassword.new.reset_password(discourse_username, new_password) +