about summary refs log tree commit diff
path: root/lib/mastodon
diff options
context:
space:
mode:
authorThibG <thib@sitedethib.com>2020-02-22 01:29:14 +0100
committerGitHub <noreply@github.com>2020-02-22 01:29:14 +0100
commitca7ee9f1cfc6dad138b1589a95d9c7febe213a3c (patch)
treebe9b0b0d5fbf693851f657973b89dc01e4ce331c /lib/mastodon
parent0f07218e53bf581127cdcf5fbf12d9c207ace8d7 (diff)
Add `--reset-password` option to `tootctl accounts modify` (#13126)
Diffstat (limited to 'lib/mastodon')
-rw-r--r--lib/mastodon/accounts_cli.rb7
1 files changed, 7 insertions, 0 deletions
diff --git a/lib/mastodon/accounts_cli.rb b/lib/mastodon/accounts_cli.rb
index 6dbb75689..8c91c3013 100644
--- a/lib/mastodon/accounts_cli.rb
+++ b/lib/mastodon/accounts_cli.rb
@@ -120,6 +120,7 @@ module Mastodon
     option :disable, type: :boolean
     option :disable_2fa, type: :boolean
     option :approve, type: :boolean
+    option :reset_password, type: :boolean
     desc 'modify USERNAME', 'Modify a user'
     long_desc <<-LONG_DESC
       Modify a user account.
@@ -138,6 +139,9 @@ module Mastodon
 
       With the --disable-2fa option, the two-factor authentication
       requirement for the user can be removed.
+
+      With the --reset-password option, the user's password is replaced by
+      a randomly-generated one, printed in the output.
     LONG_DESC
     def modify(username)
       user = Account.find_local(username)&.user
@@ -152,6 +156,8 @@ module Mastodon
         user.moderator = options[:role] == 'moderator'
       end
 
+      password = SecureRandom.hex if options[:reset_password]
+      user.password = password if options[:reset_password]
       user.email = options[:email] if options[:email]
       user.disabled = false if options[:enable]
       user.disabled = true if options[:disable]
@@ -161,6 +167,7 @@ module Mastodon
 
       if user.save
         say('OK', :green)
+        say("New password: #{password}") if options[:reset_password]
       else
         user.errors.to_h.each do |key, error|
           say('Failure/Error: ', :red)