A corporation manager and dashboard for EVE Online
Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.
 
 
 
 
 

97 righe
2.9 KiB

  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 db:setup` 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 db:setup 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.char_names
  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. user.name = chars.first
  46. puts "\nUsing character: #{user.name}"
  47. else
  48. puts "\nChoose a character:"
  49. chars.each_with_index do |name, i|
  50. puts " [#{i}]: #{name}"
  51. end
  52. puts "Enter the number next to your chosen character: "
  53. loop do
  54. index = STDIN.gets.to_i
  55. break if index >= 0 && index < chars.length
  56. puts "Bad input; try again: "
  57. end
  58. user.name = chars[index]
  59. end
  60. unless user.member_of? corp_id
  61. puts 'You are not a member of the given corporation. Stopping.'
  62. next
  63. end
  64. print "\nEnter your email address (used for password resets; may be blank): "
  65. user.email = STDIN.gets.chomp
  66. user.email = nil if user.email.empty?
  67. print "\nEnter your new password (to log in to the website, **NOT** for EVE!): "
  68. user.password = STDIN.noecho(&:gets).chomp
  69. puts
  70. print "\nConfirm the password: "
  71. if user.password != STDIN.noecho(&:gets).chomp
  72. puts "\nPasswords do not match. Stopping."
  73. next
  74. end
  75. puts
  76. AdminSetting.set(:corp_name, corp_name)
  77. AdminSetting.set(:site_name, corp_name)
  78. AdminSetting.set(:corp_id, corp_id)
  79. user.save
  80. puts "\nDone!"
  81. end
  82. end