solidus_social 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3fe49d36ea644340c59c66b5e8506ab57a466f6c
4
- data.tar.gz: d42af370d565407ebdbccbe60d32fbcbef814478
3
+ metadata.gz: f1a51d0589d5c133e7feade204f1e502a9381ddc
4
+ data.tar.gz: 3a1c269db431f9221b2db01cf828dec5614981f2
5
5
  SHA512:
6
- metadata.gz: 836eb284a9553b79eec6a3738a50cb30cb37162dad469fccee63ec153b4b7c888268d8beae8564a47efae281811c0f14f9ebf1f5f72136092eb32655428f4b79
7
- data.tar.gz: 9b458f66b04f4ab4be83f0d4c151f5096cce9ff51790a2b9de95bba362e14e602d3fd392ae817491970ca4a6bd6cc55eb4c9eb30e788a615b566632ccd9e11b1
6
+ metadata.gz: 4bde42eaf3d0cfc966111ab8d0f094827b5d6004b74f37b0cc7d8ee677f20e44c6e579e57ace4a3599bdb23bd460f8b071c14aad6180e2896742d154cddc33c1
7
+ data.tar.gz: 74e0eac9c4637558d86d4bc1891a80712c921f03b9273e861123d06fcb9eba51b73140b0e7cf92063976b253b40c8c2a04cf3068bc97f93baba530a887053878
data/.rubocop.yml CHANGED
@@ -1,8 +1,150 @@
1
- ---
2
- inherit_from: .hound.yml
3
-
4
1
  AllCops:
5
- Exclude:
6
- - spec/dummy/**/*
7
- - bin/*
8
- - Guardfile
2
+ Exclude:
3
+ - spec/dummy/**/*
4
+ - bin/*
5
+ - Guardfile
6
+ - vendor/**/*
7
+
8
+ Style/MutableConstant:
9
+ Enabled: false
10
+
11
+ # Relaxed.Ruby.Style
12
+
13
+ Style/Alias:
14
+ Enabled: false
15
+ StyleGuide: http://relaxed.ruby.style/#stylealias
16
+
17
+ Style/BeginBlock:
18
+ Enabled: false
19
+ StyleGuide: http://relaxed.ruby.style/#stylebeginblock
20
+
21
+ Style/BlockDelimiters:
22
+ Enabled: false
23
+ StyleGuide: http://relaxed.ruby.style/#styleblockdelimiters
24
+
25
+ Style/Documentation:
26
+ Enabled: false
27
+ StyleGuide: http://relaxed.ruby.style/#styledocumentation
28
+
29
+ Style/DotPosition:
30
+ Enabled: false
31
+ StyleGuide: http://relaxed.ruby.style/#styledotposition
32
+
33
+ Style/DoubleNegation:
34
+ Enabled: false
35
+ StyleGuide: http://relaxed.ruby.style/#styledoublenegation
36
+
37
+ Style/EndBlock:
38
+ Enabled: false
39
+ StyleGuide: http://relaxed.ruby.style/#styleendblock
40
+
41
+ Style/FormatString:
42
+ Enabled: false
43
+ StyleGuide: http://relaxed.ruby.style/#styleformatstring
44
+
45
+ Style/IfUnlessModifier:
46
+ Enabled: false
47
+ StyleGuide: http://relaxed.ruby.style/#styleifunlessmodifier
48
+
49
+ Style/Lambda:
50
+ Enabled: false
51
+ StyleGuide: http://relaxed.ruby.style/#stylelambda
52
+
53
+ Style/ModuleFunction:
54
+ Enabled: false
55
+ StyleGuide: http://relaxed.ruby.style/#stylemodulefunction
56
+
57
+ Style/MultilineBlockChain:
58
+ Enabled: false
59
+ StyleGuide: http://relaxed.ruby.style/#stylemultilineblockchain
60
+
61
+ Style/NegatedIf:
62
+ Enabled: false
63
+ StyleGuide: http://relaxed.ruby.style/#stylenegatedif
64
+
65
+ Style/NegatedWhile:
66
+ Enabled: false
67
+ StyleGuide: http://relaxed.ruby.style/#stylenegatedwhile
68
+
69
+ Style/ParallelAssignment:
70
+ Enabled: false
71
+ StyleGuide: http://relaxed.ruby.style/#styleparallelassignment
72
+
73
+ Style/PercentLiteralDelimiters:
74
+ Enabled: false
75
+ StyleGuide: http://relaxed.ruby.style/#stylepercentliteraldelimiters
76
+
77
+ Style/PerlBackrefs:
78
+ Enabled: false
79
+ StyleGuide: http://relaxed.ruby.style/#styleperlbackrefs
80
+
81
+ Style/Semicolon:
82
+ Enabled: false
83
+ StyleGuide: http://relaxed.ruby.style/#stylesemicolon
84
+
85
+ Style/SignalException:
86
+ Enabled: false
87
+ StyleGuide: http://relaxed.ruby.style/#stylesignalexception
88
+
89
+ Style/SingleLineBlockParams:
90
+ Enabled: false
91
+ StyleGuide: http://relaxed.ruby.style/#stylesinglelineblockparams
92
+
93
+ Style/SingleLineMethods:
94
+ Enabled: false
95
+ StyleGuide: http://relaxed.ruby.style/#stylesinglelinemethods
96
+
97
+ Style/SpaceBeforeBlockBraces:
98
+ Enabled: false
99
+ StyleGuide: http://relaxed.ruby.style/#stylespacebeforeblockbraces
100
+
101
+ Style/SpaceInsideParens:
102
+ Enabled: false
103
+ StyleGuide: http://relaxed.ruby.style/#stylespaceinsideparens
104
+
105
+ Style/SpecialGlobalVars:
106
+ Enabled: false
107
+ StyleGuide: http://relaxed.ruby.style/#stylespecialglobalvars
108
+
109
+ Style/StringLiterals:
110
+ Enabled: false
111
+ StyleGuide: http://relaxed.ruby.style/#stylestringliterals
112
+
113
+ Style/WhileUntilModifier:
114
+ Enabled: false
115
+ StyleGuide: http://relaxed.ruby.style/#stylewhileuntilmodifier
116
+
117
+ Lint/AmbiguousRegexpLiteral:
118
+ Enabled: false
119
+ StyleGuide: http://relaxed.ruby.style/#lintambiguousregexpliteral
120
+
121
+ Lint/AssignmentInCondition:
122
+ Enabled: false
123
+ StyleGuide: http://relaxed.ruby.style/#lintassignmentincondition
124
+
125
+ Metrics/AbcSize:
126
+ Enabled: false
127
+
128
+ Metrics/BlockNesting:
129
+ Enabled: false
130
+
131
+ Metrics/ClassLength:
132
+ Enabled: false
133
+
134
+ Metrics/ModuleLength:
135
+ Enabled: false
136
+
137
+ Metrics/CyclomaticComplexity:
138
+ Enabled: false
139
+
140
+ Metrics/LineLength:
141
+ Enabled: false
142
+
143
+ Metrics/MethodLength:
144
+ Enabled: false
145
+
146
+ Metrics/ParameterLists:
147
+ Enabled: false
148
+
149
+ Metrics/PerceivedComplexity:
150
+ Enabled: false
data/.travis.yml CHANGED
@@ -1,19 +1,21 @@
1
- ---
1
+ sudo: false
2
+ cache: bundler
2
3
  language: ruby
