adds feature flags for omniauth login buttons/controls

Conflicts:
	app/controllers/users/omniauth_callbacks_controller.rb
	app/views/devise/_omniauth_form.html.erb
This commit is contained in:
kikito
2016-01-25 16:15:02 +01:00
parent 98f99954e7
commit d5eab64568
4 changed files with 47 additions and 16 deletions

View File

@@ -1,15 +1,15 @@
class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController
def twitter
sign_in_with :twitter
sign_in_with :twitter_login, :twitter
end
def facebook
sign_in_with :facebook
sign_in_with :facebook_login, :facebook
end
def google_oauth2
sign_in_with :google_oauth2
sign_in_with :google_login, :google_oauth2
end
def after_sign_in_path_for(resource)
@@ -22,7 +22,9 @@ class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController
private
def sign_in_with(provider)
def sign_in_with(feature, provider)
raise ActionController::RoutingError.new('Not Found') unless Setting["feature.#{feature}"]
auth = env["omniauth.auth"]
identity = Identity.first_or_create_from_oauth(auth)

View File

@@ -1,12 +1,35 @@
<% if current_page?(new_user_session_path) %>
<% if feature?(:twitter_login) || feature?(:facebook_login) || feature?(:google_login) %>
<% if current_page?(new_user_session_path) %>
<% if feature? :twitter_login %>
<%= link_to t("omniauth.twitter.sign_in"), user_omniauth_authorize_path(:twitter), class: "button-twitter button radius expand" %>
<% end %>
<% if feature? :facebook_login %>
<%= link_to t("omniauth.facebook.sign_in"), user_omniauth_authorize_path(:facebook), class: "button-facebook button radius expand" %>
<% end %>
<% if feature? :google_login %>
<%= link_to t("omniauth.google_oauth2.sign_in"), user_omniauth_authorize_path(:google_oauth2), class: "button-google button radius expand" %>
<% end %>
<hr/>
<% elsif current_page?(new_user_registration_path) %>
<% elsif current_page?(new_user_registration_path) %>
<% if feature? :twitter_login %>
<%= link_to t("omniauth.twitter.sign_up"), user_omniauth_authorize_path(:twitter), class: "button-twitter button radius expand" %>
<% end %>
<% if feature? :facebook_login %>
<%= link_to t("omniauth.facebook.sign_up"), user_omniauth_authorize_path(:facebook), class: "button-facebook button radius expand" %>
<% end %>
<% if feature? :google_login %>
<%= link_to t("omniauth.google_oauth2.sign_up"), user_omniauth_authorize_path(:google_oauth2), class: "button-google button radius expand" %>
<p>Al hacer login con una red social, usted está aceptando los términos legales.</p>
<% end %>
<hr/>
<% end %>
<% end %>

View File

@@ -20,6 +20,9 @@ Setting.create(key: 'org_name', value: 'Consul')
Setting.create(key: 'place_name', value: 'City')
Setting.create(key: 'feature.debates', value: "true")
Setting.create(key: 'feature.spending_proposals', value: "true")
Setting.create(key: 'feature.twitter_login', value: "true")
Setting.create(key: 'feature.facebook_login', value: "true")
Setting.create(key: 'feature.google_login', value: "true")
puts "Creating Geozones"
('A'..'Z').each{ |i| Geozone.create(name: "District #{i}") }

View File

@@ -53,3 +53,6 @@ Setting["place_name"] = "Consul-land"
# Feature flags
Setting['feature.debates'] = true
Setting['feature.spending_proposals'] = true
Setting['feature.twitter_login'] = true
Setting['feature.facebook_login'] = true
Setting['feature.google_login'] = true