DEV: allow creating users with random passwords via rake

Use: `RANDOM_PASSWORD=1 bin/rake admin:create`

Handy in conjunction with dev mode /session/username/become.
This commit is contained in:
Sam Saffron 2018-12-18 11:42:19 +08:00
parent f67cc2a540
commit abbbcb2622
1 changed files with 6 additions and 2 deletions

View File

@ -56,8 +56,12 @@ task "admin:create" => :environment do
admin.email = email
admin.username = UserNameSuggester.suggest(admin.email)
begin
password = ask("Password: ") { |q| q.echo = false }
password_confirmation = ask("Repeat password: ") { |q| q.echo = false }
if ENV["RANDOM_PASSWORD"] == "1"
password = password_confirmation = SecureRandom.hex
else
password = ask("Password: ") { |q| q.echo = false }
password_confirmation = ask("Repeat password: ") { |q| q.echo = false }
end
end while password != password_confirmation
admin.password = password
end