3
4
  rvm:
4
- - 2.1
5
- - 2.2
6
- - '2.3.0'
5
+ - 2.3.1
7
6
  env:
8
7
  matrix:
9
- - SOLIDUS_BRANCH=master
10
- - SOLIDUS_BRANCH=v1.2
11
- - SOLIDUS_BRANCH=v1.1
12
- - SOLIDUS_BRANCH=v1.0
13
- sudo: false
14
- before_script:
15
- - sh -e /etc/init.d/xvfb start
16
- - export DISPLAY=:99.0
17
- - bundle exec rake test_app
18
- script:
19
- - bundle exec rspec spec
8
+ - SOLIDUS_BRANCH=v1.0 DB=postgres
9
+ - SOLIDUS_BRANCH=v1.1 DB=postgres
10
+ - SOLIDUS_BRANCH=v1.2 DB=postgres
11
+ - SOLIDUS_BRANCH=v1.3 DB=postgres
12
+ - SOLIDUS_BRANCH=v1.4 DB=postgres
13
+ - SOLIDUS_BRANCH=v2.0 DB=postgres
14
+ - SOLIDUS_BRANCH=master DB=postgres
15
+ - SOLIDUS_BRANCH=v1.0 DB=mysql
16
+ - SOLIDUS_BRANCH=v1.1 DB=mysql
17
+ - SOLIDUS_BRANCH=v1.2 DB=mysql
18
+ - SOLIDUS_BRANCH=v1.3 DB=mysql
19
+ - SOLIDUS_BRANCH=v1.4 DB=mysql
20
+ - SOLIDUS_BRANCH=v2.0 DB=mysql
21
+ - SOLIDUS_BRANCH=master DB=mysql
data/Gemfile CHANGED
@@ -1,7 +1,17 @@
1
- source 'https://rubygems.org'
1
+ source "https://rubygems.org"
2
2
 
3
3
  branch = ENV.fetch('SOLIDUS_BRANCH', 'master')
4
- gem 'solidus', github: 'solidusio/solidus', branch: branch
5
- gem 'solidus_auth_devise'
4
+ gem "solidus", github: "solidusio/solidus", branch: branch
5
+
6
+ if branch == 'master' || branch >= "v2.0"
7
+ gem "rails-controller-testing", group: :test
8
+ end
9
+
10
+ gem 'pg'
11
+ gem 'mysql2'
12
+
13
+ group :development, :test do
14
+ gem "pry-rails"
15
+ end
6
16
 
7
17
  gemspec
