empower 0.2.0 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c4c3229553d50515a185e98428ca4b3712db0369
4
- data.tar.gz: 0184e418539e3327d2ccf79a37ff368df57da3e2
3
+ metadata.gz: 5f282ec451bc0207158dc10d4d43bd27cb2d1de8
4
+ data.tar.gz: 5cf9fb2f6d5bd09213e3f7fd597fbc207c276134
5
5
  SHA512:
6
- metadata.gz: 1d711d0e818e0718e9e61946271bbdc7d9c6f7d4e8f80ff88ce5faae51570dfce3cc8d4ebdd039dd203a3e402733d9e16bef0dd4c03bccb30e2dbedae59fff86
7
- data.tar.gz: fccf01a06fe48a48c1bd3b2c5e21a4c09396501524e74eea8d76cf8cbe201890f609983ffa282357a9c5945a63f1c231e9ef7b74826cc35f72f75b58bf3045cc
6
+ metadata.gz: 3e7f7f3de609b231dbbd2a9d5056dedf39b699c65e750a2af7bca2600e14629ae609f1deb370768c61c279eaa3bb01ec0d405bc15f5a95e02ee38f96a01122a7
7
+ data.tar.gz: 48514512ccf088ca78b74a4c99c3d6ae2c822b434a48e9ddd6900de8972c1dbdbdc64462a58822137d2eb42e6d06fe01c7f79066e5b373dc69cd919b0020f26d
@@ -1,41 +1,39 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- empower (0.2.0)
4
+ empower (1.0.0)
5
5
  devise
6
+ omniauth
6
7
  omniauth-facebook
7
- rails (~> 4.1.0)
8
+ omniauth-google-oauth2
9
+ omniauth-twitter
10
+ simple_form
8
11
 
9
12
  GEM
10
13
  remote: https://rubygems.org/
11
14
  specs:
12
- actionmailer (4.1.10)
13
- actionpack (= 4.1.10)
14
- actionview (= 4.1.10)
15
- mail (~> 2.5, >= 2.5.4)
16
- actionpack (4.1.10)
17
- actionview (= 4.1.10)
18
- activesupport (= 4.1.10)
19
- rack (~> 1.5.2)
15
+ actionpack (4.2.1)
16
+ actionview (= 4.2.1)
17
+ activesupport (= 4.2.1)
18
+ rack (~> 1.6)
20
19
  rack-test (~> 0.6.2)
21
- actionview (4.1.10)
22
- activesupport (= 4.1.10)
20
+ rails-dom-testing (~> 1.0, >= 1.0.5)
21
+ rails-html-sanitizer (~> 1.0, >= 1.0.1)
22
+ actionview (4.2.1)
23
+ activesupport (= 4.2.1)
23
24
  builder (~> 3.1)
24
25
  erubis (~> 2.7.0)
25
- activemodel (4.1.10)
26
- activesupport (= 4.1.10)
26
+ rails-dom-testing (~> 1.0, >= 1.0.5)
27
+ rails-html-sanitizer (~> 1.0, >= 1.0.1)
28
+ activemodel (4.2.1)
29
+ activesupport (= 4.2.1)
27
30
  builder (~> 3.1)
28
- activerecord (4.1.10)
29
- activemodel (= 4.1.10)
30
- activesupport (= 4.1.10)
31
- arel (~> 5.0.0)
32
- activesupport (4.1.10)
33
- i18n (~> 0.6, >= 0.6.9)
31
+ activesupport (4.2.1)
32
+ i18n (~> 0.7)
34
33
  json (~> 1.7, >= 1.7.7)
35
34
  minitest (~> 5.1)
36
- thread_safe (~> 0.1)
35
+ thread_safe (~> 0.3, >= 0.3.4)
37
36
  tzinfo (~> 1.1)
38
- arel (5.0.1.20140414130214)
39
37
  bcrypt (3.1.10)
40
38
  builder (3.2.2)
41
39
  devise (3.4.1)
@@ -49,17 +47,19 @@ GEM
49
47
  faraday (0.9.1)
50
48
  multipart-post (>= 1.2, < 3)
51
49
  hashie (3.4.1)
52
- hike (1.2.3)
53
50
  i18n (0.7.0)
