Skip to content

Commit

Permalink
heroku was causing problems because I needed to change the db schema
Browse files Browse the repository at this point in the history
  • Loading branch information
lancejpollard committed Jun 1, 2010
1 parent ff7edc6 commit 716c6b9
Show file tree
Hide file tree
Showing 15 changed files with 64 additions and 46 deletions.
7 changes: 6 additions & 1 deletion app/controllers/user_sessions_controller.rb
Expand Up @@ -15,7 +15,12 @@ def create
flash[:notice] = "Login successful!"
redirect_to current_user ? profile_url(current_user) : login_url
else
render :action => :new
if @user_session.errors.on(:user)
# if we set error on the base object, likely it's because we didn't find a user
render :action => :confirm
else
render :action => :new
end
end
end
end
Expand Down
10 changes: 3 additions & 7 deletions app/controllers/users_controller.rb
Expand Up @@ -2,11 +2,6 @@ class UsersController < ApplicationController
before_filter :require_no_user, :only => [:new, :create]
before_filter :require_user, :only => [:show, :edit, :update]
before_filter :admin_only, :only => :detonate
before_filter :show_sesh

def show_sesh
#puts "SESH: #{session.inspect}"
end

def new
@user = User.new
Expand All @@ -20,7 +15,7 @@ def create
flash[:notice] = "Account registered!"
redirect_back_or_default profile_url(@user)
else
render :action => :new
redirect_to login_url
end
end
end
Expand All @@ -35,6 +30,7 @@ def edit
end

def update
return create unless @current_user
@user = @current_user # makes our views "cleaner" and more consistent
@user.update_attributes(params[:user]) do |result|
if result
Expand All @@ -50,6 +46,6 @@ def update
def detonate
session.clear
User.all.collect(&:destroy)
redirect_to signup_url
redirect_to login_url
end
end
6 changes: 5 additions & 1 deletion app/models/user.rb
@@ -1,5 +1,9 @@
class User < ActiveRecord::Base
acts_as_authentic
acts_as_authentic do |config|
config.validate_email_field = false
config.validate_login_field = false
config.validate_password_field = false
end

include Profile
end
14 changes: 14 additions & 0 deletions app/views/user_sessions/confirm.html.haml
@@ -0,0 +1,14 @@
%h2 Confirm
%form.authentication_form{:action => signup_url, :method => :post}
%fieldset
/ authentication_type should be "user" or "session", based on controller
- transfer = case session[:auth_method]
- when "oauth"
- %w(_key _token _secret auth_method oauth_provider)
- when "openid"
- %w(auth_method openid_identifier)
- transfer.each do |hidden|
%input{:type => :hidden, :name => hidden.to_sym, :value => session[hidden.to_sym]}
%input{:type => :hidden, :name => :authentication_type, :value => :user}
%input{:type => :text, :name => "user[email]"}
%input.submit{:name => :submit, :type => :submit, :value => "Register"}/
19 changes: 10 additions & 9 deletions app/views/user_sessions/new.html.haml
@@ -1,18 +1,19 @@
%h2 Login!
%form#authentication_form{:action => authenticate_url, :method => :post}
- form_for @user_session, :url => authenticate_path, :html => { :method => :post, :class => "authentication_form" } do |f|
= f.error_messages
/ authentication_type should be "user" or "session", based on controller
= oauth_login_hidden_input
%fieldset
%input{:type => :hidden, :name => :authentication_method, :value => :oauth}
%input{:type => :hidden, :name => :authentication_type, :value => :session}
%legend Click your Oauth or OpenID provider.
%legend Click your Oauth or OpenID provider
.oauth_providers
%ul
- %w(google facebook twitter).each do |name|
- %w(google facebook twitter yahoo myspace linked_in).each do |name|
%li.oauth_provider
%img{:src => "/images/icons/#{name}.png"}
%input{:type => :radio, :id => "#{name}_oauth_provider", :name => :oauth_provider, :value => name}
= image_tag "/images/icons/#{name}.png"
= radio_button_tag :oauth_provider, name
.clearfix
%fieldset
%legend Or type in your OpenID address
.openid_address
%input.nice{:type => :text, :name => "openid_identifier"}
%input.submit{:name => :submit, :type => :submit, :value => "Register"}/
= text_field_tag :openid_identifier, nil, :class => :nice
= submit_tag "Login", :class => :submit
6 changes: 3 additions & 3 deletions app/views/users/edit.html.haml
@@ -1,12 +1,12 @@
%h2 My Account
%form#authentication_form{:action => connected_path, :method => :post}
%form.authentication_form{:action => connected_path, :method => :post}
%fieldset
%input{:type => :hidden, :name => :authentication_type, :value => :user}
%input{:type => :hidden, :name => :_method, :value => :put}
%legend Add another Oauth or OpenID provider.
.oauth_providers
%ul
- %w(google facebook twitter).each do |name|
- %w(google facebook twitter yahoo myspace linked_in).each do |name|
%li.oauth_provider
%img{:src => "/images/icons/#{name}.png"}
%input{:type => :radio, :id => "#{name}_oauth_provider", :name => :oauth_provider, :value => name}
Expand All @@ -15,4 +15,4 @@
%legend Or type in your OpenID address
.openid_address
%input.nice{:type => :text, :name => "openid_identifier"}
%input.submit{:name => :submit, :type => :submit, :value => "Update"}/
%input.submit{:name => :submit, :type => :submit, :value => "Update"}/
8 changes: 4 additions & 4 deletions app/views/users/new.html.haml
@@ -1,12 +1,12 @@
%h2 Login or Register!
%form#authentication_form{:action => register_url, :method => :post}
%h2 LogIn!
%form.authentication_form{:action => signup_url, :method => :post}
%fieldset
/ authentication_type should be "user" or "session", based on controller
%input{:type => :hidden, :name => :authentication_type, :value => :user}
%input{:type => :hidden, :name => :authentication_type, :value => current_user.nil? ? :user : :session}
%legend Click your Oauth or OpenID provider.
.oauth_providers
%ul
- %w(google facebook twitter).each do |name|
- %w(google facebook twitter yahoo myspace linked_in).each do |name|
%li.oauth_provider
%img{:src => "/images/icons/#{name}.png"}
%input{:type => :radio, :id => "#{name}_oauth_provider", :name => :oauth_provider, :value => name}
Expand Down
15 changes: 10 additions & 5 deletions config/routes.rb
@@ -1,15 +1,20 @@
ActionController::Routing::Routes.draw do |map|
map.connect '/', :controller => :users, :action => :new
map.reset "reset", :controller => :users, :action => :detonate
map.logout 'logout', :controller => :user_sessions, :action => :destroy

