about summary refs log tree commit diff
path: root/lib
diff options
context:
space:
mode:
authorbeatrix-bitrot <beatrix.bitrot@gmail.com>2017-06-27 20:46:13 +0000
committerbeatrix-bitrot <beatrix.bitrot@gmail.com>2017-06-27 20:46:13 +0000
commitddafde942ca53816c19b0ea0cb40bb1b46cf5668 (patch)
treec0ac2138fe994c4c2a15c23b47d4155f75148945 /lib
parente6300de1421d28d173658e61601b9e016c3d0a6d (diff)
parentda42bfadb58888e3a18afd66395f0f3edc2fa622 (diff)
Merge remote-tracking branch 'upstream/master'
Diffstat (limited to 'lib')
-rw-r--r--lib/tasks/mastodon.rake31
1 files changed, 31 insertions, 0 deletions
diff --git a/lib/tasks/mastodon.rake b/lib/tasks/mastodon.rake
index 6c7326b74..0e182c755 100644
--- a/lib/tasks/mastodon.rake
+++ b/lib/tasks/mastodon.rake
@@ -42,6 +42,37 @@ namespace :mastodon do
     end
   end
 
+  desc 'Add a user by providing their email, username and initial password.' \
+       'The user will receive a confirmation email, then they must reset their password before logging in.'
+  task add_user: :environment do
+    print 'Enter email: '
+    email = STDIN.gets.chomp
+
+    print 'Enter username: '
+    username = STDIN.gets.chomp
+
+    print 'Create user and send them confirmation mail [y/N]: '
+    confirm = STDIN.gets.chomp
+    puts
+
+    if confirm.casecmp?('y')
+      password = SecureRandom.hex
+      user = User.new(email: email, password: password, account_attributes: { username: username })
+      if user.save
+        puts 'User added and confirmation mail sent to user\'s email address.'
+        puts "Here is the random password generated for the user: #{password}"
+      else
+        puts 'Following errors occured while creating new user:'
+        user.errors.each do |key, val|
+          puts "#{key}: #{val}"
+        end
+      end
+    else
+      puts 'Aborted by user.'
+    end
+    puts
+  end
+
   namespace :media do
     desc 'Removes media attachments that have not been assigned to any status for longer than a day'
     task clear: :environment do