54
51
  json (1.8.2)
55
- jwt (1.4.1)
56
- mail (2.6.3)
57
- mime-types (>= 1.16, < 3)
58
- mime-types (2.4.3)
59
- minitest (5.5.1)
52
+ jwt (1.5.0)
53
+ loofah (2.0.2)
54
+ nokogiri (>= 1.5.9)
55
+ mini_portile (0.6.2)
56
+ minitest (5.6.1)
60
57
  multi_json (1.11.0)
61
58
  multi_xml (0.5.5)
62
59
  multipart-post (2.0.0)
60
+ nokogiri (1.6.6.2)
61
+ mini_portile (~> 0.6.0)
62
+ oauth (0.4.7)
63
63
  oauth2 (1.0.0)
64
64
  faraday (>= 0.8, < 0.10)
65
65
  jwt (~> 1.0)
@@ -71,45 +71,43 @@ GEM
71
71
  rack (~> 1.0)
72
72
  omniauth-facebook (2.0.1)
73
73
  omniauth-oauth2 (~> 1.2)
74
- omniauth-oauth2 (1.2.0)
75
- faraday (>= 0.8, < 0.10)
76
- multi_json (~> 1.3)
74
+ omniauth-google-oauth2 (0.2.6)
75
+ omniauth (> 1.0)
76
+ omniauth-oauth2 (~> 1.1)
77
+ omniauth-oauth (1.1.0)
78
+ oauth
79
+ omniauth (~> 1.0)
80
+ omniauth-oauth2 (1.3.0)
77
81
  oauth2 (~> 1.0)
78
82
  omniauth (~> 1.2)
83
+ omniauth-twitter (1.2.0)
84
+ json (~> 1.3)
85
+ omniauth-oauth (~> 1.1)
79
86
  orm_adapter (0.5.0)
80
- rack (1.5.2)
87
+ rack (1.6.1)
81
88
  rack-test (0.6.3)
82
89
  rack (>= 1.0)
83
- rails (4.1.10)
84
- actionmailer (= 4.1.10)
85
- actionpack (= 4.1.10)
86
- actionview (= 4.1.10)
87
- activemodel (= 4.1.10)
88
- activerecord (= 4.1.10)
89
- activesupport (= 4.1.10)
90
- bundler (>= 1.3.0, < 2.0)
91
- railties (= 4.1.10)
92
- sprockets-rails (~> 2.0)
93
- railties (4.1.10)
94
- actionpack (= 4.1.10)
95
- activesupport (= 4.1.10)
90
+ rails-deprecated_sanitizer (1.0.3)
91
+ activesupport (>= 4.2.0.alpha)
92
+ rails-dom-testing (1.0.6)
93
+ activesupport (>= 4.2.0.beta, < 5.0)
94
+ nokogiri (~> 1.6.0)
95
+ rails-deprecated_sanitizer (>= 1.0.1)
96
+ rails-html-sanitizer (1.0.2)
97
+ loofah (~> 2.0)
98
+ railties (4.2.1)
99
+ actionpack (= 4.2.1)
100
+ activesupport (= 4.2.1)
96
101
  rake (>= 0.8.7)
97
102
  thor (>= 0.18.1, < 2.0)
98
103
  rake (10.4.2)
99
- responders (1.1.2)
100
- railties (>= 3.2, < 4.2)
101
- sprockets (2.12.3)
102
- hike (~> 1.2)
103
- multi_json (~> 1.0)
104
- rack (~> 1.0)
105
- tilt (~> 1.1, != 1.3.0)
106
- sprockets-rails (2.2.4)
107
- actionpack (>= 3.0)
108
- activesupport (>= 3.0)
109
- sprockets (>= 2.8, < 4.0)
104
+ responders (2.1.0)
105
+ railties (>= 4.2.0, < 5)
106
+ simple_form (3.1.0)
107
+ actionpack (~> 4.0)
108
+ activemodel (~> 4.0)
110
109
  thor (0.19.1)
111
110
  thread_safe (0.3.5)
112
- tilt (1.4.1)
113
111
  tzinfo (1.2.2)
114
112
  thread_safe (~> 0.1)
115
113
  warden (1.2.3)