map.login 'login', :controller => :user_sessions, :action => :new
map.logout 'logout', :controller => :user_sessions, :action => :destroy, :conditions => {:method => :get}
map.authenticate 'authenticate', :controller => :user_sessions, :action => :create, :conditions => {:method => :post}
map.signup 'signup', :controller => :users, :action => :new, :as => :signup
map.register 'register', :controller => :users, :action => :create, :conditions => {:method => :post}
map.connected 'connected', :controller => :users, :action => :update, :conditions => {:method => :put}

map.register 'register', :controller => :users, :action => :new
map.signup 'signup', :controller => :users, :action => :create, :conditions => {:method => :post}
map.connected 'connect', :controller => :users, :action => :update, :conditions => {:method => :put}

map.resources :users
map.resource :user_session

map.reset "reset", :controller => :users, :action => :detonate

map.profile ':id', :controller => :users, :action => :show

map.root :controller => 'users'
end
8 changes: 0 additions & 8 deletions console

This file was deleted.

3 changes: 2 additions & 1 deletion db/migrate/20100506020514_create_users.rb
Expand Up @@ -4,6 +4,7 @@ def self.up
# authlogic
t.timestamps
t.string :login, :null => true
t.string :email, :null => true
t.string :crypted_password, :null => true
t.string :password_salt, :null => true
t.string :persistence_token, :null => false
Expand All @@ -22,7 +23,7 @@ def self.up
add_index :users, :last_request_at
add_index :users, :active_token_id
end

def self.down
drop_table :users
end
Expand Down
@@ -1,6 +1,6 @@
class CreateTokens < ActiveRecord::Migration
class CreateAccessTokens < ActiveRecord::Migration
def self.up
create_table :tokens do |t|
create_table :access_tokens do |t|
t.integer :user_id
t.string :type, :limit => 30
t.string :key # how we identify the user, in case they logout and log back in
Expand All @@ -10,11 +10,10 @@ def self.up
t.timestamps
end

add_index :tokens, :key, :unique
add_index :tokens, :token, :unique
add_index :access_tokens, :key, :unique
end

def self.down
drop_table :tokens
drop_table :access_tokens
end
end
1 change: 1 addition & 0 deletions db/schema.rb
Expand Up @@ -39,6 +39,7 @@
t.datetime "created_at"
t.datetime "updated_at"
t.string "login"
t.string "email"
t.string "crypted_password"
t.string "password_salt"
t.string "persistence_token", :null => false
Expand Down
File renamed without changes
2 changes: 1 addition & 1 deletion public/javascripts/application.js
Expand Up @@ -2,7 +2,7 @@ $ = jQuery.noConflict();
Cufon.replace('h2, p, legend');

$(document).ready(function() {
$form = $("#authentication_form");
$form = $(".authentication_form");

// progressively enhance buttons
$("li.oauth_provider").each(function(index, element) {
Expand Down
2 changes: 1 addition & 1 deletion public/stylesheets/application.css
Expand Up @@ -163,7 +163,7 @@ input#btn::-moz-focus-inner, input[type="button"]::-moz-focus-inner {
border : 0px;
}

#authentication_form {
.authentication_form {
clear:both;
width:501px;
height:45px;
Expand Down

0 comments on commit 716c6b9

Please sign in to comment.