Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Omniauth support added and Tractis modified to work together #42

Merged
merged 2 commits into from

3 participants

@bglusman

Tractis isnt yet an omniauth strategy, but that doesnt look too hard and works alongside omniauth as if it were a strategy for now.

Started second strategy, but think github's oauth may be broken at the moment at cloud9 login fails similarly to our failure so thats in separate branch for now.

@voodoorai2000 voodoorai2000 merged commit 407ac2a into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
View
3  Gemfile
@@ -7,7 +7,8 @@ gem "mechanize"
gem "inherited_resources"
gem "dynamic_form"
gem "congress-scrapper"
-
+gem "omniauth"
+
group :development, :test do
gem 'sqlite3-ruby', :require => 'sqlite3'
gem 'rspec-rails'
View
63 Gemfile.lock
@@ -1,6 +1,8 @@
GEM
remote: http://rubygems.org/
specs:
+ XMLCanonicalizer (1.0.1)
+ log4r (>= 1.0.4)
ZenTest (4.5.0)
actionmailer (3.1.1)
actionpack (= 3.1.1)
@@ -58,6 +60,10 @@ GEM
diff-lcs (1.1.3)
dynamic_form (1.1.4)
erubis (2.7.0)
+ faraday (0.7.5)
+ addressable (~> 2.2.6)
+ multipart-post (~> 1.1.3)
+ rack (>= 1.1.0, < 2)
ffi (1.0.9)
has_scope (0.5.1)
heroku (2.11.0)
@@ -79,6 +85,9 @@ GEM
addressable (~> 2.2.6)
linecache19 (0.5.12)
ruby_core_source (>= 0.1.4)
+ log4r (1.1.9)
+ macaddr (1.4.0)
+ systemu (~> 2.2.0)
mail (2.3.0)
i18n (>= 0.4.0)
mime-types (~> 1.16)
@@ -90,16 +99,62 @@ GEM
webrobots (~> 0.0, >= 0.0.9)
mime-types (1.16)
multi_json (1.0.3)
+ multi_xml (0.4.1)
+ multipart-post (1.1.3)
net-http-digest_auth (1.1.1)
net-http-persistent (1.9)
+ net-ldap (0.2.2)
nokogiri (1.5.0)
+ oa-basic (0.3.2)
+ oa-core (= 0.3.2)
+ rest-client (~> 1.6.0)
+ oa-core (0.3.2)
+ oa-enterprise (0.3.2)
+ XMLCanonicalizer (~> 1.0.1)
+ addressable (~> 2.2.6)
+ net-ldap (~> 0.2.2)
+ nokogiri (~> 1.5.0)
+ oa-core (= 0.3.2)
+ pyu-ruby-sasl (~> 0.0.3.1)
+ rubyntlm (~> 0.1.1)
+ uuid
+ oa-more (0.3.2)
+ multi_json (~> 1.0.0)
+ oa-core (= 0.3.2)
+ rest-client (~> 1.6.0)
+ oa-oauth (0.3.2)
+ faraday (~> 0.7.3)
+ multi_json (~> 1.0.0)
+ multi_xml (~> 0.4.0)
+ oa-core (= 0.3.2)
+ oauth (~> 0.4.0)
+ oauth2 (~> 0.5.0)
+ oa-openid (0.3.2)
+ oa-core (= 0.3.2)
+ rack-openid (~> 1.3.1)
+ ruby-openid-apps-discovery (~> 1.2.0)
+ oauth (0.4.5)
+ oauth2 (0.5.1)
+ faraday (~> 0.7.4)
+ multi_json (~> 1.0.3)
+ omniauth (0.3.2)
+ oa-basic (= 0.3.2)
+ oa-core (= 0.3.2)
+ oa-enterprise (= 0.3.2)
+ oa-more (= 0.3.2)
+ oa-oauth (= 0.3.2)
+ oa-openid (= 0.3.2)
polyglot (0.3.2)
progressbar (0.9.1)
+ pyu-ruby-sasl (0.0.3.3)
rack (1.3.5)
rack-cache (1.1)
rack (>= 0.4)
rack-mount (0.8.3)
rack (>= 1.0.0)
+ rack-openid (1.3.1)
+ rack (>= 1.1.0)
+ ruby-openid (>= 2.1.8)
rack-ssl (1.3.2)
rack
rack-test (0.6.1)
@@ -146,8 +201,12 @@ GEM
columnize (>= 0.3.1)
linecache19 (>= 0.5.11)
ruby-debug-base19 (>= 0.11.19)
+ ruby-openid (2.1.8)
+ ruby-openid-apps-discovery (1.2.0)
+ ruby-openid (>= 2.1.7)
ruby_core_source (0.1.5)
archive-tar-minitar (>= 0.5.2)
+ rubyntlm (0.1.1)
rubyzip (0.9.4)
selenium-webdriver (2.9.1)
childprocess (>= 0.2.1)
@@ -163,6 +222,7 @@ GEM
sqlite3 (>= 1.3.3)
steak (1.1.0)
rspec (>= 1.3)
+ systemu (2.2.0)
term-ansicolor (1.0.7)
thor (0.14.6)
tilt (1.3.3)
@@ -170,6 +230,8 @@ GEM
polyglot
polyglot (>= 0.3.1)
tzinfo (0.3.30)
+ uuid (2.3.4)
+ macaddr (~> 1.0)
webmock (1.7.7)
addressable (~> 2.2, > 2.2.5)
crack (>= 0.1.7)
@@ -192,6 +254,7 @@ DEPENDENCIES
inherited_resources
launchy
mechanize
+ omniauth
progressbar
rails (= 3.1.1)
rspec-rails
View
15 app/controllers/user_sessions_controller.rb
@@ -10,7 +10,8 @@ def new
def authenticate
valid_tractis_identity_verification!(ENV["TRACTIS_API_KEY"], params)
- @current_user = User.find_or_create_by_dni(params["tractis:attribute:dni"]) do |user|
+ @current_user = User.find_or_create_by_uid(params["tractis:attribute:dni"]) do |user|
+ user.provider = "tractis"
user.name = params["tractis:attribute:name"]
end
@@ -18,15 +19,23 @@ def authenticate
redirect_back_or_default root_url
end
- def create
+ def create_fake
name = params[:name].present? ? params[:name] : "Backdoor Mother Fucking Fake User"
@current_user = User.find_or_create_by_name(name) do |user|
- user.dni = "#{rand(99999999)}V"
+ user.provider = "fake"
+ user.uid = name
end
session[:current_user_id] = @current_user.id
redirect_back_or_default root_url
end
+
+ def create
+ auth = request.env["omniauth.auth"]
+ @current_user = User.find_by_provider_and_uid(auth["provider"], auth["uid"]) || User.create_with_omniauth(auth)
+ session[:current_user_id] = @current_user.id
+ redirect_back_or_default root_url
+ end
def destroy
session[:current_user_id] = nil
View
13 app/models/user.rb
@@ -8,7 +8,8 @@ class User < ActiveRecord::Base
after_save :count_votes
- validates :dni, :presence => true
+ validates :provider, :presence => true
+ validates :uid, :presence => true
def has_voted_for?(proposal)
voted_proposals.include?(proposal)
@@ -67,4 +68,12 @@ def is_admin?
admin
end
-end
+ create! do |user|
+ user.provider = auth["provider"]
+ user.uid = auth["uid"]
+ user.name = auth["user_info"]["name"]
+ end
+ end
+
+end
View
9 app/views/user_sessions/new.html.erb
@@ -1,12 +1,15 @@
-<h2><%= t(:dnie_auth_required)%></h2>
+<h2><%= t(:auth_required)%></h2>
<section id="login-section">
+
+ <p><%= link_to "Sign in with Twitter", "/auth/twitter" %></p>
+
<div style="margin-bottom: 10px;">
<%= identity_verification_gateway(t(:identify_with_dnie), ENV["TRACTIS_API_KEY"], :action => 'authenticate') %>
</div>
<% if Rails.env != 'production' %>
- <%= form_tag user_session_path do %>
+ <%= form_tag create_fake_user_session_path do %>
<p><%= t(:try_with_test_id) %></p>
<p>
<%= label_tag t(:fake_name) %>
@@ -15,4 +18,4 @@
<%= submit_tag t(:try_here) %>
<% end %>
<% end %>
-</section>
View
10 config/initializers/omniauth.rb
@@ -0,0 +1,10 @@
+Rails.application.config.middleware.use OmniAuth::Builder do
+ if ENV['TWITTER_CONSUMER_KEY'].blank? or ENV['TWITTER_CONSUMER_SECRET'].blank?
+ warn "*" * 80
+ warn "WARNING: Missing consumer key or secret. First, register an app with Twitter at"
+ warn "https://dev.twitter.com/apps to obtain OAuth credentials. Then, start the server"
+ warn "with the command: TWITTER_CONSUMER_KEY=abc TWITTER_CONSUMER_SECRET=123 rails server"
+ warn "*" * 80
+ end
+ use OmniAuth::Strategies::Twitter, ENV['TWITTER_CONSUMER_KEY'], ENV['TWITTER_CONSUMER_SECRET']
+end
View
2  config/locales/es.yml
@@ -43,7 +43,7 @@
vote_proposal: 'Vota esta propuesta'
explain: "Explica tu opinión (opcional)"
optional_link: "Enlace (opcional)"
- dnie_auth_required: 'Autenticación con DNIe requerida'
+ auth_required: 'Autenticación requerida'
identify_with_dnie: 'Identifícate con tu DNIe'
try_with_test_id: 'o haz tongo creando una identidad falsa...'
fake_name: 'falso nombre'
View
3  config/routes.rb
@@ -17,6 +17,7 @@
resource :user_session do
get 'authenticate'
+ post 'create_fake'
end
resources :users do
@@ -28,6 +29,8 @@
end
end
+ get '/auth/twitter/callback', :to => 'user_sessions#create', :as => 'callback'
+
root :to => "welcome#index"
# The priority is based upon order of creation:
View
8 db/migrate/20111023200908_add_provider_and_uid_to_users.rb
@@ -0,0 +1,8 @@
+class AddProviderAndUidToUsers < ActiveRecord::Migration
+ def change
+ change_table :users do |t|
+ t.string :provider
+ t.string :uid
+ end
+ end
+end
View
4 db/schema.rb
@@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 20110319234436) do
+ActiveRecord::Schema.define(:version => 20111023200908) do
create_table "categories", :force => true do |t|
t.string "name"
@@ -68,6 +68,8 @@
t.boolean "admin", :default => false
t.string "dni"
t.string "name"
+ t.string "provider"
+ t.string "uid"
end
create_table "votes", :force => true do |t|
View
2  spec/acceptance/dni_authentication_spec.rb
@@ -26,7 +26,7 @@
register_as("Bad Ass Mother Fucking New User", "12345678V")
page.should have_content I18n.t(:currently_logged_as, :username => "Bad Ass Mother Fucking New User")
- User.find_by_name_and_dni("Bad Ass Mother Fucking New User", "12345678V").should be
+ User.find_by_name_and_uid("Bad Ass Mother Fucking New User", "12345678V").should be
end
scenario "Invalid authentication" do
View
2  spec/acceptance/spokesmen_spec.rb
@@ -77,7 +77,7 @@
click_link "Fan de Punset"
click_button "Elegir a Fan de Punset como mi portavoz"
- page.should have_content("Autenticación con DNIe requerida")
+ page.should have_content("Autenticación requerida")
page.should_not have_content("Has elegido a tu portavoz.")
login_as @user
View
2  spec/acceptance/support/helpers.rb
@@ -1,7 +1,7 @@
module HelperMethods
def login_as(user)
stub_tractis_request
- get_tractis_callback(user.name, user.dni)
+ get_tractis_callback(user.name, user.uid)
end
def register_as(name, dni)
View
2  spec/acceptance/vote_for_proposals_spec.rb
@@ -77,7 +77,7 @@
visit proposal_path(proposal)
click_button I18n.t(:yes_option)
- page.should have_content I18n.t(:dnie_auth_required)
+ page.should have_content I18n.t(:auth_required)
page.should_not have_css("button", :text => I18n.t(:i_am_sure))
login_as @user
View
5 spec/support/factories.rb
@@ -15,7 +15,8 @@ def create_vote(attrs = {})
end
def create_user(attrs = {})
- attrs[:dni] ||= "#{rand(9999999)}V"
+ attrs[:provider] ||= "test"
+ attrs[:uid] ||= "#{rand(9999999)}V"
attrs[:name] ||= "Mother Fucking Real User"
User.create!(attrs)
end
@@ -30,4 +31,4 @@ def create_proposer(attrs = {})
end
-RSpec.configuration.include Factories
Something went wrong with that request. Please try again.