Rakefile: add task to create initial users

This commit is contained in:
Pierre de La Morinerie 2018-06-11 14:49:42 +00:00
parent f2ebf48564
commit b0c5d8ec66
2 changed files with 23 additions and 9 deletions

View file

@ -81,16 +81,9 @@ Dans le fichier `config/intializers/token.rb`, ajouter
*Note : les valeurs pour ces paramètres sont renseignées dans le Keepass*
## Création des comptes initiaux
bin/rails console
> email = "<votre email>"
> password = "<votre mot de passe>"
> Administration.create(email: email, password: password)
> Administrateur.create(email: email, password: password)
> Gestionnaire.create(email: email, password: password)
> User.create(email: email, password: password)
## Création d'un compte de test initial en local
bin/rake create_test_account -- --email=EMAIL --password=PASSWORD
## Lancement de l'application

View file

@ -5,6 +5,27 @@ require File.expand_path('config/application', __dir__)
Rails.application.load_tasks
desc "Create a test account that includes all roles"
task :create_test_account => :environment do
email, password = nil
optparse = OptionParser.new do |opts|
opts.banner = "Usage: rake create_test_account -- --email=EMAIL --password=PASSWORD"
opts.on("--email ARG", String) { |e| email = e }
opts.on("--password ARG", String) { |p| password = p }
end
args = optparse.order!(ARGV) {}
optparse.parse!(args)
raise optparse.banner if email.nil? || password.nil?
raise "Password must be at least 8 characters." if password.length < 8
Administration.create!(email: email, password: password)
Administrateur.create!(email: email, password: password)
Gestionnaire.create!(email: email, password: password)
User.create!(email: email, password: password, confirmed_at: DateTime.now)
puts "Test account #{email} created"
end
task :deploy do
domains = %w(37.187.249.111 149.202.72.152 149.202.198.6)
domains.each do |domain|