This repository has been archived by the owner on Dec 12, 2021. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
26 changed files
with
296 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
module AuthenticationsHelper | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" %> | ||
</a> | ||
<a href="/auth/facebook" class="auth_provider"> | ||
<%= image_tag "auth/facebook_128.png", :size => "128x128", :alt => "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 %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,5 +34,4 @@ | |
<p><%= f.submit %></p> | ||
<% end %> | ||
|
||
|
||
<p><%= link_to "Back to List", games_path %></p> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.