goss-resetpw.rb v0.2 -- full support

This commit is contained in:
David Sainty 2024-10-10 17:26:59 +11:00
parent 98814a1957
commit b690b68f85

View File

@ -1,7 +1,7 @@
# Federated Computer, Inc. # Federated Computer, Inc.
# David Sainty <saint@federated.computer> 2024 A.D. # David Sainty <saint@federated.computer> 2024 A.D.
# Gossamer Threads to Discourse -- Reset Discourse Password and Clear Gossamer Password # 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__) require File.expand_path("../../../../config/environment", __FILE__)
@ -23,6 +23,26 @@ class GossamerResetPassword
user.save! user.save!
puts " STEP 2 COMPLETED: Discourse Password updated for username: #{discourse_username}" 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 else
puts "User not found: #{discourse_username}" puts "User not found: #{discourse_username}"
end end