-
Notifications
You must be signed in to change notification settings - Fork 53
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Restore and support with solidus starter frontend #127
base: master
Are you sure you want to change the base?
Changes from all commits
e4b0de3
1121d48
3c80335
cc4a7a7
91d5cc8
cdab9f2
a0580b7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
/* | ||
*= require spree/frontend | ||
*= require spree/frontend/fontello | ||
*= require_tree . | ||
*/ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,20 @@ | ||
# frozen_string_literal: true | ||
|
||
class Spree::AuthenticationMethod < ApplicationRecord | ||
def self.provider_options | ||
SolidusSocial.configured_providers.map { |provider_name| [provider_name.split("_").first.camelize, provider_name] } | ||
end | ||
|
||
validates :provider, presence: true | ||
class Spree::AuthenticationMethod < ActiveRecord::Base | ||
validates :provider, :api_key, :api_secret, presence: true | ||
|
||
def self.active_authentication_methods? | ||
where(environment: ::Rails.env, active: true).exists? | ||
end | ||
|
||
scope :available_for, lambda { |user| | ||
sc = where(environment: ::Rails.env) | ||
sc = sc.where(['provider NOT IN (?)', user.user_authentications.map(&:provider)]) if user && !user.user_authentications.empty? | ||
sc = sc.where.not(provider: user.user_authentications.pluck(:provider)) if user && !user.user_authentications.empty? | ||
sc | ||
} | ||
|
||
def provider_name | ||
provider = SolidusSocial::OAUTH_PROVIDERS.find { |oauth_provider| oauth_provider[1] == self.provider } | ||
provider ? provider[0].capitalize : nil | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
# frozen_string_literal: true | ||
|
||
class Spree::UserAuthentication < ApplicationRecord | ||
class Spree::UserAuthentication < ActiveRecord::Base | ||
belongs_to :user | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,50 @@ | ||
<div data-hook="admin_social_methods_form_fields" class="row"> | ||
<div class="col-4"> | ||
<div data-hook="environment" class="field"> | ||
<%= f.field_container :environment do %> | ||
<%= label_tag nil, Spree::AuthenticationMethod.human_attribute_name(:environment) %> | ||
<%= collection_select(:authentication_method, :environment, Rails.configuration.database_configuration.keys, :to_s, :titleize, {}, { class: 'select2 fullwidth' }) %> | ||
<% end %> | ||
<div data-hook="admin_social_methods_form_fields"> | ||
<div class="row"> | ||
<div class="col-12 col-lg-6"> | ||
<div data-hook="environment" class="field"> | ||
<%= f.field_container :environment do %> | ||
<%= label_tag nil, Spree::AuthenticationMethod.human_attribute_name(:environment) %> | ||
<%= collection_select(:authentication_method, :environment, Rails.configuration.database_configuration.keys, :to_s, :titleize, {}, { class: 'select2 fullwidth' }) %> | ||
<% end %> | ||
</div> | ||
</div> | ||
|
||
<div class="col-12 col-lg-6"> | ||
<div data-hook="environment" class="field"> | ||
<%= f.field_container :provider do %> | ||
<%= f.label :provider, I18n.t('spree.social_provider') %> | ||
<%= f.select :provider, | ||
SolidusSocial::OAUTH_PROVIDERS.collect { |p| [ p[0], p[1] ] },{}, | ||
{ include_blank: false, class: 'select2' } %> | ||
<% end %> | ||
</div> | ||
</div> | ||
</div> | ||
<div class="col-4"> | ||
<div data-hook="environment" class="field"> | ||
<%= f.field_container :provider do %> | ||
<%= f.label :provider, I18n.t('spree.social_provider') %> | ||
<%= f.select :provider, Spree::AuthenticationMethod.provider_options, {}, { include_blank: false, class: 'select2 fullwidth' } %> | ||
<% end %> | ||
|
||
<div class="row"> | ||
<div class="col-12 col-lg-6"> | ||
<div data-hook="environment" class="form-group"> | ||
<%= f.label :api_key, I18n.t('spree.social_api_key') %> | ||
<%= f.text_field :api_key, class: 'form-control' %> | ||
</div> | ||
</div> | ||
<div class="col-12 col-lg-6"> | ||
<div data-hook="environment" class="form-group"> | ||
<%= f.label :api_secret, I18n.t('spree.social_api_secret') %> | ||
<%= f.text_field :api_secret, class: 'form-control' %> | ||
</div> | ||
</div> | ||
</div> | ||
<div class="col-4"> | ||
<div data-hook="environment" class="field"> | ||
<%= f.field_container :active do %> | ||
<%= f.label :active, I18n.t('spree.active') %><br> | ||
<%= f.radio_button :active, :true %><span style="padding:0 2px;"><%= I18n.t('spree.say_yes') %></span> | ||
<%= f.radio_button :active, :false %><span style="padding:0 2px"><%= I18n.t('spree.say_no') %></span> | ||
<% end %> | ||
|
||
<div class="row"> | ||
<div class="col-12 col-lg-6"> | ||
<div data-hook="environment" class="field"> | ||
<%= f.field_container :active do %> | ||
<%= f.label :active, I18n.t('spree.active') %><br> | ||
<%= f.radio_button :active, :true %><span style="padding:0 2px;"><%= I18n.t('spree.say_yes') %></span> | ||
<%= f.radio_button :active, :false %><span style="padding:0 2px"><%= I18n.t('spree.say_no') %></span> | ||
<% end %> | ||
</div> | ||
</div> | ||
</div> | ||
</div> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<div id="social-signin-links" class="text-center"> | ||
<% if (!spree_current_user || !spree_current_user.user_authentications) && Spree::AuthenticationMethod.active_authentication_methods? %> | ||
<div class="flex items-center my-4"> | ||
<hr class="w-full h-px bg-gray-200 border-0 dark:bg-gray-700"> | ||
<span class="px-3 text-gray-900 font-medium dark:text-white dark:bg-gray-900"><%= I18n.t('spree.or') %></span> | ||
<hr class="w-full h-px bg-gray-200 border-0 dark:bg-gray-700"> | ||
</div> | ||
<% end %> | ||
|
||
<div class="flex flex-col items-center w-full space-y-4"> | ||
<% Spree::AuthenticationMethod.available_for(spree_current_user).each do |method| %> | ||
<% if method.active %> | ||
<%= form_tag(spree.send("spree_user_#{method.provider}_omniauth_authorize_path", r: rand), method: 'post', class: "w-full") do %> | ||
<%= button_tag(type: 'submit', title: t('spree.sign_in_with', provider: method.provider_name), class: "w-full px-7 rounded-full text-body-sm font-bold leading-none uppercase whitespace-nowrap transiton-colors duration-200 border text-white flex items-center justify-between") do %> | ||
<svg class="w-5 h-5 fill-black dark:fill-white"> | ||
<use xlink:href="<%= image_path('remixicon.symbol.svg') %>#ri-<%= method.provider_name.downcase %>-fill"></use> | ||
</svg> | ||
<div class="flex-1 py-3"> | ||
<span class="font-medium text-black dark:text-white text-center"><%= t('spree.sign_in_with', provider: method.provider_name) %></span> | ||
</div> | ||
<div></div> | ||
<% end %> | ||
<% end %> | ||
<% end %> | ||
<% end %> | ||
</div> | ||
</div> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# frozen_string_literal: true | ||
|
||
SolidusSocial::OAUTH_PROVIDERS.each do |provider| | ||
SolidusSocial.init_provider(provider[1]) | ||
end | ||
|
||
OmniAuth.config.logger = Logger.new(STDOUT) | ||
OmniAuth.logger.progname = 'omniauth' | ||
|
||
OmniAuth.config.on_failure = proc do |env| | ||
env['devise.mapping'] = Devise.mappings[Spree.user_class.table_name.singularize.to_sym] | ||
controller_klass = ActiveSupport::Inflector.constantize("Spree::OmniauthCallbacksController") | ||
controller_klass.action(:failure).call(env) | ||
end | ||
|
||
Devise.setup do |config| | ||
config.router_name = :spree | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# frozen_string_literal: true | ||
|
||
class AddDbIndexToUserAuthentications < SolidusSupport::Migration[4.2] | ||
def change | ||
add_index :spree_user_authentications, [:uid, :provider], unique: true | ||
add_index :spree_user_authentications, :user_id | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# frozen_string_literal: true | ||
|
||
class AddForeignKeyToUserAuthenticationsForUserId < SolidusSupport::Migration[4.2] | ||
def change | ||
add_foreign_key :spree_user_authentications, :spree_users, column: :user_id | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# frozen_string_literal: true | ||
|
||
class ChangeUserIdTypeForSpreeUserAuthentications < SolidusSupport::Migration[4.2] | ||
def change | ||
change_column :spree_user_authentications, :user_id, :bigint | ||
end | ||
end |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,20 +7,37 @@ | |
require 'solidus_social/version' | ||
require 'solidus_social/engine' | ||
|
||
|
||
module SolidusSocial | ||
def self.configured_providers | ||
::Spree::SocialConfig.providers.keys.map(&:to_s) | ||
end | ||
OAUTH_PROVIDERS = [ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you explain what's wrong with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hi @kennyadsl Earlier, we used to configure the providers using an initializer file, where we configure provider with credentials, I find it would be more appropriate if we pull the provider and credentials details from the Constant I took, just to maintain the list of provider into the extension itself. |
||
%w(Facebook facebook true), | ||
%w(Twitter twitter2 false), | ||
%w(Github github true), | ||
%w(Google google_oauth2 true) | ||
] | ||
|
||
# Setup all OAuth providers | ||
def self.init_provider(provider) | ||
begin | ||
ActiveRecord::Base.connection_pool.with_connection(&:active?) | ||
rescue | ||
return | ||
end | ||
|
||
def self.init_providers | ||
::Spree::SocialConfig.providers.each do |provider, credentials| | ||
setup_key_for(provider, credentials[:api_key], credentials[:api_secret]) | ||
return unless ActiveRecord::Base.connection.data_source_exists?('spree_authentication_methods') | ||
key, secret = nil | ||
::Spree::AuthenticationMethod.where(environment: ::Rails.env).each do |auth_method| | ||
next unless auth_method.provider == provider | ||
key = auth_method.api_key | ||
secret = auth_method.api_secret | ||
Rails.logger.info("[Solidus Social] Loading #{auth_method.provider.capitalize} as authentication source") | ||
end | ||
setup_key_for(provider.to_sym, key, secret) | ||
end | ||
|
||
def self.setup_key_for(provider, key, secret) | ||
Devise.setup do |config| | ||
config.omniauth provider, key, secret, setup: true | ||
config.omniauth provider, key, secret, setup: true, info_fields: 'email, name' | ||
end | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
module SolidusSupport | ||
class << self | ||
# Currently it checks only legacy frontend support | ||
# enabling this here for starter frontend to load missing routes and controllers | ||
def frontend_available? | ||
true | ||
end | ||
end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you explain this one, please?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @kennyadsl I faced an issue after installing the extension i.e - somehow the sprockets is looking for the file
spree/frontend
to be there when compiling assets, and raised an error with Sprockets::FileNotFound. I have to change this so that it points to an file instead of frontend directory as Sprockets is unable to find.Here is the screenshot:
Let me know if there any better way to handle this.