A corporation manager and dashboard for EVE Online
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

calefaction.rake 3.0 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. require 'io/console'
  2. namespace :calefaction do
  3. desc "Set some initial database values and creates an admin user"
  4. task setup: :environment do
  5. begin
  6. AdminSetting.get(:test)
  7. rescue ActiveRecord::StatementInvalid
  8. puts "The database has not been set up properly. You need to run\n"\
  9. "`rake db:setup` first."
  10. next
  11. end
  12. if AdminSetting.get(:corp_id).nil?
  13. puts "The database does not contain the correct seed values. You need "\
  14. "to run\n`rake db:reset tmp:cache:clear` first."
  15. next
  16. end
  17. if AdminSetting.get(:corp_id).to_i > 0
  18. puts "The database is not empty; you should change settings from "\
  19. "within the\napplication. Alternatively, you can start over with\n"\
  20. "`rake db:reset tmp:cache:clear calefaction:setup`."
  21. next
  22. end
  23. print "Enter your corporation's name: "
  24. corp_name = STDIN.gets.chomp
  25. print "\nEnter your corporation's ID (this is visible in the URL for "\
  26. "your corp's page on \nzKillboard, among other places): "
  27. corp_id = STDIN.gets.to_i
  28. if corp_id <= 0
  29. puts 'Corporation ID must be a positive integer. Stopping.'
  30. next
  31. end
  32. print "\nEnter your character's API key ID (create one at\n"\
  33. "https://community.eveonline.com/support/api-key/createpredefined?accessMask=8): "
  34. api_key = STDIN.gets.chomp
  35. print "\nEnter the verification code for the key you just entered: "
  36. api_verify = STDIN.gets.chomp
  37. user = User.new(api_key: api_key, api_verify: api_verify, admin?: true)
  38. chars = user.characters
  39. if chars.empty?
  40. puts "The given API key is invalid, has no characters, or something "\
  41. "else is wrong\nwith the EVE API right now..."
  42. next
  43. end
  44. if chars.length == 1
  45. puts "\nUsing character: #{chars.first.name}"
  46. user.char_id = chars.first.characterID
  47. else
  48. puts "\nChoose a character:"
  49. chars.each_with_index do |char, i|
  50. puts " [#{i}]: #{char.name}"
  51. end
  52. print "Enter the number next to your chosen character: "
  53. loop do
  54. index = STDIN.gets.to_i
  55. if index >= 0 && index < chars.length
  56. user.char_id = chars[index].characterID and break
  57. end
  58. print "Bad input; try again: "
  59. end
  60. end
  61. unless user.member_of? corp_id
  62. puts 'You are not a member of the given corporation. Stopping.'
  63. next
  64. end
  65. print "\nEnter your email address (required; used to log in): "
  66. user.email = STDIN.gets.chomp
  67. if user.email.blank?
  68. puts "\nInvalid email address. Stopping."
  69. next
  70. end
  71. print "\nEnter your new password (to log in to the website, **NOT** for EVE!): "
  72. user.password = STDIN.noecho(&:gets).chomp
  73. puts
  74. print "\nConfirm the password: "
  75. if user.password != STDIN.noecho(&:gets).chomp
  76. puts "\nPasswords do not match. Stopping."
  77. next
  78. end
  79. puts
  80. AdminSetting.set(:corp_name, corp_name)
  81. AdminSetting.set(:site_name, corp_name)
  82. AdminSetting.set(:corp_id, corp_id)
  83. user.save
  84. puts "\nDone!"
  85. end
  86. end