Skip to content

Commit

Permalink
Merge branch 'master' of github.com:annaswims/GrinnellPlans
Browse files Browse the repository at this point in the history
Conflicts:
	Gemfile
  • Loading branch information
annaswims committed Mar 12, 2011
2 parents 17d816a + 984c953 commit 715ce5a
Show file tree
Hide file tree
Showing 18 changed files with 269 additions and 32 deletions.
30 changes: 30 additions & 0 deletions Gemfile
@@ -0,0 +1,30 @@
source 'http://rubygems.org'
source 'http://gems.github.com'

gem 'rails', '3.0.4'
gem 'sqlite3'
gem 'capistrano'
gem 'mysql'
gem 'haml'
gem 'authlogic'
gem 'dynamic_form'
gem 'crypt3'

#https://github.com/rails/jquery-ujs
gem 'jquery-rails', '>= 0.2.6'

group :production do
gem "exception_notification", :git => "git://github.com/rails/exception_notification", :require => 'exception_notifier'
end

group :development do
gem 'hirb'
gem 'annotate'
gem "railroady"
# gem 'rails3-footnotes'
# To use debugger (ruby-debug for Ruby 1.8.7+, ruby-debug19 for Ruby 1.9.2+)
gem 'ruby-debug'
# gem 'ruby-debug19'
gem "single_test"
end

11 changes: 11 additions & 0 deletions Gemfile.lock
Expand Up @@ -37,6 +37,8 @@ GEM
activesupport (3.0.4)
annotate (2.4.0)
arel (2.0.8)
authlogic (2.1.6)
activesupport
builder (2.1.2)
capistrano (2.5.19)
highline
Expand All @@ -45,6 +47,8 @@ GEM
net-ssh (>= 2.0.14)
net-ssh-gateway (>= 1.0.0)
columnize (0.3.2)
crypt3 (1.1.2)
dynamic_form (1.1.3)
erubis (2.6.6)
abstract (>= 1.0.0)
haml (3.0.25)
Expand Down Expand Up @@ -95,6 +99,8 @@ GEM
ruby-debug-base (~> 0.10.4.0)
ruby-debug-base (0.10.4)
linecache (>= 0.3)
single_test (0.3.7)
sqlite3 (1.3.3)
thor (0.14.6)
treetop (1.4.9)
polyglot (>= 0.3.1)
Expand All @@ -105,7 +111,10 @@ PLATFORMS

DEPENDENCIES
annotate
authlogic
capistrano
crypt3
dynamic_form
exception_notification!
haml
hirb
Expand All @@ -114,3 +123,5 @@ DEPENDENCIES
railroady
rails (= 3.0.4)
ruby-debug
single_test
sqlite3
2 changes: 2 additions & 0 deletions Rakefile
Expand Up @@ -3,5 +3,7 @@

require File.expand_path('../config/application', __FILE__)
require 'rake'
require 'single_test'

Plans::Application.load_tasks
SingleTest.load_tasks
21 changes: 21 additions & 0 deletions app/controllers/account_sessions_controller.rb
@@ -0,0 +1,21 @@
class AccountSessionsController < ApplicationController

def new
@session = AccountSession.new
end

def create
@session = AccountSession.new params[ :account_session ]
if @session.save
redirect_to :controller => :home, :action => :index
else
render :action => :new
end
end

def destroy
current_account_session.destroy
flash[ :notice ] = "You've been logged out."
redirect_to new_account_session_path
end
end
7 changes: 7 additions & 0 deletions app/controllers/application_controller.rb
Expand Up @@ -6,4 +6,11 @@ class ApplicationController < ActionController::Base
# Likewise, all the methods added will be available for all controllers.
helper :all # include all helpers, all the time

def current_account
@current_account ||= current_account_session && current_account_session.record
end

def current_account_session
@current_account_session ||= AccountSession.find
end
end
23 changes: 22 additions & 1 deletion app/models/account.rb
Expand Up @@ -21,7 +21,11 @@ class Account < ActiveRecord::Base
has_one :viewed_secret, :foreign_key=> :userid
has_one :plan, :foreign_key => :user_id
has_one :display, :foreign_key => :user_id


before_validation do
self.show_images = true
end

#can't have "changed" attribute because of changed? method
class << self
def instance_method_already_implemented?(method_name)
Expand All @@ -36,6 +40,23 @@ def changed_date
self[:changed]
end

acts_as_authentic do |c|
c.login_field :username
c.crypted_password_field :crypted_password
c.crypto_provider PhpCrypt::CryptoProviders::MD5
c.transition_from_crypto_providers PhpCrypt::CryptoProviders::DES
c.validate_email_field false
c.check_passwords_against_database false
end

