diff --git a/goss-resetpw.rb b/goss-resetpw.rb index 83a02c8..3a28330 100644 --- a/goss-resetpw.rb +++ b/goss-resetpw.rb @@ -1,7 +1,7 @@ # Federated Computer, Inc. # David Sainty 2024 A.D. # Gossamer Threads to Discourse -- Reset Discourse Password and Clear Gossamer Password -# v0.1 Initial +# v0.2 Full support require File.expand_path("../../../../config/environment", __FILE__) @@ -23,6 +23,26 @@ class GossamerResetPassword user.save! puts " STEP 2 COMPLETED: Discourse Password updated for username: #{discourse_username}" + # Update other attributes (other than password which is already correct) + user.active = true + user.approved = true + user.approved_at = Time.now + user.approved_by_id = 1 + user.save! + puts " STEP 3 COMPLETED: Other attributes (active, approved, approved_at, approved_by_id) updated for username: #{discourse_username}" + + # Generate a new token, hash it, and create a confirmed email token for the user + token = SecureRandom.hex(20) + token_hash = EmailToken.hash_token(token) + + EmailToken.create!( + user_id: user.id, + email: user.email, + token_hash: token_hash, + confirmed: true + ) + puts " STEP 4 COMPLETED: New token generated, hashed and set as confirmed email token for username: #{discourse_username}" + else puts "User not found: #{discourse_username}" end