Browse Source

Feature: add a rake task that's like register but also accepts password

and produces cleaner output
Andrew 11 months ago
parent
commit
4234c0ba7b
1 changed files with 22 additions and 0 deletions
  1. 22
    0
      lib/tasks/mastodon.rake

+ 22
- 0
lib/tasks/mastodon.rake View File

@@ -483,6 +483,28 @@ namespace :mastodon do
483 483
     end
484 484
   end
485 485
 
486
+  desc 'Machine-readably add a user by providing their email, username and initial password.' \
487
+      'The user will receive a confirmation email.'
488
+  task add_user_automatic: :environment do
489
+    print 'Enter email: '
490
+    email = STDIN.gets.chomp
491
+
492
+    print 'Enter username: '
493
+    username = STDIN.gets.chomp
494
+
495
+    print 'Enter password: '
496
+    password = STDIN.gets.chomp
497
+
498
+    user = User.new(email: email, password: password, account_attributes: { username: username })
499
+    if user.save
500
+      puts 'User added and confirmation mail sent to user\'s email address.'
501
+    else
502
+      user.errors.each do |key, val|
503
+        STDERR.puts "#{key}: #{val}"
504
+      end
505
+    end
506
+  end
507
+
486 508
   namespace :media do
487 509
     desc 'Remove media attachments attributed to silenced accounts'
488 510
     task remove_silenced: :environment do