# Trick authlogic into behaving with our column name
def crypted_password= hash
write_attribute :password, hash
end

def crypted_password
read_attribute :password
end
end


Expand Down
6 changes: 6 additions & 0 deletions app/models/account_session.rb
@@ -0,0 +1,6 @@
class AccountSession < Authlogic::Session::Base
# Workaround for Rails 3 compat
def to_key
new_record? ? nil : [ self.send(self.class.primary_key) ]
end
end
Expand Up @@ -7,7 +7,8 @@
=image_tag "logo.png"
%tr.boxes
%td.boxes{:colspan=>2, :align=>"center"}
=form_for @account, :url=>{:action=>:login} do |f|
=form_for @session, :url => account_session_path do |f|
= f.error_messages
=f.label :username
=f.text_field :username
%br
Expand All @@ -20,7 +21,7 @@
document.getElementById("account_js_test_value").value = "on";
%tr
%td{:align=>"right", :width=>"50%"}
=form_for @account, :url=>{:action=>:login} do |f|
=form_for @session do |f|
=f.hidden_field "guest", :value => "1"
=f.submit "Guest"
%td
Expand Down
2 changes: 1 addition & 1 deletion config/application.rb
Expand Up @@ -13,7 +13,7 @@ class Application < Rails::Application
# -- all .rb files in that directory are automatically loaded.