data/README.md CHANGED
@@ -6,12 +6,15 @@ In contrast to something flexible, like
6
6
  [OmniAuth](https://github.com/intridea/omniauth), Empower aims to create the
7
7
  solution simply, quickly, and effectively.
8
8
 
9
+ Empower currently supports the following strategies:
10
+
11
+ * [Facebook](https://github.com/mkdynamic/omniauth-facebook)
12
+ * [Google (OAuth2)](https://github.com/zquestz/omniauth-google-oauth2)
13
+ * [Twitter](https://github.com/arunagw/omniauth-twitter)
14
+
9
15
  To make this happen, you need to understand what's required from you prior to
10
16
  using this gem. See below.
11
17
 
12
- > **Note: At this time, there are no configuration options, and Empower only
13
- > supports Facebook authentication.** This will change soon.
14
-
15
18
  Installation
16
19
  ----------
17
20
 
@@ -36,12 +39,13 @@ $ gem install empower
36
39
  Requirements
37
40
  ----------
38
41
 
39
- There are two major prerequisites to using Empower:
42
+ There are three major prerequisites to using Empower:
40
43
 
41
44
  * Using/installing [Devise](https://github.com/plataformatec/devise)
42
45
  * Creating a `User` model
46
+ * Add `name` and `image` to your `User` model
43
47
 
44
- Referencing [this section in the
48
+ Referencing [this section in Devise's
45
49
  README](https://github.com/plataformatec/devise#getting-started), this means
46
50
  you should run the following commands:
47
51
 
@@ -50,6 +54,9 @@ $ bundle exec rails g devise:install
50
54
  $ bundle exec rails g devise User
51
55
  ```
52
56
 
57
+ Meanwhile, the `empower:install` generator will take care of adding the
58
+ migration for the added columns. Just double check it.
59
+
53
60
  Usage
54
61
  ----------
55
62
 
@@ -60,7 +67,8 @@ $ bundle exec rails g empower:install
60
67
  ```
61
68
 
62
69
  Before you begin, replace the `APP_ID` and `APP_SECRET` in
63
- `config/initializers/devise.rb` with your Facebook's keys.
70
+ `config/initializers/devise.rb` for each of the strategies you wish to use. If
71
+ you don't want to use a strategy, delete it from the Devise config file.
64
72
 
65
73
  > *Note: I suggest NOT tracking these keys with Git and hiding them someone
66
74
  > like an environment variable or a private settings file.*
@@ -70,18 +78,31 @@ Restart your server and you're ready to go.
70
78
  Helpers
71
79
  ----------
72
80
 
73
- There is one helper, and that is a Facebook sign in button.
81
+ There is a helper for a sign in button for each of the strategies in the form
82
+ of `[strategy]_login_button`. Facebook's looks like this:
74
83
 
75
84
  ```erb
76
85
  <%= facebook_login_button %>
77
86
  ```
78
87
 
88
+ Optionally, you can pass a custom message to the button helper:
89
+
90
+ ```erb
91
+ <%= facebook_login_button "Sign In, Friendo!" %>
92
+ ```
93
+
79
94
  Otherwise, if you want to handle your own links, they would look like this:
80
95
 
81
96
  ```erb
82
97
  <%= link_to 'Login', user_omniauth_authorize_path(:facebook) %>
83
98
  ```
84
99
 
100
+ The odd man out here is Google, which needs to be written like this:
101
+
102
+ ```erb
103
+ <%= link_to 'Login', user_omniauth_authorize_path(:google_oauth2) %>
104
+ ```
105
+
85
106
  Overriding Redirects
86
107
  ----------
87
108
 
@@ -93,6 +114,39 @@ application controller
93
114
  :-redirect-to-a -specific-page-on-successful-sign-in#redirect-back-to-current-
94
115
  page-after-oauth- signin) for more information.
95
116
 
117
+ Gotcha!
118
+ ----------
119
+
120
+ There are a handful of quirks in this gem, but I think there are two worthy of
121
+ noting over any others
122
+
123
+ ### Consolidating User Accounts
124
+
125
+ Each individual user needs a unique email address with Devise, which makes
126
+ perfect sense. A common issue with OmniAuth is that users signed up for the
127
+ various services with different email addresses over the years.
128
+
129
+ The ways in which I've seen developers circumvent this is convoluted. I like to
130
+ keep things simple and so we say *if a social account uses a different email
131
+ address, then the user account within your app is a different account.*
132
+
133
+ That being said, we do consolidate accounts where we can. If, for example, your
134
+ Facebook and Google accounts use the same email address, the user account
135
+ within your app with be the same.
136
+
137
+ ### No Twitter Email
138
+
139
+ Twitter, in all its infinite wisdom, will not share email addresses in their
140
+ OmniAuth solution. So, we have to create a separate form when the user signs in
141
+ so we can capture a real email address.
142
+
143
+ This solution has several holes in it. There isn't a simple way of ensuring
144
+ that they are entering a valid email address or an email address of someone
145
+ already using the app.
146
+
147
+ If this is a concern, I suggest opening a PR to force confirmable on Devise and
148
+ working it into this solution.
149
+
96
150
  Contributing
97
151
  ----------
98
152
 
@@ -1,17 +1,23 @@
1
- require_dependency "empower_controller"
2
-
3
1
  class Empower::OmniauthCallbacksController < EmpowerController
4
2
 
5
- def facebook
6
- @user = User.from_omniauth(request.env["omniauth.auth"])
3
+ def self.provides_callback_for(provider)
4
+ class_eval %Q{
5
+ def #{provider}
6
+ @user = User.find_for_oauth(env["omniauth.auth"])
7
7
 
8
- if @user.persisted?
9
- sign_in @user #this will throw if @user is not activated
10
- redirect_to after_sign_in_path_for(@user)
11
- else
12
- session["devise.facebook_data"] = request.env["omniauth.auth"]
13
- redirect_to after_sign_in_path_for(@user)
14
- end
8
+ if @user.persisted?
9
+ sign_in_and_redirect @user, :event => :authentication
10
+ set_flash_message(
11
+ :notice,
12
+ :success,
13
+ :kind => "#{provider}".capitalize
14
+ ) if is_navigational_format?
15
+ else
16
+ session["devise.#{provider}_data"] = env["omniauth.auth"]
17
+ redirect_to new_user_registration_url
18
+ end
19
+ end
20
+ }
15
21
  end
16
22
 
17
23
  def failure
@@ -21,4 +27,8 @@ class Empower::OmniauthCallbacksController < EmpowerController
21
27
  )
22
28
  end
23
29
 
30
+ [:facebook, :google_oauth2, :twitter].each do |provider|
31
+ provides_callback_for provider
32
+ end
33
+
24
34
  end
@@ -0,0 +1,51 @@
1
+ class Empower::UsersController < ApplicationController
2
+
3
+ before_filter :authenticate_user!
4
+ before_filter :verify_unverified_email
5
+
6
+ def edit
7
+ end
8
+
9
+ def update
10
+ user = User.find_by_email(params[:user][:email])
11
+ temp_user = current_user
12
+ # if there isn't a user with that email address, we
13
+ # change email address of temp user
14
+ if user.nil?
15
+ current_user.update!(user_params)
16
+ updated_user = current_user
17
+ sign_out temp_user
18
+ sign_in_and_redirect updated_user
19
+ # if there is an existing user with that email address,
20
+ # we find the existing user and delete the temp user
21
+ elsif user != current_user
22
+ sign_out temp_user
23
+ temp_user.identities.first.update(:user => user)
24
+ temp_user.destroy
25
+ sign_in_and_redirect user
26
+ else
27
+ render 'new'
28
+ end
29
+ end
30
+
31
+ private
32
+
33
+ def user_params
34
+ params.require(:user).permit(:email)
35
+ end
36
+
37
+ def verify_unverified_email
38
+ if current_user.email_verified?
39
+ raise ActionController::RoutingError.new('Not Found')
40
+ end
41
+ end
42
+
43
+ def after_sign_in_path_for(resource)
44
+ if resource.email_verified?
45
+ stored_location_for(resource) || main_app.root_path
46
+ else
47
+ empower.finish_signup_path
48
+ end
49
+ end
50
+
51
+ end
@@ -1,2 +1,13 @@
1
- class EmpowerController < ApplicationController
1
+ class EmpowerController < Devise::OmniauthCallbacksController
2
+
3
+ private
4
+
5
+ def after_sign_in_path_for(resource)
6
+ if resource.email_verified?
7
+ stored_location_for(resource) || main_app.root_path
8
+ else
9
+ empower.finish_signup_path
10
+ end
11
+ end
12
+
2
13
  end
@@ -6,7 +6,23 @@ module Empower
6
6
  text,
7
7
  main_app.user_omniauth_authorize_path(:facebook),
8
8
  :class => 'button facebook'
9
- )
9
+ ) unless user_signed_in?
10
+ end
11
+
12
+ def google_login_button(text = 'Sign in with Google')
13
+ link_to(
14
+ text,
15
+ main_app.user_omniauth_authorize_path(:google_oauth2),
16
+ :class => 'button google'
17
+ ) unless user_signed_in?
18
+ end
19
+
20
+ def twitter_login_button(text = 'Sign in with Twitter')
21
+ link_to(
22
+ text,
23
+ main_app.user_omniauth_authorize_path(:twitter),
24
+ :class => 'button twitter'
25
+ ) unless user_signed_in?
10
26
  end
11
27
 
12
28
  end
@@ -0,0 +1,6 @@
1
+ <h2>Enter an Email Address</h2>
2
+
3
+ <%= simple_form_for current_user, :url => empower.complete_signup_path do |f| %>
4
+ <%= f.input :email, :input_html => { :value => '' } %>
5
+ <%= f.submit "Save Email Address" %>
6
+ <% end %>
@@ -1,2 +1,6 @@
1
1
  Empower::Engine.routes.draw do
2
+
3
+ get 'users/oauth/finish' => 'users#edit', :as => :finish_signup
4
+ patch 'users/oauth/finish' => 'users#update', :as => :complete_signup
5
+
2
6
  end
@@ -19,9 +19,13 @@ Gem::Specification.new do |spec|
19
19
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
20
20
  spec.require_paths = ["lib"]
21
21
 
22
- spec.add_dependency "rails", "~> 4.1.0"
23
- spec.add_dependency "devise"
22
+ # spec.add_dependency "rails", "~> 4.1.0"
23
+ spec.add_dependency 'devise'
24
+ spec.add_dependency 'omniauth'
24
25
  spec.add_dependency 'omniauth-facebook'
26
+ spec.add_dependency 'omniauth-google-oauth2'
27
+ spec.add_dependency 'omniauth-twitter'
28
+ spec.add_dependency 'simple_form'
25
29
 
26
30
  spec.add_development_dependency "bundler", "~> 1.6"
27
31
  end
@@ -1,5 +1,11 @@
1
1
  require 'empower/engine'
2
2
  require 'empower/omniauth'
3
3
 
4
+ require 'omniauth'
5
+ require 'omniauth-facebook'
6
+ require 'omniauth-google-oauth2'
7
+ require 'omniauth-twitter'
8
+ require 'simple_form'
9
+
4
10
  module Empower
5
11
  end
@@ -2,51 +2,64 @@ module Empower
2
2
  module OmniAuth
3
3
  extend ActiveSupport::Concern
4
4
 
5
+ TEMP_EMAIL_PREFIX = 'change@me'
6
+ TEMP_EMAIL_REGEX = /\Achange@me/
7
+
5
8
  included do
6
- devise :omniauthable, :omniauth_providers => [:facebook]
9
+ devise :omniauthable,
10
+ :omniauth_providers => [:facebook, :google_oauth2, :twitter]
11
+
12
+ has_many :identities
13
+
14
+ validates_format_of :email, :without => TEMP_EMAIL_REGEX, :on => :update
15
+ end
16
+
17
+ def email_verified?
18
+ self.email && self.email !~ TEMP_EMAIL_REGEX
7
19
  end
8
20
 
9
21
  module ClassMethods
10
- def from_omniauth(auth)
11
- user = User.find_by_email(auth.info.email)
22
+ def find_for_oauth(auth, signed_in_resource = nil)
23
+
24
+ # Get the identity and user if they exist
25
+ identity = Identity.find_for_oauth(auth)
26
+
27
+ # If a signed_in_resource is provided it always overrides the existing user
28
+ # to prevent the identity being locked with accidentally created accounts.
29
+ # Note that this may leave zombie accounts (with no associated identity) which
30
+ # can be cleaned up at a later date.
31
+ user = signed_in_resource ? signed_in_resource : identity.user
32
+
33
+ # Create the user if needed
12
34
  if user.nil?
13
- user = User.create!(
14
- :email => auth.info.email,
15
- :password => Devise.friendly_token[0,20],
16
- )
17
- attrs = {}
18
- if ActiveRecord::Base.connection.column_exists?(:users, :name, :string)
19
- attrs[:name] = auth.info.name
20
- end
21
- if ActiveRecord::Base.connection.column_exists?(:users, :image, :string)
22
- attrs[:image] = auth.info.image
23
- end
24
- if attrs.keys.size > 0
25
- user.update_columns(attrs)
26
- end
27
- else
28
- attrs = {}
29
- if ActiveRecord::Base.connection.column_exists?(:users, :name, :string)
30
- attrs[:name] = auth.info.name
31
- end
32
- if ActiveRecord::Base.connection.column_exists?(:users, :image, :string)
33
- attrs[:image] = auth.info.image
34
- end
35
- if attrs.keys.size > 0
36
- user.update_columns(attrs)
35
+
36
+ # Get the existing user by email if the provider gives us a verified email.
37
+ # If no verified email was provided we assign a temporary email and ask the
38
+ # user to verify it on the next step via UsersController.finish_signup
39
+ email = auth.info.email
40
+ user = User.find_by_email(email) if email
41
+
42
+ # Create the user if it's a new registration
43
+ if user.nil?
44
+ user = User.new(
45
+ :name => auth.extra.raw_info.name,
46
+ :image => auth.info.image,
47
+ #username: auth.info.nickname || auth.uid,
48
+ :email => email ? email : "#{TEMP_EMAIL_PREFIX}-#{auth.uid}-#{auth.provider}.com",
49
+ :password => Devise.friendly_token[0,20]
50
+ )
51
+ user.save!
37
52
  end
38
53
  end
39
- user
40
- end
41
54
 
42
- def new_with_session(params, session)
43
- super.tap do |user|
44
- if data = session["devise.facebook_data"] &&
45
- session["devise.facebook_data"]["extra"]["raw_info"]
46
- user.email = data["email"] if user.email.blank?
47
- end
55
+ # Associate the identity with the user if needed
56
+ if identity.user != user
57
+ identity.user = user
58
+ identity.save!
48
59
  end
60
+ user
49
61
  end
50
62
  end
63
+
51
64
  end
52
65
  end
@@ -1,3 +1,3 @@
1
1
  module Empower
2
- VERSION = "0.2.0"
2
+ VERSION = "1.0.0"
3
3
  end
@@ -5,16 +5,33 @@ module Empower
5
5
  class InstallGenerator < Rails::Generators::Base
6
6
  desc "Add OmniAuth config to Devise"
7
7
 
8
- source_root File.expand_path('../../templates', __FILE__)
8
+ source_root File.expand_path('../templates', __FILE__)
9
9
 
10
10
  def verify_prereqs
11
11
  perform_checks
12
12
  end
13
13
 
14
+ def add_omniauth_columns_to_users
15
+ cols = ''
16
+ cols += 'name ' unless User.new.respond_to?(:name)
17
+ cols += 'image ' unless User.new.respond_to?(:image)
18
+ unless cols.blank?
19
+ generate "migration add_omniauth_columns_to_users #{cols}"
20
+ end
21
+ end
22
+
23
+ def add_identity_model
24
+ generate "model identity user:references provider:string uid:string"
25
+ template "identity_model.rb", "app/models/identity.rb", :force => true
26
+ end
27
+
14
28
  def add_devise_config
29
+ config = "\n config.omniauth :facebook, 'APP_ID', 'APP_SECRET'"
30
+ config += "\n config.omniauth :google_oauth2, 'APP_ID', 'APP_SECRET'"
31
+ config += "\n config.omniauth :twitter, 'APP_ID', 'APP_SECRET'"
15
32
  insert_into_file(
16
33
  'config/initializers/devise.rb',
17
- "\n config.omniauth :facebook, 'APP_ID', 'APP_SECRET'",
34
+ config,
18
35
  :after => 'Devise.setup do |config|'
19
36
  )
20
37
  end
@@ -41,6 +58,11 @@ module Empower
41
58
  ', :controllers => { :omniauth_callbacks => "empower/omniauth_callbacks" }',
42
59
  :after => 'devise_for :users'
43
60
  )
61
+ insert_into_file(
62
+ 'config/routes.rb',
63
+ " mount Empower::Engine => '/'\n",
64
+ :after => /Rails\.application\.routes\.draw\ do(.*)\n/
65
+ )
44
66
  end
45
67
 
46
68
  def add_helper
@@ -51,6 +73,24 @@ module Empower
51
73
  )
52
74
  end
53
75
 
76
+ def add_routes_helper
77
+ m = "\n def method_missing(method, *args, &block)\n"
78
+ m += " if(\n"
79
+ m += " (method.to_s.end_with?('_path') || method.to_s.end_with?('_url')) &&\n"
80
+ m += " main_app.respond_to?(method)\n"
81
+ m += " )\n"
82
+ m += " main_app.send(method, *args)\n"
83
+ m += " else\n"
84
+ m += " super\n"
85
+ m += " end\n"
86
+ m += " end\n\n"
87
+ insert_into_file(
88
+ 'app/helpers/application_helper.rb',
89
+ m,
90
+ :after => /module\ ApplicationHelper(.*)\n/
91
+ )
92
+ end
93
+
54
94
  private
55
95
 
56
96
  def perform_checks
@@ -0,0 +1,18 @@
1
+ class Identity < ActiveRecord::Base
2
+
3
+ # ------------------------------------------ Associations
4
+
5
+ belongs_to :user
6
+
7
+ # ------------------------------------------ Validations
8
+
9
+ validates_presence_of :uid, :provider
10
+ validates_uniqueness_of :uid, :scope => :provider
11
+
12
+ # ------------------------------------------ Class Methods
13
+
14
+ def self.find_for_oauth(auth)
15
+ find_or_create_by(:uid => auth.uid, :provider => auth.provider)
16
+ end
17
+
18
+ end
metadata CHANGED
@@ -1,31 +1,31 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: empower
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sean C Davis
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-04-27 00:00:00.000000000 Z
11
+ date: 2015-05-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: rails
14
+ name: devise
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 4.1.0
19
+ version: '0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: 4.1.0
26
+ version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
- name: devise
28
+ name: omniauth
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - ">="
@@ -52,6 +52,48 @@ dependencies:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: omniauth-google-oauth2
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: omniauth-twitter
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: simple_form
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
55
97
  - !ruby/object:Gem::Dependency
56
98
  name: bundler
57
99
  requirement: !ruby/object:Gem::Requirement
@@ -83,9 +125,11 @@ files:
83
125
  - app/assets/javascripts/empower/application.js
84
126
  - app/assets/stylesheets/empower/application.css
85
127
  - app/controllers/empower/omniauth_callbacks_controller.rb
128
+ - app/controllers/empower/users_controller.rb
86
129
  - app/controllers/empower_controller.rb
87
130
  - app/helpers/empower/application_helper.rb
88
131
  - app/helpers/empower/omniauth_helper.rb
132
+ - app/views/empower/users/edit.html.erb
89
133
  - app/views/layouts/empower/application.html.erb
90
134
  - config/routes.rb
91
135
  - empower.gemspec
@@ -94,6 +138,7 @@ files:
94
138
  - lib/empower/omniauth.rb
95
139
  - lib/empower/version.rb
96
140
  - lib/generators/empower/install_generator.rb
141
+ - lib/generators/empower/templates/identity_model.rb
97
142
  - lib/tasks/empower_tasks.rake
98
143
  homepage: https://github.com/seancdavis/empower
99
144
  licenses:
@@ -115,7 +160,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
115
160
  version: '0'
116
161
  requirements: []
117
162
  rubyforge_project:
118
- rubygems_version: 2.2.0
163
+ rubygems_version: 2.4.6
119
164
  signing_key:
120
165
  specification_version: 4
121
166
  summary: ''