| @@ -9,14 +9,14 @@ class UsersController < ApplicationController | |||||
| def login | def login | ||||
| if request.post? | if request.post? | ||||
| if params[:username].blank? || params[:password].blank? | |||||
| flash.now[:alert] = 'Both a character name and password are required.' | |||||
| if params[:email].blank? || params[:password].blank? | |||||
| flash.now[:alert] = 'Both an email and a password are required.' | |||||
| render 'login' and return | render 'login' and return | ||||
| end | end | ||||
| user = User.find_by(name: params[:username]) | |||||
| user = User.find_by(email: params[:email]) | |||||
| if user.nil? || !user.authenticate(params[:password]) | if user.nil? || !user.authenticate(params[:password]) | ||||
| flash.now[:alert] = 'Incorrect character name or password.' | |||||
| flash.now[:alert] = 'Incorrect email address or password.' | |||||
| render 'login' and return | render 'login' and return | ||||
| end | end | ||||
| @@ -4,12 +4,13 @@ class User < ActiveRecord::Base | |||||
| has_secure_password | has_secure_password | ||||
| alias_attribute :admin?, :is_admin | alias_attribute :admin?, :is_admin | ||||
| def char_names | |||||
| def name | |||||
| ensure_api_user | ensure_api_user | ||||
| @api.scope = 'char' | |||||
| begin | begin | ||||
| @api.Characters.characters.map { |char| char.name } | |||||
| rescue EAAL::EAALError | |||||
| [] | |||||
| @api.CharacterSheet(characterID: userid).name | |||||
| rescue EAAL::Exception::EAALError | |||||
| '?' | |||||
| end | end | ||||
| end | end | ||||
| @@ -25,12 +26,21 @@ class User < ActiveRecord::Base | |||||
| ensure_api_user | ensure_api_user | ||||
| @api.scope = 'char' | @api.scope = 'char' | ||||
| begin | begin | ||||
| @api.CharacterSheet(names: name).corporationID.to_i | |||||
| rescue EAAL::EAALError | |||||
| @api.CharacterSheet(characterID: userid).corporationID.to_i | |||||
| rescue EAAL::Exception::EAALError | |||||
| 0 | 0 | ||||
| end | end | ||||
| end | end | ||||
| def characters | |||||
| ensure_api_user | |||||
| begin | |||||
| @api.Characters.characters | |||||
| rescue EAAL::Exception::EAALError | |||||
| [] | |||||
| end | |||||
| end | |||||
| private | private | ||||
| def ensure_api_user | def ensure_api_user | ||||
| @api ||= EAAL::API.new(api_key, api_verify) | @api ||= EAAL::API.new(api_key, api_verify) | ||||
| @@ -5,8 +5,8 @@ | |||||
| <%= form_tag do %> | <%= form_tag do %> | ||||
| <table> | <table> | ||||
| <tr> | <tr> | ||||
| <td><%= label_tag('username', 'Character name') %></td> | |||||
| <td><%= text_field_tag('username') %></td> | |||||
| <td><%= label_tag('email', 'Email address') %></td> | |||||
| <td><%= email_field_tag('email') %></td> | |||||
| </tr> | </tr> | ||||
| <tr> | <tr> | ||||
| <td><%= label_tag('password', 'Password') %></td> | <td><%= label_tag('password', 'Password') %></td> | ||||
| @@ -0,0 +1,6 @@ | |||||
| class ReplaceNameWithIdInUser < ActiveRecord::Migration | |||||
| def change | |||||
| remove_column :users, :name, :string | |||||
| add_column :users, :userid, :integer, first: true | |||||
| end | |||||
| end | |||||
| @@ -11,7 +11,7 @@ | |||||
| # | # | ||||
| # It's strongly recommended that you check this file into your version control system. | # It's strongly recommended that you check this file into your version control system. | ||||
| ActiveRecord::Schema.define(version: 20150316234044) do | |||||
| ActiveRecord::Schema.define(version: 20150317052416) do | |||||
| create_table "admin_settings", force: :cascade do |t| | create_table "admin_settings", force: :cascade do |t| | ||||
| t.string "key" | t.string "key" | ||||
| @@ -19,7 +19,7 @@ ActiveRecord::Schema.define(version: 20150316234044) do | |||||
| end | end | ||||
| create_table "users", force: :cascade do |t| | create_table "users", force: :cascade do |t| | ||||
| t.string "name" | |||||
| t.integer "userid" | |||||
| t.string "email" | t.string "email" | ||||
| t.string "password_digest" | t.string "password_digest" | ||||
| t.string "api_key" | t.string "api_key" | ||||
| @@ -17,7 +17,7 @@ module Calefaction::EVE | |||||
| @@api.scope = 'corp' | @@api.scope = 'corp' | ||||
| begin | begin | ||||
| @@api.CorporationSheet(corporationID: corp_id).ticker | @@api.CorporationSheet(corporationID: corp_id).ticker | ||||
| rescue EAAL::EAALError | |||||
| rescue EAAL::Exception::EAALError | |||||
| nil | nil | ||||
| end | end | ||||
| end | end | ||||
| @@ -13,14 +13,14 @@ namespace :calefaction do | |||||
| if AdminSetting.get(:corp_id).nil? | if AdminSetting.get(:corp_id).nil? | ||||
| puts "The database does not contain the correct seed values. You need "\ | puts "The database does not contain the correct seed values. You need "\ | ||||
| "to run\n`rake db:reset db:setup` first." | |||||
| "to run\n`rake db:reset tmp:cache:clear` first." | |||||
| next | next | ||||
| end | end | ||||
| if AdminSetting.get(:corp_id).to_i > 0 | if AdminSetting.get(:corp_id).to_i > 0 | ||||
| puts "The database is not empty; you should change settings from "\ | puts "The database is not empty; you should change settings from "\ | ||||
| "within the\napplication. Alternatively, you can start over with\n"\ | "within the\napplication. Alternatively, you can start over with\n"\ | ||||
| "`rake db:reset db:setup calefaction:setup`." | |||||
| "`rake db:reset tmp:cache:clear calefaction:setup`." | |||||
| next | next | ||||
| end | end | ||||
| @@ -43,7 +43,7 @@ namespace :calefaction do | |||||
| api_verify = STDIN.gets.chomp | api_verify = STDIN.gets.chomp | ||||
| user = User.new(api_key: api_key, api_verify: api_verify, admin?: true) | user = User.new(api_key: api_key, api_verify: api_verify, admin?: true) | ||||
| chars = user.char_names | |||||
| chars = user.characters | |||||
| if chars.empty? | if chars.empty? | ||||
| puts "The given API key is invalid, has no characters, or something "\ | puts "The given API key is invalid, has no characters, or something "\ | ||||
| "else is wrong\nwith the EVE API right now..." | "else is wrong\nwith the EVE API right now..." | ||||
| @@ -51,20 +51,21 @@ namespace :calefaction do | |||||
| end | end | ||||
| if chars.length == 1 | if chars.length == 1 | ||||
| user.name = chars.first | |||||
| puts "\nUsing character: #{user.name}" | |||||
| puts "\nUsing character: #{chars.first.name}" | |||||
| user.userid = chars.first.characterID | |||||
| else | else | ||||
| puts "\nChoose a character:" | puts "\nChoose a character:" | ||||
| chars.each_with_index do |name, i| | |||||
| puts " [#{i}]: #{name}" | |||||
| chars.each_with_index do |char, i| | |||||
| puts " [#{i}]: #{char.name}" | |||||
| end | end | ||||
| puts "Enter the number next to your chosen character: " | |||||
| print "Enter the number next to your chosen character: " | |||||
| loop do | loop do | ||||
| index = STDIN.gets.to_i | index = STDIN.gets.to_i | ||||
| break if index >= 0 && index < chars.length | |||||
| puts "Bad input; try again: " | |||||
| if index >= 0 && index < chars.length | |||||
| user.userid = chars[index].characterID and break | |||||
| end | |||||
| print "Bad input; try again: " | |||||
| end | end | ||||
| user.name = chars[index] | |||||
| end | end | ||||
| unless user.member_of? corp_id | unless user.member_of? corp_id | ||||
| @@ -72,9 +73,12 @@ namespace :calefaction do | |||||
| next | next | ||||
| end | end | ||||
| print "\nEnter your email address (used for password resets; may be blank): " | |||||
| print "\nEnter your email address (required; used to log in): " | |||||
| user.email = STDIN.gets.chomp | user.email = STDIN.gets.chomp | ||||
| user.email = nil if user.email.empty? | |||||
| if user.email.blank? | |||||
| puts "\nInvalid email address. Stopping." | |||||
| next | |||||
| end | |||||
| print "\nEnter your new password (to log in to the website, **NOT** for EVE!): " | print "\nEnter your new password (to log in to the website, **NOT** for EVE!): " | ||||
| user.password = STDIN.noecho(&:gets).chomp | user.password = STDIN.noecho(&:gets).chomp | ||||