data/README.md CHANGED
@@ -3,49 +3,52 @@
3
3
  [![Build Status](https://travis-ci.org/solidusio-contrib/solidus_social.svg?branch=master)](https://travis-ci.org/solidusio-contrib/solidus_social)
4
4
  [![Code Climate](https://codeclimate.com/github/solidusio-contrib/solidus_social/badges/gpa.svg)](https://codeclimate.com/github/solidusio-contrib/solidus_social)
5
5
 
6
- Core for all social media related functionality for Solidus.
7
- The Solidus Social gem handles authorization, account creation and association through social media sources such as Twitter and Facebook.
8
- This gem is beta at best and should be treated as such.
9
- Features and code base will change rapidly as this is under active development.
10
- Use with caution.
6
+ Social login support for Solidus. Solidus Social handles authorization, account
7
+ creation and association through third-party services. Currently Twitter,
8
+ Facebook, Github, Google OAuth2, and Amazon are available out of the box.
11
9
 
12
- ---
13
-
14
- ## Setup for Production
10
+ ## Installation
15
11
 
16
12
  Add this extension to your `Gemfile`:
13
+
17
14
  ```ruby
18
15
  gem 'solidus_social'
19
16
  ```
20
17
 
21
18
  Then run:
19
+
22
20
  ```sh
23
21
  $ bundle && bundle exec rails g solidus_social:install
24
22
  $ bundle exec rake db:migrate
25
23
  ```
26
24
 
27
- Preference(optional): By default url will be '/users/auth/:provider'. If you wish to modify the url to: '/member/auth/:provider', '/profile/auth/:provider', or '/auth/:provider' then you can do this accordingly in your **config/initializers/spree.rb** file as described below -
25
+ Optional: By default the login path will be '/users/auth/:provider'. If you
26
+ want something else, configure it in `config/initializers/solidus_social.rb`.
28
27
 
29
28
  ```ruby
30
- Spree::SocialConfig[:path_prefix] = 'member' # for /member/auth/:provider
29
+ Spree::SocialConfig[:path_prefix] = 'member' # for /member/auth/:provider
31
30
  Spree::SocialConfig[:path_prefix] = 'profile' # for /profile/auth/:provider
32
- Spree::SocialConfig[:path_prefix] = '' # for /auth/:provider
31
+ Spree::SocialConfig[:path_prefix] = '' # for /auth/:provider
33
32
  ```
34
33
 
35
- ---
36
-
37
- ## Spree Setup to Utilize OAuth Sources
34
+ ## Using OAuth Sources
38
35
 
39
36
  Login as an admin user and navigate to Configuration > Social Authentication Methods
40
37
 
41
- Click on the New Authentication Method button to enter the key obtained from their respective source, (See below for instructions on setting up the various providers).
38
+ Click "New Authentication Method" and enter your API key for the service. (See
39
+ below for instructions on setting up the different providers.)
42
40
 
43
- Multiple key entries can now be entered based on the rails environment. This allows for portability and the lack of need to check in your key to your repository. You also have the ability to enable and disable sources. These setting will be reflected on the client UI as well.
41
+ Multiple key entries can now be entered based on the Rails environment. This
42
+ allows for portability and the lack of need to check in your key to your
43
+ repository. You also have the ability to enable and disable sources. These
44
+ setting will be reflected on the client UI as well.
44
45
 
45
- Alternatively you can ship keys as environment variables and create these Authentication Method records on application boot via an initializer. Below is an example for facebook.
46
+ If you store your configuration/credentials in environment variables, you can
47
+ create Authentication Methods on application boot via an initializer if they
48
+ don't already exist.
46
49
 
47
50
  ```ruby
48
- # Ensure our environment is bootstrapped with a facebook connect app
51
+ # Ensure our environment is bootstrapped with a Facebook Connect app
49
52
  if ActiveRecord::Base.connection.table_exists? 'spree_authentication_methods'
50
53
  Spree::AuthenticationMethod.where(environment: Rails.env, provider: 'facebook').first_or_create do |auth_method|
51
54
  auth_method.api_key = ENV['FACEBOOK_APP_ID']
@@ -57,82 +60,105 @@ end
57
60
 
58
61
  **You MUST restart your application after configuring or updating an authentication method.**
59
62
 
60
- ---
61
-
62
- ## Setup the Applications at the Respective Sources
63
+ ## Registering Your Application
63
64
 
64
- OAuth Applications @ Facebook, Twitter and / or Github are supported out of the box but you will need to setup applications are each respective site as follows for public use and for development.
65
+ Facebook, Twitter, Github, Google OAuth2, and Amazon are supported out of the
66
+ box but, you will need to register your application with each of the sites you
67
+ want to use.
65
68
 
66
- > All URLs must be in the form of domain.tld you may add a port as well for development
69
+ When setting up development applications, keep in mind that most services do
70
+ not support `localhost` for your URL/domain. You will need to us a regular
71
+ domain (i.e. `domain.tld`, `hostname.local`) or an IP addresses (`127.0.0.1`).
72
+ Make sure you specifity the right IP address.
67
73
 
68
74
  ### Facebook
69
75
 
70
76
  [Facebook / Developers / Apps][2]
71
77
 
72
- 1. Name the app what you will and agree to the terms.
73
- 2. Fill out the capcha
74
- 3. Under the Web Site tab
75
- 4. Site URL: http://your_computer.local:3000 for development / http://your-site.com for production
76
- 5. Site domain: your-computer.local / your-site.com respectively
78
+ 1. Name the app and agree to the terms.
79
+ 2. Fill out the capcha.
80
+ 3. Under the "Web Site" tab enter:
81
+ - Site URL: `http://yourhostname.local:3000` for development and
82
+ `http://your-site.com` for production
83
+ - Site domain: `yourhostname.local` and `your-site.com` respectively
77
84
 
78
85
  ### Twitter
79
86
 
80
87
  [Twitter / Application Management / Create an application][3]
81
88
 
82
- 1. Name and Description must be filled in with something
83
- 2. Application Website: http://your_computer.local:3000 for development / http://your-site.com for production
84
- 3. Application Type: Browser
85
- 4. Callback URL: http://your_computer.local:3000 for development / http://your-site.com for production
86
- 5. Default Access Type: Read & Write
87
- 6. Save Application
89
+ 1. Fill in the name and description.
90
+ 2. Fill in the rest of the details:
91
+ - Application Website: `http://yourhostname.local:3000` for development and
92
+ `http://your-site.com` for production
93
+ - Application Type: "Browser"
94
+ - Callback URL: `http://yourhostname.local:3000 for development and
95
+ `http://your-site.com` for production
96
+ - Default Access Type: "Read & Write"
97
+ 6. Save the application.
88
98
 
89
99
  ### Github
90
100
 
91
101
  [Github / Applications / Register a new OAuth application][4]
92
102
 
93
- 1. Name The Application
94
- 2. Main URL: http://your_computer.local:3000 for development / http://your-site.com for production
95
- 3. Callback URL: http://your_computer.local:3000 for development / http://your-site.com for production
96
- 4. Click Create
97
-
98
- > This does not seem to be a listed Github item right now. To View and / or edit your applications goto [http://github.com/account/applications](http://github.com/account/applications)
103
+ 1. Name the application.
104
+ 2. Fill in the details
105
+ - Main URL: `http://yourhostname.local:3000` for development and
106
+ `http://your-site.com` for production
107
+ - Callback URL: `http://yourhostname.local:3000` for development and
108
+ `http://your-site.com` for production
109
+ 4. Click Create.
99
110
 
100
111
  ### Amazon
101
112
 
102
113
  [Amazon / App Console / Register a new OAuth application][10]
103
114
 
104
- 1. Register New Application
105
- 2. Name the Application, provide description and URL for Privacy Policy
106
- 3. Click Save
107
- 4. Add Your site under Web Settings > Allowed Return URLs (example: http://localhost:3000/users/auth/amazon/callback)
115
+ 1. Register New Application.
116
+ 2. Name the Application, provide description and URL for Privacy Policy.
117
+ 3. Click Save.
118
+ 4. Add Your site under Web Settings > Allowed Return URLs (example:
119
+ `http://localhost:3000/users/auth/amazon/callback`)
108
120
 
109
121
  > The app console is available at [https://login.amazon.com/manageApps](https://login.amazon.com/manageApps)
110
122
 
111
- ### Other OAuth sources that are currently supported
123
+ ### Google OAuth2
112
124
 
113
- * Google (OAuth)
125
+ _TODO: Write instructions._
114
126
 
115
- ## Adding other OAuth sources
127
+ ### Other OAuth Providers
116
128
 
117
- It is easy to add any OAuth source, given there is an OmniAuth strategy gem for it (and if not, you can easily [write one by yourself](https://github.com/intridea/omniauth/wiki/Strategy-Contribution-Guide). For instance, if you want to add authorization via LinkedIn, the steps will be:
129
+ Other OAuth providers are supported, given that there is an [OmniAuth
130
+ strategy][12] for them. (If there isn't, you can [write one][13].)
118
131
 
119
- 1. Add `gem "omniauth-linkedin"` to your Gemfile, run `bundle install`.
120
- 2. In an initializer file, e.g. `config/initializers/devise.rb`, add and init a new provider for SolidusSocial:
132
+ #### LinkedIn Example
121
133
 
122
- SolidusSocial::OAUTH_PROVIDERS << ['LinkedIn', 'linkedin']
123
- SolidusSocial.init_provider('linkedin')
134
+ 1. Add `gem "omniauth-linkedin"` to your Gemfile and run `bundle install`.
135
+ 2. In `config/initializers/solidus_social.rb` add and initialize a new provider
136
+ for SolidusSocial:
124
137
 
138
+ ```ruby
139
+ SolidusSocial::OAUTH_PROVIDERS << ['LinkedIn', 'linkedin']
140
+ SolidusSocial.init_provider('linkedin')
141
+ ```
125
142
  3. Activate your provider as usual (via initializer or admin interface).
126
- 4. Override `spree/users/social` view to render OAuth links in preferred way for a new one to be displayed. Or alternatively, include to your CSS a definition for `.icon-spree-linkedin-circled` and an embedded icon font for LinkedIn from [fontello.com](http://fontello.com/) (the way existing icons for Facebook, Twitter, etc are implemented). You can also override CSS classes for other providers, `.icon-spree-<provider>-circled`, to use different font icons or classic background images, without having to override views.
143
+ 4. Do **one** of the following:
144
+
145
+ - Override the `spree/users/social` view to render OAuth links to display
146
+ your LinkedIn link.
147
+ - Include in your CSS a definition for `.icon-spree-linkedin-circled` and an
148
+ embedded icon font for LinkedIn from [Fontello][14] (the way existing
149
+ icons for Facebook, Twitter, etc are implemented). You can also override
150
+ CSS classes for other providers, `.icon-spree-<provider>-circled`, to use
151
+ different font icons or classic background images, without having to
152
+ override views.
127
153
 
128
- ---
154
+ ## Documentation
155
+
156
+ API documentation is available [on RubyDoc.info][15].
129
157
 
130
158
  ## Contributing
131
159
 
132
160
  See corresponding [guidelines][11].
133
161
 
134
- ---
135
-
136
162
  Copyright (c) 2014 [John Dyer][7] and [contributors][8], released under the [New BSD License][9]
137
163
 
138
164
  [1]: https://github.com/spree/spree
@@ -146,3 +172,7 @@ Copyright (c) 2014 [John Dyer][7] and [contributors][8], released under the [New
146
172
  [9]: https://github.com/solidusio-contrib/solidus_social/blob/master/LICENSE.md
147
173
  [10]: https://login.amazon.com/manageApps
148
174
  [11]: https://github.com/solidusio-contrib/solidus_social/blob/master/CONTRIBUTING.md
175
+ [12]: https://github.com/intridea/omniauth/wiki/List-of-Strategies
176
+ [13]: https://github.com/intridea/omniauth/wiki/Strategy-Contribution-Guide
177
+ [14]: http://fontello.com/
178
+ [15]: http://www.rubydoc.info/github/solidusio-contrib/solidus_social/
data/Rakefile CHANGED
@@ -6,7 +6,13 @@ require 'spree/testing_support/common_rake'
6
6
 
7
7
  RSpec::Core::RakeTask.new
8
8
 
9
- task default: :spec
9
+ task :default do
10
+ if Dir["spec/dummy"].empty?
11
+ Rake::Task[:test_app].invoke
12
+ Dir.chdir("../../")
13
+ end
14
+ Rake::Task[:spec].invoke
15
+ end
10
16
 
11
17
  desc 'Generates a dummy app for testing'
12
18
  task :test_app do
@@ -4,47 +4,11 @@ class Spree::OmniauthCallbacksController < Devise::OmniauthCallbacksController
4
4
  include Spree::Core::ControllerHelpers::Auth
5
5
  include Spree::Core::ControllerHelpers::Store
6
6
 
7
- def self.provides_callback_for(*providers)
8
- providers.each do |provider|
9
- class_eval <<-FUNCTION_DEFS, __FILE__, __LINE__ + 1
10
- def #{provider}
11
- if request.env['omniauth.error'].present?
12
- flash[:error] = I18n.t('devise.omniauth_callbacks.failure', kind: auth_hash['provider'], reason: Spree.t(:user_was_not_valid))
13
- redirect_back_or_default(root_url)
14
- return
15
- end
16
-
17
- authentication = Spree::UserAuthentication.find_by_provider_and_uid(auth_hash['provider'], auth_hash['uid'])
18
-
19
- if authentication.present? and authentication.try(:user).present?
20
- flash[:notice] = I18n.t('devise.omniauth_callbacks.success', kind: auth_hash['provider'])
21
- sign_in_and_redirect :spree_user, authentication.user
22
- elsif spree_current_user
23
- spree_current_user.apply_omniauth(auth_hash)
24
- spree_current_user.save!
25
- flash[:notice] = I18n.t('devise.sessions.signed_in')
26
- redirect_back_or_default(account_url)
27
- else
28
- user = Spree::User.find_by_email(auth_hash['info']['email']) || Spree::User.new
29
- user.apply_omniauth(auth_hash)
30
- if user.save
31
- flash[:notice] = I18n.t('devise.omniauth_callbacks.success', kind: auth_hash['provider'])
32
- sign_in_and_redirect :spree_user, user
33
- else
34
- session[:omniauth] = auth_hash.except('extra')
35
- flash[:notice] = Spree.t(:one_more_step, kind: auth_hash['provider'].capitalize)
36
- redirect_to new_spree_user_registration_url
37
- return
38
- end
39
- end
40
-
41
- if current_order
42
- user = spree_current_user || authentication.user
43
- current_order.associate_user!(user)
44
- session[:guest_token] = nil
45
- end
46
- end
47
- FUNCTION_DEFS
7
+ class << self
8
+ def provides_callback_for(*providers)
9
+ providers.each do |provider|
10
+ define_method(provider) { omniauth_callback }
11
+ end
48
12
  end
49
13
  end
50
14
 
@@ -52,6 +16,44 @@ class Spree::OmniauthCallbacksController < Devise::OmniauthCallbacksController
52
16
  provides_callback_for provider[1].to_sym
53
17
  end
54
18
 
19
+ def omniauth_callback
20
+ if request.env['omniauth.error'].present?
21
+ flash[:error] = I18n.t('devise.omniauth_callbacks.failure', kind: auth_hash['provider'], reason: Spree.t(:user_was_not_valid))
22
+ redirect_back_or_default(root_url)
23
+ return
24
+ end
25
+
26
+ authentication = Spree::UserAuthentication.find_by_provider_and_uid(auth_hash['provider'], auth_hash['uid'])
27
+
28
+ if authentication.present? and authentication.try(:user).present?
29
+ flash[:notice] = I18n.t('devise.omniauth_callbacks.success', kind: auth_hash['provider'])
30
+ sign_in_and_redirect :spree_user, authentication.user
31
+ elsif spree_current_user
32
+ spree_current_user.apply_omniauth(auth_hash)
33
+ spree_current_user.save!
34
+ flash[:notice] = I18n.t('devise.sessions.signed_in')
35
+ redirect_back_or_default(account_url)
36
+ else
37
+ user = Spree::User.find_by_email(auth_hash['info']['email']) || Spree::User.new
38
+ user.apply_omniauth(auth_hash)
39
+ if user.save
40
+ flash[:notice] = I18n.t('devise.omniauth_callbacks.success', kind: auth_hash['provider'])
41
+ sign_in_and_redirect :spree_user, user
42
+ else
43
+ session[:omniauth] = auth_hash.except('extra')
44
+ flash[:notice] = Spree.t(:one_more_step, kind: auth_hash['provider'].capitalize)
45
+ redirect_to new_spree_user_registration_url
46
+ return
47
+ end
48
+ end
49
+
50
+ if current_order
51
+ user = spree_current_user || authentication.user
52
+ current_order.associate_user!(user)
53
+ session[:guest_token] = nil
54
+ end
55
+ end
56
+
55
57
  def failure
56
58
  set_flash_message :alert, :failure, kind: failed_strategy.name.to_s.humanize, reason: failure_message
57
59
  redirect_to spree.login_path
@@ -2,10 +2,10 @@
2
2
  <% if (!spree_current_user || !spree_current_user.user_authentications) && Spree::AuthenticationMethod.active_authentication_methods? %>
3
3
  <h2><%= Spree.t(:sign_in_through_one_of_these_services) %></h2>
4
4
  <% end %>
5
-
6
- <% Spree::AuthenticationMethod.available_for(@spree_user).each do |method| %>
5
+
6
+ <% Spree::AuthenticationMethod.available_for(spree_current_user).each do |method| %>
7
7
  <%= link_to(content_tag(:i, '', class: "icon-spree-#{method.provider.to_url}-circled"),
8
- spree.spree_user_omniauth_authorize_url(provider: method.provider),
8
+ spree.send("spree_user_#{method.provider}_omniauth_authorize_path"),
9
9
  title: Spree.t(:sign_in_with, provider: method.provider)) if method.active %>
10
10
  <% end %>
11
11
  </div>
@@ -1,28 +1,30 @@
1
1
  <% if Spree::AuthenticationMethod.active_authentication_methods? %>
2
- <% @body_id = 'login' %>
3
- <div id="existing-customer">
4
- <% if spree_current_user.user_authentications %>
5
- <% unless spree_current_user.user_authentications.empty? %>
6
- <p><strong><%= Spree.t(:you_have_signed_in_with_these_services) %>:</strong></p>
7
- <div class="authentications">
8
- <% for user_authentication in spree_current_user.user_authentications %>
9
- <div class="authentication">
10
- <div class="provider columns two">
11
- <%= content_tag(:i, '', class: "icon-spree-#{user_authentication.provider.to_url}-circled columns") %>
12
- <%= user_authentication.provider %>
2
+ <% @body_id = 'login' %>
3
+ <div id="existing-customer">
4
+ <% if spree_current_user.user_authentications %>
5
+ <% unless spree_current_user.user_authentications.empty? %>
6
+ <p><strong><%= Spree.t(:you_have_signed_in_with_these_services) %>:</strong></p>
7
+ <div class="authentications">
8
+ <% for user_authentication in spree_current_user.user_authentications %>
9
+ <div class="authentication">
10
+ <div class="provider columns two">
11
+ <%= content_tag(:i, '', class: "icon-spree-#{user_authentication.provider.to_url}-circled columns") %>
12
+ <%= user_authentication.provider %>
13
+ </div>
14
+ <div class="uid columns two"><%= user_authentication.uid %></div>
15
+ <%= link_to 'X', user_authentication, data: { confirm: "#{Spree.t(:remove_authentication_option_confirmation)}" }, method: :delete, class: 'remove' %>
13
16
  </div>
14
- <div class="uid columns two"><%= user_authentication.uid %></div>
15
- <%= link_to 'X', user_authentication, data: { confirm: "#{Spree.t(:remove_authentication_option_confirmation)}" }, method: :delete, class: 'remove' %>
16
- </div>
17
- <% end %>
18
- <div class="clear"></div>
19
- </div>
17
+ <% end %>
18
+ <div class="clear"></div>
19
+ </div>
20
+ <% end %>
20
21
  <% end %>
22
+
23
+ <% if Spree::AuthenticationMethod.available_for(spree_current_user).present? %>
24
+ <%= content_tag(:p, content_tag(:strong, Spree.t(:add_another_service))) %>
25
+ <%= render 'spree/shared/social' %>
26
+ <% end %>
27
+ </div>
21
28
 
22
- <% end %>
23
- <%= content_tag(:p, content_tag(:strong, Spree.t(:add_another_service))) if Spree::AuthenticationMethod.available_for(spree_current_user).exists? %>
24
- <%= render 'spree/shared/social' %>
25
- </div>
26
-
27
- <div class="clear"></div>
29
+ <div class="clear"></div>
28
30
  <% end %>
@@ -4,7 +4,7 @@ module SolidusSocial
4
4
  class_option :auto_run_migrations, type: :boolean, default: false
5
5
 
6
6
  def add_stylesheets
7
- inject_into_file 'vendor/assets/stylesheets/spree/frontend/all.css', " *= require spree/frontend/solidus_social\n", before: /\*\//, verbose: true
7
+ inject_into_file 'vendor/assets/stylesheets/spree/frontend/all.css', " *= require spree/frontend/solidus_social\n", before: %r(\*/), verbose: true
8
8
  end
9
9
 
10
10
  def add_migrations
@@ -12,7 +12,7 @@ module SolidusSocial
12
12
  end
13
13
 
14
14
  def run_migrations
15
- run_migrations = options[:auto_run_migrations] || ['', 'y', 'Y'].include?(ask 'Would you like to run the migrations now? [Y/n]')
15
+ run_migrations = options[:auto_run_migrations] || ['', 'y', 'Y'].include?(ask('Would you like to run the migrations now? [Y/n]'))
16
16
  if run_migrations
17
17
  run 'bundle exec rake db:migrate'
18
18
  else
@@ -9,7 +9,7 @@ module SolidusSocial
9
9
 
10
10
  module VERSION
11
11
  MAJOR = 1
12
- MINOR = 0
12
+ MINOR = 1
13
13
  TINY = 0
14
14
  PRE = nil
15
15
 
@@ -21,7 +21,8 @@ Gem::Specification.new do |s|
21
21
  s.require_path = 'lib'
22
22
  s.requirements << 'none'
23
23
 
24
- s.add_runtime_dependency 'solidus_core', ["~> 1.0"]
24
+ s.add_runtime_dependency 'solidus_core', [">= 1.0", "< 3"]
25
+ s.add_runtime_dependency 'solidus_auth_devise'
25
26
  s.add_runtime_dependency 'omniauth'
26
27
  s.add_runtime_dependency 'oa-core'
27
28
  s.add_runtime_dependency 'omniauth-twitter'
@@ -30,18 +31,14 @@ Gem::Specification.new do |s|
30
31
  s.add_runtime_dependency 'omniauth-google-oauth2'
31
32
  s.add_runtime_dependency 'omniauth-amazon'
32
33
 
33
- s.add_development_dependency 'capybara', '~> 2.4.1'
34
- s.add_development_dependency 'database_cleaner', '1.3.0'
35
- s.add_development_dependency 'rspec-rails', '~> 3.1.0'
34
+ s.add_development_dependency 'capybara', '~> 2.4'
35
+ s.add_development_dependency 'database_cleaner', '1.3'
36
+ s.add_development_dependency 'rspec-rails', '~> 3.1'
36
37
  s.add_development_dependency 'factory_girl', '~> 4.4'
37
- s.add_development_dependency 'pry-rails'
38
38
  s.add_development_dependency 'selenium-webdriver', '>= 2.41.0'
39
- s.add_development_dependency 'poltergeist', '~> 1.5.0'
39
+ s.add_development_dependency 'poltergeist', '~> 1.5'
40
40
  s.add_development_dependency 'simplecov', '~> 0.9.0'
41
41
  s.add_development_dependency 'sqlite3', '~> 1.3.10'
42
- s.add_development_dependency 'coffee-rails'
43
- s.add_development_dependency 'sass-rails'
44
- s.add_development_dependency 'guard-rspec'
45
- s.add_development_dependency 'rubocop', '>= 0.24.1'
42
+ s.add_development_dependency 'rubocop', '~> 0.39.0'
46
43
  s.add_development_dependency 'rake', '< 11'
47
44
  end
@@ -5,7 +5,7 @@ RSpec.feature 'Admin Authentication Methods', :js do
5
5
  scenario 'has configuration tab' do
6
6
  visit spree.admin_path
7
7
  click_link 'Settings'
8
- expect(page).to have_text 'SOCIAL AUTHENTICATION METHODS'
8
+ expect(page).to have_text(/Social Authentication Methods/i)
9
9
  end
10
10
  end
11
11
 
@@ -17,10 +17,10 @@ RSpec.feature 'Admin Authentication Methods', :js do
17
17
  end
18
18
 
19
19
  scenario 'can create new' do
20
- expect(page).to have_text 'NO AUTHENTICATION METHODS FOUND, ADD ONE!'
20
+ expect(page).to have_text /NO AUTHENTICATION METHODS FOUND, ADD ONE!/i
21
21
 
22
22
  click_link 'New Authentication Method'
23
- expect(page).to have_text 'BACK TO AUTHENTICATION METHODS LIST'
23
+ expect(page).to have_text /BACK TO AUTHENTICATION METHODS LIST/i
24
24
  select 'Test', from: 'authentication_method[environment]'
25
25
  select2 'Github', from: 'Social Provider'
26
26
  fill_in 'API Key', with: 'KEY123'
@@ -43,6 +43,15 @@ RSpec.feature 'signing in using Omniauth', :js do
43
43
  click_link 'My Account'
44
44
  expect(page).to have_text 'My Account'
45
45
  end
46
+
47
+ scenario "view 'My Account'" do
48
+ visit spree.root_path
49
+ click_link 'Login'
50
+ find('a[title="Login with facebook"]').trigger('click')
51
+ expect(page).to have_text 'You are now signed in with your facebook account.'
52
+ click_link 'My Account'
53
+ expect(page).not_to have_selector 'div#social-signin-links'
54
+ end
46
55
  end
47
56
 
48
57
  context 'twitter' do
@@ -1,7 +1,6 @@
1
1
  require 'database_cleaner'
2
2
 
3
3
  RSpec.configure do |config|
4
-
5
4
  config.before(:suite) do
6
5
  DatabaseCleaner.clean_with :truncation
7
6
  end
metadata CHANGED
@@ -1,29 +1,49 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: solidus_social
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Dyer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-03-10 00:00:00.000000000 Z
11
+ date: 2016-09-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: solidus_core
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '1.0'
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '3'
20
23
  type: :runtime
21
24
  prerelease: false
22
25
  version_requirements: !ruby/object:Gem::Requirement
23
26
  requirements:
24
- - - "~>"
27
+ - - ">="
25
28
  - !ruby/object:Gem::Version
26
29
  version: '1.0'
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '3'
33
+ - !ruby/object:Gem::Dependency
34
+ name: solidus_auth_devise
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ type: :runtime
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
27
47
  - !ruby/object:Gem::Dependency
28
48
  name: omniauth
29
49
  requirement: !ruby/object:Gem::Requirement
@@ -128,42 +148,42 @@ dependencies:
128
148
  requirements:
129
149
  - - "~>"
130
150
  - !ruby/object:Gem::Version
131
- version: 2.4.1
151
+ version: '2.4'
132
152
  type: :development
133
153
  prerelease: false
134
154
  version_requirements: !ruby/object:Gem::Requirement
135
155
  requirements:
136
156
  - - "~>"
137
157
  - !ruby/object:Gem::Version
138
- version: 2.4.1
158
+ version: '2.4'
139
159
  - !ruby/object:Gem::Dependency
140
160
  name: database_cleaner
141
161
  requirement: !ruby/object:Gem::Requirement
142
162
  requirements:
143
163
  - - '='
144
164
  - !ruby/object:Gem::Version
145
- version: 1.3.0
165
+ version: '1.3'
146
166
  type: :development
147
167
  prerelease: false
148
168
  version_requirements: !ruby/object:Gem::Requirement
149
169
  requirements:
150
170
  - - '='
151
171
  - !ruby/object:Gem::Version
152
- version: 1.3.0
172
+ version: '1.3'
153
173
  - !ruby/object:Gem::Dependency
154
174
  name: rspec-rails
155
175
  requirement: !ruby/object:Gem::Requirement
156
176
  requirements:
157
177
  - - "~>"
158
178
  - !ruby/object:Gem::Version
159
- version: 3.1.0
179
+ version: '3.1'
160
180
  type: :development
161
181
  prerelease: false
162
182
  version_requirements: !ruby/object:Gem::Requirement
163
183
  requirements:
164
184
  - - "~>"
165
185
  - !ruby/object:Gem::Version
166
- version: 3.1.0
186
+ version: '3.1'
167
187
  - !ruby/object:Gem::Dependency
168
188
  name: factory_girl
169
189
  requirement: !ruby/object:Gem::Requirement
@@ -178,20 +198,6 @@ dependencies:
178
198
  - - "~>"
179
199
  - !ruby/object:Gem::Version
180
200
  version: '4.4'
181
- - !ruby/object:Gem::Dependency
182
- name: pry-rails
183
- requirement: !ruby/object:Gem::Requirement
184
- requirements:
185
- - - ">="
186
- - !ruby/object:Gem::Version
187
- version: '0'
188
- type: :development
189
- prerelease: false
190
- version_requirements: !ruby/object:Gem::Requirement
191
- requirements:
192
- - - ">="
193
- - !ruby/object:Gem::Version
194
- version: '0'
195
201
  - !ruby/object:Gem::Dependency
196
202
  name: selenium-webdriver
197
203
  requirement: !ruby/object:Gem::Requirement
@@ -212,14 +218,14 @@ dependencies:
212
218
  requirements:
213
219
  - - "~>"
214
220
  - !ruby/object:Gem::Version
215
- version: 1.5.0
221
+ version: '1.5'
216
222
  type: :development
217
223
  prerelease: false
218
224
  version_requirements: !ruby/object:Gem::Requirement
219
225
  requirements:
220
226
  - - "~>"
221
227
  - !ruby/object:Gem::Version
222
- version: 1.5.0
228
+ version: '1.5'
223
229
  - !ruby/object:Gem::Dependency
224
230
  name: simplecov
225
231
  requirement: !ruby/object:Gem::Requirement
@@ -248,62 +254,20 @@ dependencies:
248
254
  - - "~>"
249
255
  - !ruby/object:Gem::Version
250
256
  version: 1.3.10
251
- - !ruby/object:Gem::Dependency
252
- name: coffee-rails
253
- requirement: !ruby/object:Gem::Requirement
254
- requirements:
255
- - - ">="
256
- - !ruby/object:Gem::Version
257
- version: '0'
258
- type: :development
259
- prerelease: false
260
- version_requirements: !ruby/object:Gem::Requirement
261
- requirements:
262
- - - ">="
263
- - !ruby/object:Gem::Version
264
- version: '0'
265
- - !ruby/object:Gem::Dependency
266
- name: sass-rails
267
- requirement: !ruby/object:Gem::Requirement
268
- requirements:
269
- - - ">="
270
- - !ruby/object:Gem::Version
271
- version: '0'
272
- type: :development
273
- prerelease: false
274
- version_requirements: !ruby/object:Gem::Requirement
275
- requirements:
276
- - - ">="
277
- - !ruby/object:Gem::Version
278
- version: '0'
279
- - !ruby/object:Gem::Dependency
280
- name: guard-rspec
281
- requirement: !ruby/object:Gem::Requirement
282
- requirements:
283
- - - ">="
284
- - !ruby/object:Gem::Version
285
- version: '0'
286
- type: :development
287
- prerelease: false
288
- version_requirements: !ruby/object:Gem::Requirement
289
- requirements:
290
- - - ">="
291
- - !ruby/object:Gem::Version
292
- version: '0'
293
257
  - !ruby/object:Gem::Dependency
294
258
  name: rubocop
295
259
  requirement: !ruby/object:Gem::Requirement
296
260
  requirements:
297
- - - ">="
261
+ - - "~>"
298
262
  - !ruby/object:Gem::Version
299
- version: 0.24.1
263
+ version: 0.39.0
300
264
  type: :development
301
265
  prerelease: false
302
266
  version_requirements: !ruby/object:Gem::Requirement
303
267
  requirements:
304
- - - ">="
268
+ - - "~>"
305
269
  - !ruby/object:Gem::Version
306
- version: 0.24.1
270
+ version: 0.39.0
307
271
  - !ruby/object:Gem::Dependency
308
272
  name: rake
309
273
  requirement: !ruby/object:Gem::Requirement
@@ -332,7 +296,6 @@ files:
332
296
  - CHANGELOG.md
333
297
  - CONTRIBUTING.md
334
298
  - Gemfile
335
- - Guardfile
336
299
  - LICENSE.md
337
300
  - README.md
338
301
  - Rakefile
@@ -411,7 +374,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
411
374
  requirements:
412
375
  - none
413
376
  rubyforge_project:
414
- rubygems_version: 2.4.5.1
377
+ rubygems_version: 2.5.1
415
378
  signing_key:
416
379
  specification_version: 4
417
380
  summary: Adds social network login services (OAuth) to Spree
data/Guardfile DELETED
@@ -1,10 +0,0 @@
1
- guard 'rspec', cmd: 'bundle exec rspec' do
2
- watch('spec/spec_helper.rb') { 'spec' }
3
- watch('config/routes.rb') { 'spec/controllers' }
4
- watch(%r{^spec/(.+)_spec\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
5
- watch(%r{^app/(.+)_decorator\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
6
- watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
7
- watch(%r{^app/(.*)(\.erb)$}) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
8
- watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
9
- watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb" }
10
- end