# Custom directories with classes and modules you want to be autoloadable.
# config.autoload_paths += %W(#{config.root}/extras)
config.autoload_paths += %W(#{config.root}/lib)

# Only load the plugins named here, in the order given (default is alphabetical).
# :all can be used as a placeholder for all plugins not explicitly named.
Expand Down
1 change: 1 addition & 0 deletions config/routes.rb
Expand Up @@ -58,4 +58,5 @@
# This is a legacy wild controller route that's not recommended for RESTful applications.
# Note: This route will make all actions in every controller accessible via GET requests.
match ':controller(/:action(/:id(.:format)))'
resource :account_session, :only => [ :new, :create, :destroy ]
end
11 changes: 11 additions & 0 deletions db/migrate/20110227065143_add_authlogic_columns.rb
@@ -0,0 +1,11 @@
class AddAuthlogicColumns < ActiveRecord::Migration
def self.up
add_column :accounts, :persistence_token, :string
add_column :accounts, :password_salt, :string
end

def self.down
remove_column :accounts, :persistence_token
remove_column :accounts, :password_salt
end
end
64 changes: 36 additions & 28 deletions db/schema.rb
Expand Up @@ -10,35 +10,37 @@
#
# It's strongly recommended to check this file into your version control system.

ActiveRecord::Schema.define(:version => 0) do
ActiveRecord::Schema.define(:version => 20110227065143) do

create_table "accounts", :primary_key => "userid", :force => true do |t|
t.string "username", :limit => 16, :default => "", :null => false
t.string "username", :limit => 16, :default => "", :null => false
t.datetime "created"
t.string "password", :limit => 34
t.string "email", :limit => 64
t.string "pseudo", :limit => 64
t.string "password", :limit => 34
t.string "email", :limit => 64
t.string "pseudo", :limit => 64
t.datetime "login"
t.datetime "changed"
t.integer "poll", :limit => 1
t.string "group_bit", :limit => 1
t.integer "poll", :limit => 1
t.string "group_bit", :limit => 1
t.string "spec_message"
t.string "grad_year", :limit => 4
t.integer "edit_cols", :limit => 1
t.integer "edit_rows", :limit => 1
t.string "webview", :limit => 1, :default => "0"
t.string "notes_asc", :limit => 1
t.string "user_type", :limit => 128
t.boolean "show_images", :default => false, :null => false
t.string "guest_password", :limit => 30
t.boolean "is_admin", :default => false
t.string "grad_year", :limit => 4
t.integer "edit_cols", :limit => 1
t.integer "edit_rows", :limit => 1
t.string "webview", :limit => 1, :default => "0"
t.string "notes_asc", :limit => 1
t.string "user_type", :limit => 128
t.boolean "show_images", :default => false, :null => false
t.string "guest_password", :limit => 30
t.boolean "is_admin", :default => false
t.string "persistence_token"
t.string "password_salt"
end

add_index "accounts", ["changed"], :name => "changed"
add_index "accounts", ["password"], :name => "password"
add_index "accounts", ["password"], :name => "password_2"
add_index "accounts", ["username", "changed"], :name => "username_changed"
add_index "accounts", ["username", "userid"], :name => "usernameid_uniq", :unique => true
add_index "accounts", ["username"], :name => "username", :unique => true
add_index "accounts", ["username"], :name => "username_2"

create_table "autofinger", :id => false, :force => true do |t|
t.integer "owner", :limit => 2, :default => 0, :null => false
Expand All @@ -50,21 +52,22 @@
end

add_index "autofinger", ["interest"], :name => "interest"
add_index "autofinger", ["owner", "interest"], :name => "unique", :unique => true
add_index "autofinger", ["owner"], :name => "owner"

create_table "avail_links", :primary_key => "linknum", :force => true do |t|
t.string "linkname", :limit => 128
t.text "descr"
t.text "html_code", :limit => 255
t.text "static", :limit => 255
t.text "html_code"
t.text "static"
end

create_table "boardvotes", :primary_key => "voteid", :force => true do |t|
t.integer "userid", :limit => 2, :default => 0, :null => false
t.integer "threadid", :limit => 2, :default => 0, :null => false
t.integer "messageid", :limit => 2, :default => 0, :null => false
t.timestamp "vote_date", :null => false
t.integer "vote", :limit => 2
t.integer "userid", :limit => 2, :default => 0, :null => false
t.integer "threadid", :limit => 2, :default => 0, :null => false
t.integer "messageid", :limit => 2, :default => 0, :null => false
t.datetime "vote_date", :null => false
t.integer "vote", :limit => 2
end

create_table "display", :primary_key => "userid", :force => true do |t|
Expand All @@ -82,13 +85,17 @@
t.string "status", :limit => 3
end

add_index "js_status", ["userid"], :name => "userid_idx"

create_table "mainboard", :primary_key => "threadid", :force => true do |t|
t.string "title", :limit => 128
t.datetime "created"
t.datetime "lastupdated"
t.integer "userid", :limit => 2, :default => 0, :null => false
end

add_index "mainboard", ["lastupdated"], :name => "lastupdated"

create_table "migration_test", :id => false, :force => true do |t|
t.text "field1"
end
Expand All @@ -110,7 +117,7 @@

create_table "plans", :force => true do |t|
t.integer "user_id", :limit => 2
t.text "plan", :limit => 16777215
t.text "plan", :limit => 2147483647
t.text "edit_text"
end

Expand Down Expand Up @@ -141,13 +148,15 @@
t.datetime "date_approved"
end

add_index "secrets", ["display", "date_approved"], :name => "display_date"

create_table "style", :primary_key => "style", :force => true do |t|
t.string "path", :limit => 128
t.string "descr"
end

create_table "stylesheet", :primary_key => "userid", :force => true do |t|
t.text "stylesheet", :limit => 255
t.text "stylesheet"
end

create_table "subboard", :primary_key => "messageid", :force => true do |t|
Expand All @@ -159,7 +168,6 @@
end

add_index "subboard", ["threadid"], :name => "threadid"
add_index "subboard", ["userid"], :name => "userid"

create_table "system", :id => false, :force => true do |t|
t.text "motd"
Expand Down
6 changes: 6 additions & 0 deletions db/seeds.rb
@@ -1,7 +1,13 @@
require 'active_record/fixtures'
# This file should contain all the record creation needed to seed the database with its default values.
# The data can then be loaded with the rake db:seed (or created alongside the db with db:setup).
#
# Examples:
#
# cities = City.create([{ :name => 'Chicago' }, { :name => 'Copenhagen' }])
# Mayor.create(:name => 'Daley', :city => cities.first)

puts "Loading #{Rails.env} seeds"
Dir[Rails.root.join("db/seed", Rails.env, "*.{yml,csv}")].each do |file|
Fixtures.create_fixtures("db/seed/#{Rails.env}", File.basename(file, '.*'))
end
19 changes: 19 additions & 0 deletions lib/php_crypt/crypto_providers/des.rb
@@ -0,0 +1,19 @@
module PhpCrypt
module CryptoProviders
class DES
attr_writer :salt
def self.salt
@salt ||= "ab"
end

def self.encrypt *tokens
tokens.join.crypt salt
end

def self.matches? crypted, *tokens
salt = crypted[ 0..1 ]
crypted == tokens.join.crypt( salt )
end
end
end
end
17 changes: 17 additions & 0 deletions lib/php_crypt/crypto_providers/md5.rb
@@ -0,0 +1,17 @@
module PhpCrypt
module CryptoProviders
class MD5
def self.encrypt *tokens
Crypt3.crypt tokens.join
end

def self.matches? crypted, *tokens
begin
Crypt3.check tokens.join, crypted
rescue
false
end
end
end
end
end

0 comments on commit 715ce5a

Please sign in to comment.