Skip to content
This repository has been archived by the owner on Dec 12, 2021. It is now read-only.

Commit

Permalink
adding omniauth and logo
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanb committed Oct 16, 2010
1 parent 8f82705 commit cc2af52
Show file tree
Hide file tree
Showing 26 changed files with 296 additions and 8 deletions.
8 changes: 5 additions & 3 deletions Gemfile
Expand Up @@ -3,7 +3,7 @@ source 'http://rubygems.org'
gem 'rails', '3.0.0'
gem 'mysql2'
gem 'nifty-generators'

gem 'omniauth'
gem 'jquery-rails'
gem 'bcrypt-ruby', :require => 'bcrypt'

Expand All @@ -17,5 +17,7 @@ group :development, :test do
gem 'autotest-rails'
end

gem 'capistrano', :group => :development
gem 'thin', :group => :development
group :development do
gem 'capistrano'
gem 'thin'
end
49 changes: 49 additions & 0 deletions Gemfile.lock
Expand Up @@ -29,6 +29,7 @@ GEM
activemodel (= 3.0.0)
activesupport (= 3.0.0)
activesupport (3.0.0)
addressable (2.2.2)
arel (1.0.1)
activesupport (~> 3.0.0)
autotest (4.4.1)
Expand All @@ -51,6 +52,9 @@ GEM
factory_girl_rails (1.0)
factory_girl (~> 1.3)
rails (>= 3.0.0.beta4)
faraday (0.4.6)
addressable (>= 2.1.1)
rack (>= 1.0.1)
go_gtp (0.0.4)
highline (1.6.1)
i18n (0.4.1)
Expand All @@ -63,7 +67,9 @@ GEM
mime-types (1.16)
mocha (0.9.8)
rake
multi_json (0.0.4)
mysql2 (0.2.4)
net-ldap (0.1.1)
net-scp (1.0.4)
net-ssh (>= 1.99.1)
net-sftp (2.0.5)
Expand All @@ -72,10 +78,46 @@ GEM
net-ssh-gateway (1.0.1)
net-ssh (>= 1.99.1)
nifty-generators (0.4.2)
nokogiri (1.4.3.1)
oa-basic (0.1.4)
multi_json (~> 0.0.2)
nokogiri (~> 1.4.2)
oa-core (= 0.1.4)
rest-client (~> 1.6.0)
oa-core (0.1.4)
rack (~> 1.1)
oa-enterprise (0.1.4)
net-ldap (~> 0.1.1)
nokogiri (~> 1.4.2)
oa-core (= 0.1.4)
rubyntlm (~> 0.1.1)
oa-oauth (0.1.4)
multi_json (~> 0.0.2)
nokogiri (~> 1.4.2)
oa-core (= 0.1.4)
oauth (~> 0.4.0)
oauth2 (~> 0.0.10)
oa-openid (0.1.4)
oa-core (= 0.1.4)
rack-openid (~> 1.1.1)
ruby-openid-apps-discovery
oauth (0.4.3)
oauth2 (0.0.13)
faraday (~> 0.4.1)
multi_json (>= 0.0.4)
omniauth (0.1.4)
oa-basic (= 0.1.4)
oa-core (= 0.1.4)
oa-enterprise (= 0.1.4)
oa-oauth (= 0.1.4)
oa-openid (= 0.1.4)
polyglot (0.3.1)
rack (1.2.1)
rack-mount (0.6.13)
rack (>= 1.0.0)
rack-openid (1.1.2)
rack (>= 0.4)
ruby-openid (>= 2.0.3)
rack-test (0.5.6)
rack (>= 1.0)
rails (3.0.0)
Expand All @@ -92,6 +134,8 @@ GEM
rake (>= 0.8.4)
thor (~> 0.14.0)
rake (0.8.7)
rest-client (1.6.1)
mime-types (>= 1.16)
rspec (2.0.0)
rspec-core (= 2.0.0)
rspec-expectations (= 2.0.0)
Expand All @@ -104,6 +148,10 @@ GEM
rspec-expectations (= 2.0.0)
rspec-rails (2.0.1)
rspec (~> 2.0.0)
ruby-openid (2.1.8)
ruby-openid-apps-discovery (1.2.0)
ruby-openid (>= 2.1.7)
rubyntlm (0.1.1)
thin (1.2.7)
daemons (>= 1.0.9)
eventmachine (>= 0.12.6)
Expand All @@ -127,6 +175,7 @@ DEPENDENCIES
mocha
mysql2
nifty-generators
omniauth
rails (= 3.0.0)
rspec-rails (>= 2.0.1)
thin
35 changes: 35 additions & 0 deletions app/controllers/authentications_controller.rb
@@ -0,0 +1,35 @@
class AuthenticationsController < ApplicationController
def index
@authentications = current_user.authentications if current_user
end

