Kaynağa Gözat

Finish most of the user model, add a thing to init the db and create an admin.

old-ruby
Ben Kurtovic 9 yıl önce
ebeveyn
işleme
92b10037cd
23 değiştirilmiş dosya ile 139 ekleme ve 24 silme
  1. +1
    -3
      Gemfile
  2. +2
    -0
      Gemfile.lock
  3. +3
    -1
      README.md
  4. +6
    -2
      app/controllers/users_controller.rb
  5. +8
    -0
      app/helpers/tools_helper.rb
  6. +0
    -0
     
  7. +0
    -0
     
  8. +20
    -0
      app/models/concerns/encryptor.rb
  9. +16
    -0
      app/models/user.rb
  10. +1
    -1
      app/views/admin/index.html.erb
  11. +1
    -1
      app/views/shared/_header.html.erb
  12. +0
    -4
      app/views/tools/index.html.erb
  13. +0
    -4
      app/views/users/create.html.erb
  14. +4
    -0
      app/views/users/signup.html.erb
  15. +5
    -1
      config/routes.rb
  16. +4
    -1
      db/migrate/20150314013929_create_users.rb
  17. +7
    -4
      db/schema.rb
  18. +0
    -0
     
  19. +55
    -0
      lib/tasks/calefaction.rake
  20. +0
    -0
     
  21. +0
    -0
     
  22. +6
    -2
      test/fixtures/users.yml
  23. +0
    -0
     

+ 1
- 3
Gemfile Dosyayı Görüntüle

@@ -4,6 +4,7 @@ gem 'rails', '4.2.0'
gem 'sqlite3'
gem 'uglifier', '>= 1.3.0'
gem 'jquery-rails'
gem 'bcrypt', '~> 3.1.7'

# At this point, avoid using SASS or CoffeeScript
# gem 'sass-rails', '~> 5.0'
@@ -21,9 +22,6 @@ gem 'jquery-rails'
# bundle exec rake doc:rails generates the API under doc/api.
# gem 'sdoc', '~> 0.4.0', group: :doc

# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'

group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug'


+ 2
- 0
Gemfile.lock Dosyayı Görüntüle

@@ -37,6 +37,7 @@ GEM
thread_safe (~> 0.3, >= 0.3.4)
tzinfo (~> 1.1)
arel (6.0.0)
bcrypt (3.1.10)
binding_of_caller (0.7.2)
debug_inspector (>= 0.0.1)
builder (3.2.2)
@@ -125,6 +126,7 @@ PLATFORMS
ruby

DEPENDENCIES
bcrypt (~> 3.1.7)
byebug
jquery-rails
rails (= 4.2.0)


+ 3
- 1
README.md Dosyayı Görüntüle

@@ -9,4 +9,6 @@ Installing

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

+ 6
- 2
app/controllers/users_controller.rb Dosyayı Görüntüle

@@ -1,7 +1,11 @@
class UsersController < ApplicationController
def create
def login
end

def login
def signup
end

def create
render 'signup'
end
end

+ 8
- 0
app/helpers/tools_helper.rb Dosyayı Görüntüle

@@ -1,2 +1,10 @@
module ToolsHelper
TOOLS = [
{:name => :campaigns},
{:name => :recruitment},
{:name => :stratmap},
{:name => :tspsolver},
{:name => :navyinfo},
{:name => :combatsim}
]
end



+ 20
- 0
app/models/concerns/encryptor.rb Dosyayı Görüntüle

@@ -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

+ 16
- 0
app/models/user.rb Dosyayı Görüntüle

@@ -1,2 +1,18 @@
# require 'calefaction/api/eveonline'

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

+ 1
- 1
app/views/admin/index.html.erb Dosyayı Görüntüle

@@ -1,6 +1,6 @@
<% provide(:title, 'Admin') %>

<h1>Admin#index</h1>
<h1>Admin Settings</h1>

<%= form_tag do %>
<table>


+ 1
- 1
app/views/shared/_header.html.erb Dosyayı Görüntüle

@@ -6,7 +6,7 @@
</span>
<% end %>
<span id="user-links">
<%= link_to "Signup", controller: "users", action: "create" %>
<%= link_to "Signup", controller: "users", action: "signup" %>
&bull;
<%= link_to "Login", controller: "users", action: "login" %>
&bull;


+ 0
- 4
app/views/tools/index.html.erb Dosyayı Görüntüle

@@ -1,5 +1 @@
<h1>Tools#index</h1>

<p>Tools: ...</p>

<p><%= AdminSetting.get('description') %></p>

+ 0
- 4
app/views/users/create.html.erb Dosyayı Görüntüle

@@ -1,4 +0,0 @@
<% provide(:title, 'Signup') %>

<h1>Users#create</h1>
<p>Find me in app/views/users/create.html.erb</p>

+ 4
- 0
app/views/users/signup.html.erb Dosyayı Görüntüle

@@ -0,0 +1,4 @@
<% provide(:title, 'Signup') %>

<h1>Users#signup</h1>
<p>Find me in app/views/users/signup.html.erb</p>

+ 5
- 1
config/routes.rb Dosyayı Görüntüle

@@ -1,12 +1,16 @@
Rails.application.routes.draw do
root 'tools#index'

get '/signup' => 'users#create'
get '/login' => 'users#login'
get '/signup' => 'users#signup'
post '/signup' => 'users#create'

get '/admin' => 'admin#index'
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)
# get 'products/:id/purchase' => 'catalog#purchase', as: :purchase



db/migrate/20150311175036_create_users.rb → db/migrate/20150314013929_create_users.rb Dosyayı Görüntüle

@@ -3,8 +3,11 @@ class CreateUsers < ActiveRecord::Migration
create_table :users do |t|
t.string :name
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_corp

t.timestamps null: false
end

+ 7
- 4
db/schema.rb Dosyayı Görüntüle

@@ -11,7 +11,7 @@
#
# 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|
t.string "key"
@@ -21,10 +21,13 @@ ActiveRecord::Schema.define(version: 20150313054643) do
create_table "users", force: :cascade do |t|
t.string "name"
t.string "email"
t.string "password_hash"
t.string "password_digest"
t.string "api_key"
t.string "api_verify"
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


+ 55
- 0
lib/tasks/calefaction.rake Dosyayı Görüntüle

@@ -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



+ 6
- 2
test/fixtures/users.yml Dosyayı Görüntüle

@@ -3,11 +3,15 @@
one:
name: MyString
email: MyString
password_hash: MyString
password_digest: <%= BCrypt::Password.create('secret') %>
api_key: MyString
is_admin: false
is_corp: false

two:
name: MyString
email: MyString
password_hash: MyString
password_digest: <%= BCrypt::Password.create('secret') %>
api_key: MyString
is_admin: false
is_corp: false


Yükleniyor…
İptal
Kaydet