...
1require 'securerandom'
2
3puts "Seeding database"
4puts "-------------------------------"
5
6# Create an initial Admin User
7admin_username = ENV['ERRBIT_ADMIN_USER'] || "errbit"
8
9def admin_email
10 return 'admin@example.com' if heroku_pr_review_app?
11
12 ENV['ERRBIT_ADMIN_EMAIL'] || "errbit@#{Errbit::Config.host}"
13end
14
15def admin_pass
16 return 'demo-admin' if heroku_pr_review_app?
17
18 @admin_pass ||= ENV['ERRBIT_ADMIN_PASSWORD'] || SecureRandom.urlsafe_base64(12)[0, 12]
19end
20
21def heroku_pr_review_app?
22 app_name = ENV.fetch("HEROKU_APP_NAME", "")
23 app_name.include?("errbit-deploy-pr-")
24end
25
26puts "Creating an initial admin user:"
27puts "-- username: #{admin_username}" if Errbit::Config.user_has_username
28puts "-- email: #{admin_email}"
29puts "-- password: #{admin_pass}"
30puts ""
31puts "Be sure to note down these credentials now!"
32puts "\nNOTE: DEMO instance, not for production use!" if heroku_pr_review_app?
33
34user = User.find_or_initialize_by(email: admin_email)
35
36user.name = 'Errbit Admin'
37user.password = admin_pass
38user.password_confirmation = admin_pass
39user.username = admin_username if Errbit::Config.user_has_username
40user.admin = true
41user.save!
42
43
44test_app_name = ENV['ERRBIT_TEST_APP_NAME'] || "Test"
45test_app_key = ENV['ERRBIT_TEST_APP_KEY'] || "test"
46
47puts ""
48puts "Creating an initial test app:"
49puts "-- name: #{test_app_name}"
50puts "-- key: #{test_app_key}"
51puts ""
52
53app = App.find_or_initialize_by(api_key: test_app_key)
54
55app.name = test_app_name
56app.api_key = test_app_key
57app.save!
View as plain text