def create
omniauth = request.env["omniauth.auth"]
authentication = Authentication.find_by_provider_and_uid(omniauth['provider'], omniauth['uid'])
if authentication
flash[:notice] = "Signed in successfully."
sign_in_and_redirect(:user, authentication.user)
elsif current_user
current_user.authentications.create!(:provider => omniauth['provider'], :uid => omniauth['uid'])
flash[:notice] = "Authentication successful."
redirect_to authentications_url
else
user = User.new
user.apply_omniauth(omniauth)
if user.save
flash[:notice] = "Signed in successfully."
sign_in_and_redirect(:user, user)
else
session[:omniauth] = omniauth.except('extra')
redirect_to new_user_registration_url
end
end
end

def destroy
@authentication = current_user.authentications.find(params[:id])
@authentication.destroy
flash[:notice] = "Successfully destroyed authentication."
redirect_to authentications_url
end
end
2 changes: 2 additions & 0 deletions app/helpers/authentications_helper.rb
@@ -0,0 +1,2 @@
module AuthenticationsHelper
end
11 changes: 11 additions & 0 deletions app/models/authentication.rb
@@ -0,0 +1,11 @@
class Authentication < ActiveRecord::Base
belongs_to :user

def provider_name
if provider == 'open_id'
"OpenID"
else
provider.titleize
end
end
end
3 changes: 2 additions & 1 deletion app/models/user.rb
@@ -1,6 +1,7 @@
class User < ActiveRecord::Base
# new columns need to be added here to be writable through mass assignment
attr_accessible :username, :email, :password, :password_confirmation, :guest

has_many :authentications

attr_accessor :password
before_save :prepare_password
Expand Down
43 changes: 43 additions & 0 deletions app/views/authentications/index.html.erb
@@ -0,0 +1,43 @@
<% title "Sign In Options" %>
<% if @authentications %>
<% unless @authentications.empty? %>
<p><strong>You have signed in with these services:</strong></p>
<div class="authentications">
<% for authentication in @authentications %>
<div class="authentication">
<%= image_tag "auth/#{authentication.provider}_32.png", :size => "32x32" %>
<div class="provider"><%= authentication.provider_name %></div>
<div class="uid"><%= authentication.uid %></div>
<%= link_to "X", authentication, :confirm => 'Are you sure you want to remove this authentication option?', :method => :delete, :class => "remove" %>
</div>
<% end %>
<div class="clear"></div>
</div>
<% end %>
<p><strong>Add another service to sign in with:</strong></p>
<% else %>
<p><strong>Sign in through one of these services:</strong></p>
<% end %>

<a href="/auth/twitter" class="auth_provider">
<%= image_tag "auth/twitter_128.png", :size => "128x128", :alt => "Twitter" %>
Twitter
</a>
<a href="/auth/facebook" class="auth_provider">
<%= image_tag "auth/facebook_128.png", :size => "128x128", :alt => "Facebook" %>
Facebook
</a>
<a href="/auth/open_id" class="auth_provider">
<%= image_tag "auth/open_id_128.png", :size => "128x128", :alt => "OpenID" %>
OpenID
</a>
<div class="clear"></div>

<% unless logged_in? %>
<p>
<strong>Don't use these services?</strong>
<%= link_to "Sign up", signup_path %> or
<%= link_to "sign in", login_path %> with a password.
</p>
<% end %>
1 change: 0 additions & 1 deletion app/views/games/new.html.erb
Expand Up @@ -34,5 +34,4 @@
<p><%= f.submit %></p>
<% end %>


