@@ -4,6 +4,7 @@ gem 'rails', '4.2.0' | |||||
gem 'sqlite3' | gem 'sqlite3' | ||||
gem 'uglifier', '>= 1.3.0' | gem 'uglifier', '>= 1.3.0' | ||||
gem 'jquery-rails' | gem 'jquery-rails' | ||||
gem 'bcrypt', '~> 3.1.7' | |||||
# At this point, avoid using SASS or CoffeeScript | # At this point, avoid using SASS or CoffeeScript | ||||
# gem 'sass-rails', '~> 5.0' | # gem 'sass-rails', '~> 5.0' | ||||
@@ -21,9 +22,6 @@ gem 'jquery-rails' | |||||
# bundle exec rake doc:rails generates the API under doc/api. | # bundle exec rake doc:rails generates the API under doc/api. | ||||
# gem 'sdoc', '~> 0.4.0', group: :doc | # gem 'sdoc', '~> 0.4.0', group: :doc | ||||
# Use ActiveModel has_secure_password | |||||
# gem 'bcrypt', '~> 3.1.7' | |||||
group :development, :test do | group :development, :test do | ||||
# Call 'byebug' anywhere in the code to stop execution and get a debugger console | # Call 'byebug' anywhere in the code to stop execution and get a debugger console | ||||
gem 'byebug' | gem 'byebug' | ||||
@@ -37,6 +37,7 @@ GEM | |||||
thread_safe (~> 0.3, >= 0.3.4) | thread_safe (~> 0.3, >= 0.3.4) | ||||
tzinfo (~> 1.1) | tzinfo (~> 1.1) | ||||
arel (6.0.0) | arel (6.0.0) | ||||
bcrypt (3.1.10) | |||||
binding_of_caller (0.7.2) | binding_of_caller (0.7.2) | ||||
debug_inspector (>= 0.0.1) | debug_inspector (>= 0.0.1) | ||||
builder (3.2.2) | builder (3.2.2) | ||||
@@ -125,6 +126,7 @@ PLATFORMS | |||||
ruby | ruby | ||||
DEPENDENCIES | DEPENDENCIES | ||||
bcrypt (~> 3.1.7) | |||||
byebug | byebug | ||||
jquery-rails | jquery-rails | ||||
rails (= 4.2.0) | rails (= 4.2.0) | ||||
@@ -9,4 +9,6 @@ Installing | |||||
calefaction can be deployed as a standard Rails app. | calefaction can be deployed as a standard Rails app. | ||||
- describe db setup here... | |||||
To set up the database and create your admin account, run: | |||||
rake db:setup calefaction:setup |
@@ -1,7 +1,11 @@ | |||||
class UsersController < ApplicationController | class UsersController < ApplicationController | ||||
def create | |||||
def login | |||||
end | end | ||||
def login | |||||
def signup | |||||
end | |||||
def create | |||||
render 'signup' | |||||
end | end | ||||
end | end |
@@ -1,2 +1,10 @@ | |||||
module ToolsHelper | module ToolsHelper | ||||
TOOLS = [ | |||||
{:name => :campaigns}, | |||||
{:name => :recruitment}, | |||||
{:name => :stratmap}, | |||||
{:name => :tspsolver}, | |||||
{:name => :navyinfo}, | |||||
{:name => :combatsim} | |||||
] | |||||
end | end |
@@ -0,0 +1,20 @@ | |||||
module Encryptor | |||||
extend ActiveSupport::Concern | |||||
class_methods do | |||||
def encrypt(value) | |||||
ensure_encryptor | |||||
@crypt.encrypt_and_sign(value) | |||||
end | |||||
def decrypt(value) | |||||
ensure_encryptor | |||||
@crypt.decrypt_and_verify(value) | |||||
end | |||||
private | |||||
def ensure_encryptor | |||||
@crypt ||= ActiveSupport::MessageEncryptor.new(Rails.application.secrets.secret_key_base) | |||||
end | |||||
end | |||||
end |
@@ -1,2 +1,18 @@ | |||||
# require 'calefaction/api/eveonline' | |||||
class User < ActiveRecord::Base | class User < ActiveRecord::Base | ||||
include Encryptor | |||||
has_secure_password | |||||
def api_verify | |||||
self.class.decrypt(super()) | |||||
end | |||||
def api_verify=(value) | |||||
super(self.class.encrypt(value)) | |||||
end | |||||
def member_of?(corp_id) | |||||
false | |||||
end | |||||
end | end |
@@ -1,6 +1,6 @@ | |||||
<% provide(:title, 'Admin') %> | <% provide(:title, 'Admin') %> | ||||
<h1>Admin#index</h1> | |||||
<h1>Admin Settings</h1> | |||||
<%= form_tag do %> | <%= form_tag do %> | ||||
<table> | <table> | ||||
@@ -6,7 +6,7 @@ | |||||
</span> | </span> | ||||
<% end %> | <% end %> | ||||
<span id="user-links"> | <span id="user-links"> | ||||
<%= link_to "Signup", controller: "users", action: "create" %> | |||||
<%= link_to "Signup", controller: "users", action: "signup" %> | |||||
• | • | ||||
<%= link_to "Login", controller: "users", action: "login" %> | <%= link_to "Login", controller: "users", action: "login" %> | ||||
• | • | ||||
@@ -1,5 +1 @@ | |||||
<h1>Tools#index</h1> | |||||
<p>Tools: ...</p> | |||||
<p><%= AdminSetting.get('description') %></p> | <p><%= AdminSetting.get('description') %></p> |
@@ -1,4 +0,0 @@ | |||||
<% provide(:title, 'Signup') %> | |||||
<h1>Users#create</h1> | |||||
<p>Find me in app/views/users/create.html.erb</p> |
@@ -0,0 +1,4 @@ | |||||
<% provide(:title, 'Signup') %> | |||||
<h1>Users#signup</h1> | |||||
<p>Find me in app/views/users/signup.html.erb</p> |
@@ -1,12 +1,16 @@ | |||||
Rails.application.routes.draw do | Rails.application.routes.draw do | ||||
root 'tools#index' | root 'tools#index' | ||||
get '/signup' => 'users#create' | |||||
get '/login' => 'users#login' | get '/login' => 'users#login' | ||||
get '/signup' => 'users#signup' | |||||
post '/signup' => 'users#create' | |||||
get '/admin' => 'admin#index' | get '/admin' => 'admin#index' | ||||
post '/admin' => 'admin#update' | post '/admin' => 'admin#update' | ||||
# routes for each tool go here, e.g.: | |||||
# get 'tools#campaigns' | |||||
# Example of named route that can be invoked with purchase_url(id: product.id) | # Example of named route that can be invoked with purchase_url(id: product.id) | ||||
# get 'products/:id/purchase' => 'catalog#purchase', as: :purchase | # get 'products/:id/purchase' => 'catalog#purchase', as: :purchase | ||||
@@ -3,8 +3,11 @@ class CreateUsers < ActiveRecord::Migration | |||||
create_table :users do |t| | create_table :users do |t| | ||||
t.string :name | t.string :name | ||||
t.string :email | t.string :email | ||||
t.string :password_hash | |||||
t.string :password_digest | |||||
t.string :api_key | |||||
t.string :api_verify | |||||
t.boolean :is_admin | t.boolean :is_admin | ||||
t.boolean :is_corp | |||||
t.timestamps null: false | t.timestamps null: false | ||||
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: 20150313054643) do | |||||
ActiveRecord::Schema.define(version: 20150314013929) do | |||||
create_table "admin_settings", force: :cascade do |t| | create_table "admin_settings", force: :cascade do |t| | ||||
t.string "key" | t.string "key" | ||||
@@ -21,10 +21,13 @@ ActiveRecord::Schema.define(version: 20150313054643) do | |||||
create_table "users", force: :cascade do |t| | create_table "users", force: :cascade do |t| | ||||
t.string "name" | t.string "name" | ||||
t.string "email" | t.string "email" | ||||
t.string "password_hash" | |||||
t.string "password_digest" | |||||
t.string "api_key" | |||||
t.string "api_verify" | |||||
t.boolean "is_admin" | t.boolean "is_admin" | ||||
t.datetime "created_at", null: false | |||||
t.datetime "updated_at", null: false | |||||
t.boolean "is_corp" | |||||
t.datetime "created_at", null: false | |||||
t.datetime "updated_at", null: false | |||||
end | end | ||||
end | end |
@@ -0,0 +1,55 @@ | |||||
require 'io/console' | |||||
namespace :calefaction do | |||||
desc "Sets some initial database values and creates an admin user" | |||||
task setup: :environment do | |||||
print "Enter your corporation's name: " | |||||
corp_name = STDIN.gets.chomp | |||||
print "\nEnter your corporation's ID (this is visible in the URL for "\ | |||||
"your corp's page on \nzKillboard, among other places): " | |||||
corp_id = STDIN.gets.chomp.to_i | |||||
if corp_id <= 0 | |||||
puts 'Corporation ID must be a positive integer. Stopping.' | |||||
next | |||||
end | |||||
print "\nEnter your character's name: " | |||||
user_name = STDIN.gets.chomp | |||||
print "\nEnter your email address (used for password resets; may be blank): " | |||||
user_email = STDIN.gets.chomp | |||||
user_email = nil if user_email.empty? | |||||
print "\nEnter your new password (to log in to the website, **NOT** for EVE!): " | |||||
user_pass = STDIN.noecho(&:gets).chomp | |||||
puts | |||||
print "\nConfirm the password: " | |||||
if user_pass != STDIN.noecho(&:gets).chomp | |||||
puts "\nPasswords do not match. Stopping." | |||||
next | |||||
end | |||||
puts | |||||
print "\nEnter your character's API key ID (create one at\n"\ | |||||
"https://community.eveonline.com/support/api-key/createpredefined?accessMask=8): " | |||||
user_api_key = STDIN.gets.chomp | |||||
print "\nEnter the verification code for the key you just entered: " | |||||
user_api_verify = STDIN.gets.chomp | |||||
User.transaction do | |||||
AdminSetting.where(key: %w(corp_name site_name)).update_all(value: corp_name) | |||||
AdminSetting.find_by(key: 'corp_id').update(value: corp_id) | |||||
user = User.new(name: user_name, email: user_email, password: user_pass, | |||||
api_key: user_api_key, api_verify: user_api_verify, | |||||
is_admin: true, is_corp: true) | |||||
unless user.member_of? corp_id | |||||
puts 'You are not a member of the given corporation. Stopping.' | |||||
raise ActiveRecord::Rollback | |||||
end | |||||
user.save | |||||
end | |||||
end | |||||
end |
@@ -3,11 +3,15 @@ | |||||
one: | one: | ||||
name: MyString | name: MyString | ||||
email: MyString | email: MyString | ||||
password_hash: MyString | |||||
password_digest: <%= BCrypt::Password.create('secret') %> | |||||
api_key: MyString | |||||
is_admin: false | is_admin: false | ||||
is_corp: false | |||||
two: | two: | ||||
name: MyString | name: MyString | ||||
email: MyString | email: MyString | ||||
password_hash: MyString | |||||
password_digest: <%= BCrypt::Password.create('secret') %> | |||||
api_key: MyString | |||||
is_admin: false | is_admin: false | ||||
is_corp: false |