<p><%= link_to "Back to List", games_path %></p>
2 changes: 2 additions & 0 deletions app/views/layouts/application.html.erb
Expand Up @@ -8,6 +8,7 @@
<%= yield(:head) %>
</head>
<body>
<a href="/" id="logo"><img src="/images/layout/logo.png" width="282" height="112" alt="Go vs Go" /></a>
<ul id="nav">
<li class="banner blue"><%= link_to "Start a Game" %></li>
<li class="gap"></li>
Expand All @@ -18,6 +19,7 @@
<li class="banner brown"><%= link_to "Log Out" %></li>
<div class="clear">
</ul>
<div class="clear"></div>
<div id="container">
<div id="user_nav">
<% if logged_in? %>
Expand Down
5 changes: 5 additions & 0 deletions config/initializers/omiauth.rb
@@ -0,0 +1,5 @@
require 'openid/store/filesystem'
Rails.application.config.middleware.use OmniAuth::Builder do
provider :twitter, PRIVATE_CONFIG["twitter_key"], PRIVATE_CONFIG["twitter_secret"]
provider :open_id, OpenID::Store::Filesystem.new('/tmp')
end
2 changes: 2 additions & 0 deletions config/routes.rb
@@ -1,8 +1,10 @@
Govsgo::Application.routes.draw do
match '/auth/:provider/callback' => 'authentications#create'
match 'user/edit' => 'users#edit', :as => :edit_current_user
match 'signup' => 'users#new', :as => :signup
match 'logout' => 'sessions#destroy', :as => :logout
match 'login' => 'sessions#new', :as => :login
resources :authentications
resources :sessions
resources :users
resources :games do
Expand Down
14 changes: 14 additions & 0 deletions db/migrate/20101016203316_create_authentications.rb
@@ -0,0 +1,14 @@
class CreateAuthentications < ActiveRecord::Migration
def self.up
create_table :authentications do |t|
t.integer :user_id
t.string :provider
t.string :uid
t.timestamps
end
end

def self.down
drop_table :authentications
end
end
Binary file added public/images/auth/facebook_128.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/auth/facebook_32.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/auth/facebook_64.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/auth/open_id_128.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/auth/open_id_32.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/auth/open_id_64.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/auth/twitter_128.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/auth/twitter_32.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/auth/twitter_64.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/layout/logo.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
83 changes: 80 additions & 3 deletions public/stylesheets/application.css
Expand Up @@ -114,12 +114,24 @@ a {
font-size: 12px;
}

/*** Logo ***/

#logo {
float: left;
margin-left: 80px;
margin-top: 20px;
}



/*** Navigation ***/

#nav {
list-style: none;
margin: 0;
padding: 0;
height: 100px;
margin-left: 400px;
margin-left: 450px;
}

#nav li {
Expand All @@ -128,7 +140,7 @@ a {

#nav li.gap {
width: 8px;
height: 60px;
height: 65px;
background-color: #12111B;
box-shadow: 7px 7px 8px #000;
-webkit-box-shadow: 7px 7px 8px #000;
Expand All @@ -147,7 +159,7 @@ a {

#nav li a {
display: block;
padding-top: 45px;
padding-top: 50px;
padding-bottom: 12px;
width: 150px;
text-align: center;
Expand Down Expand Up @@ -187,3 +199,68 @@ a {
background: -moz-linear-gradient(center bottom, #7D4C39 0%, #2A131B 100%);
}



/*** Authentications ***/

.authentications {
margin-bottom: 30px;
}

.authentication {
float: left;
background-color: #EEE;
border: solid 1px #999;
padding: 5px 10px;
-moz-border-radius: 8px;
-webkit-border-radius: 8px;
position: relative;
margin-right: 10px;
}

.authentication .remove {
text-decoration: none;
position: absolute;
top: 3px;
right: 3px;
color: #333;
padding: 2px 4px;
font-size: 10px;
}

.authentication .remove:hover {
color: #FFF;
background-color: #777;
-moz-border-radius: 7px;
-webkit-border-radius: 7px;
}

.authentication img {
float: left;
}

.authentication .provider, .authentication .uid {
margin-left: 38px;
margin-right: 20px;
}

.authentication .provider {
font-weight: bold;
}

.authentication .uid {
color: #666;
font-size: 11px;
}

.auth_provider img {
display: block;
}

.auth_provider {
float: left;
text-decoration: none;
margin-right: 20px;
text-align: center;
margin-bottom: 10px;
}

0 comments on commit cc2af52

Please sign in to comment.