empower 0.0.0 → 0.1.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 +4 -4
- data/.gitignore +8 -14
- data/Gemfile +12 -2
- data/Gemfile.lock +123 -0
- data/{LICENSE.txt → LICENSE.md} +1 -3
- data/README.md +72 -11
- data/Rakefile +16 -1
- data/app/assets/images/empower/.keep +0 -0
- data/app/assets/javascripts/empower/application.js +13 -0
- data/app/assets/stylesheets/empower/application.css +15 -0
- data/app/controllers/empower/application_controller.rb +4 -0
- data/app/controllers/empower/omniauth_callbacks_controller.rb +29 -0
- data/app/helpers/empower/application_helper.rb +4 -0
- data/app/helpers/empower/omniauth_helper.rb +13 -0
- data/app/views/layouts/empower/application.html.erb +14 -0
- data/bin/rails +12 -0
- data/config/routes.rb +2 -0
- data/empower.gemspec +18 -14
- data/lib/empower.rb +2 -2
- data/lib/empower/engine.rb +5 -0
- data/lib/empower/omniauth.rb +52 -0
- data/lib/empower/version.rb +1 -1
- data/lib/generators/empower/install_generator.rb +74 -0
- data/lib/tasks/empower_tasks.rake +4 -0
- metadata +56 -12
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 988f2741acc65aa587d283a981fb51a6f3b1d847
|
|
4
|
+
data.tar.gz: 644900fd7cf1e5428c0738dfe7c87be5cf378b42
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: c6efa48565eac7d21db4fc6b961ddab361754f968b36ff8c935ee06f3a5cfce74ebdc1c0eed13d69a6353a5e568be5e51e59859c36cb0c8d0b7874a200173734
|
|
7
|
+
data.tar.gz: fdf99f3c3c694a03545889d65488405a5645bf112348970fddf4020b557b9542caf820389716230cabb0409ef29ba79ca4629b92787c0636d2f27f27d5360a3b
|
data/.gitignore
CHANGED
|
@@ -1,14 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
/
|
|
4
|
-
/
|
|
5
|
-
/
|
|
6
|
-
/
|
|
7
|
-
/
|
|
8
|
-
/
|
|
9
|
-
/tmp/
|
|
10
|
-
*.bundle
|
|
11
|
-
*.so
|
|
12
|
-
*.o
|
|
13
|
-
*.a
|
|
14
|
-
mkmf.log
|
|
1
|
+
.bundle/
|
|
2
|
+
log/*.log
|
|
3
|
+
pkg/
|
|
4
|
+
test/dummy/db/*.sqlite3
|
|
5
|
+
test/dummy/db/*.sqlite3-journal
|
|
6
|
+
test/dummy/log/*.log
|
|
7
|
+
test/dummy/tmp/
|
|
8
|
+
test/dummy/.sass-cache
|
data/Gemfile
CHANGED
|
@@ -1,4 +1,14 @@
|
|
|
1
|
-
source
|
|
1
|
+
source "https://rubygems.org"
|
|
2
2
|
|
|
3
|
-
#
|
|
3
|
+
# Declare your gem's dependencies in empower.gemspec.
|
|
4
|
+
# Bundler will treat runtime dependencies like base dependencies, and
|
|
5
|
+
# development dependencies will be added by default to the :development group.
|
|
4
6
|
gemspec
|
|
7
|
+
|
|
8
|
+
# Declare any dependencies that are still in development here instead of in
|
|
9
|
+
# your gemspec. These might include edge Rails or gems from your path or
|
|
10
|
+
# Git. Remember to move these dependencies to your gemspec before releasing
|
|
11
|
+
# your gem to rubygems.org.
|
|
12
|
+
|
|
13
|
+
# To use debugger
|
|
14
|
+
# gem 'debugger'
|
data/Gemfile.lock
ADDED
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
PATH
|
|
2
|
+
remote: .
|
|
3
|
+
specs:
|
|
4
|
+
empower (0.1.0)
|
|
5
|
+
devise
|
|
6
|
+
omniauth-facebook
|
|
7
|
+
rails (~> 4.1.0)
|
|
8
|
+
|
|
9
|
+
GEM
|
|
10
|
+
remote: https://rubygems.org/
|
|
11
|
+
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)
|
|
20
|
+
rack-test (~> 0.6.2)
|
|
21
|
+
actionview (4.1.10)
|
|
22
|
+
activesupport (= 4.1.10)
|
|
23
|
+
builder (~> 3.1)
|
|
24
|
+
erubis (~> 2.7.0)
|
|
25
|
+
activemodel (4.1.10)
|
|
26
|
+
activesupport (= 4.1.10)
|
|
27
|
+
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)
|
|
34
|
+
json (~> 1.7, >= 1.7.7)
|
|
35
|
+
minitest (~> 5.1)
|
|
36
|
+
thread_safe (~> 0.1)
|
|
37
|
+
tzinfo (~> 1.1)
|
|
38
|
+
arel (5.0.1.20140414130214)
|
|
39
|
+
bcrypt (3.1.10)
|
|
40
|
+
builder (3.2.2)
|
|
41
|
+
devise (3.4.1)
|
|
42
|
+
bcrypt (~> 3.0)
|
|
43
|
+
orm_adapter (~> 0.1)
|
|
44
|
+
railties (>= 3.2.6, < 5)
|
|
45
|
+
responders
|
|
46
|
+
thread_safe (~> 0.1)
|
|
47
|
+
warden (~> 1.2.3)
|
|
48
|
+
erubis (2.7.0)
|
|
49
|
+
faraday (0.9.1)
|
|
50
|
+
multipart-post (>= 1.2, < 3)
|
|
51
|
+
hashie (3.4.1)
|
|
52
|
+
hike (1.2.3)
|
|
53
|
+
i18n (0.7.0)
|
|
54
|
+
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)
|
|
60
|
+
multi_json (1.11.0)
|
|
61
|
+
multi_xml (0.5.5)
|
|
62
|
+
multipart-post (2.0.0)
|
|
63
|
+
oauth2 (1.0.0)
|
|
64
|
+
faraday (>= 0.8, < 0.10)
|
|
65
|
+
jwt (~> 1.0)
|
|
66
|
+
multi_json (~> 1.3)
|
|
67
|
+
multi_xml (~> 0.5)
|
|
68
|
+
rack (~> 1.2)
|
|
69
|
+
omniauth (1.2.2)
|
|
70
|
+
hashie (>= 1.2, < 4)
|
|
71
|
+
rack (~> 1.0)
|
|
72
|
+
omniauth-facebook (2.0.1)
|
|
73
|
+
omniauth-oauth2 (~> 1.2)
|
|
74
|
+
omniauth-oauth2 (1.2.0)
|
|
75
|
+
faraday (>= 0.8, < 0.10)
|
|
76
|
+
multi_json (~> 1.3)
|
|
77
|
+
oauth2 (~> 1.0)
|
|
78
|
+
omniauth (~> 1.2)
|
|
79
|
+
orm_adapter (0.5.0)
|
|
80
|
+
rack (1.5.2)
|
|
81
|
+
rack-test (0.6.3)
|
|
82
|
+
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)
|
|
96
|
+
rake (>= 0.8.7)
|
|
97
|
+
thor (>= 0.18.1, < 2.0)
|
|
98
|
+
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)
|
|
110
|
+
thor (0.19.1)
|
|
111
|
+
thread_safe (0.3.5)
|
|
112
|
+
tilt (1.4.1)
|
|
113
|
+
tzinfo (1.2.2)
|
|
114
|
+
thread_safe (~> 0.1)
|
|
115
|
+
warden (1.2.3)
|
|
116
|
+
rack (>= 1.0)
|
|
117
|
+
|
|
118
|
+
PLATFORMS
|
|
119
|
+
ruby
|
|
120
|
+
|
|
121
|
+
DEPENDENCIES
|
|
122
|
+
bundler (~> 1.6)
|
|
123
|
+
empower!
|
data/{LICENSE.txt → LICENSE.md}
RENAMED
data/README.md
CHANGED
|
@@ -1,30 +1,91 @@
|
|
|
1
|
-
|
|
1
|
+
Empower
|
|
2
|
+
==========
|
|
2
3
|
|
|
3
|
-
|
|
4
|
+
Empower is a pre-configured OmniAuth solution for Ruby on Rails applications.
|
|
5
|
+
In contrast to something flexible, like
|
|
6
|
+
[OmniAuth](https://github.com/intridea/omniauth), Empower aims to create the
|
|
7
|
+
solution simply, quickly, and effectively.
|
|
4
8
|
|
|
5
|
-
|
|
9
|
+
To make this happen, you need to understand what's required from you prior to
|
|
10
|
+
using this gem. See below.
|
|
11
|
+
|
|
12
|
+
> **Note: At this time, there are no configuration options, and Empower only
|
|
13
|
+
> supports Facebook authentication.** This will change soon.
|
|
14
|
+
|
|
15
|
+
Installation
|
|
16
|
+
----------
|
|
6
17
|
|
|
7
18
|
Add this line to your application's Gemfile:
|
|
8
19
|
|
|
9
|
-
```
|
|
10
|
-
gem '
|
|
20
|
+
```text
|
|
21
|
+
gem 'cambium'
|
|
11
22
|
```
|
|
12
23
|
|
|
13
24
|
And then execute:
|
|
14
25
|
|
|
15
|
-
|
|
26
|
+
```text
|
|
27
|
+
$ bundle
|
|
28
|
+
```
|
|
16
29
|
|
|
17
30
|
Or install it yourself as:
|
|
18
31
|
|
|
19
|
-
|
|
32
|
+
```text
|
|
33
|
+
$ gem install cambium
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
Requirements
|
|
37
|
+
----------
|
|
38
|
+
|
|
39
|
+
There are two major prerequisites to using Empower:
|
|
40
|
+
|
|
41
|
+
* Using/installing [Devise](https://github.com/plataformatec/devise)
|
|
42
|
+
* Creating a `User` model
|
|
43
|
+
|
|
44
|
+
Referencing [this section in the
|
|
45
|
+
README](https://github.com/plataformatec/devise#getting-started), this means
|
|
46
|
+
you should run the following commands:
|
|
47
|
+
|
|
48
|
+
```text
|
|
49
|
+
$ bundle exec rails g devise:install
|
|
50
|
+
$ bundle exec rails g devise User
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
Usage
|
|
54
|
+
----------
|
|
20
55
|
|
|
21
|
-
|
|
56
|
+
Once Devise is setup and Empower is installed, you can run its generator:
|
|
22
57
|
|
|
23
|
-
|
|
58
|
+
```text
|
|
59
|
+
$ bundle exec rails g empower:install
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
Before you begin, replace the `APP_ID` and `APP_SECRET` in
|
|
63
|
+
`config/initializers/devise.rb` with your Facebook's keys.
|
|
64
|
+
|
|
65
|
+
> *Note: I suggest NOT tracking these keys with Git and hiding them someone
|
|
66
|
+
> like an environment variable or a private settings file.*
|
|
67
|
+
|
|
68
|
+
Restart your server and you're ready to go.
|
|
69
|
+
|
|
70
|
+
Helpers
|
|
71
|
+
----------
|
|
72
|
+
|
|
73
|
+
There is one helper, and that is a Facebook sign in button.
|
|
74
|
+
|
|
75
|
+
```erb
|
|
76
|
+
<%= facebook_login_button %>
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
Otherwise, if you want to handle your own links, they would look like this:
|
|
80
|
+
|
|
81
|
+
```erb
|
|
82
|
+
<%= link_to 'Login', user_omniauth_authorize_path(:facebook) %>
|
|
83
|
+
```
|
|
24
84
|
|
|
25
|
-
|
|
85
|
+
Contributing
|
|
86
|
+
----------
|
|
26
87
|
|
|
27
|
-
1. Fork it ( https://github.com/[my-github-username]/
|
|
88
|
+
1. Fork it ( https://github.com/[my-github-username]/cambium/fork )
|
|
28
89
|
2. Create your feature branch (`git checkout -b my-new-feature`)
|
|
29
90
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
|
30
91
|
4. Push to the branch (`git push origin my-new-feature`)
|
data/Rakefile
CHANGED
|
@@ -1,2 +1,17 @@
|
|
|
1
|
-
|
|
1
|
+
begin
|
|
2
|
+
require 'bundler/setup'
|
|
3
|
+
rescue LoadError
|
|
4
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
|
5
|
+
end
|
|
2
6
|
|
|
7
|
+
require 'rdoc/task'
|
|
8
|
+
|
|
9
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
|
10
|
+
rdoc.rdoc_dir = 'rdoc'
|
|
11
|
+
rdoc.title = 'Empower'
|
|
12
|
+
rdoc.options << '--line-numbers'
|
|
13
|
+
rdoc.rdoc_files.include('README.rdoc')
|
|
14
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
Bundler::GemHelper.install_tasks
|
|
File without changes
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// This is a manifest file that'll be compiled into application.js, which will include all the files
|
|
2
|
+
// listed below.
|
|
3
|
+
//
|
|
4
|
+
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
|
|
5
|
+
// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
|
|
6
|
+
//
|
|
7
|
+
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
|
|
8
|
+
// compiled file.
|
|
9
|
+
//
|
|
10
|
+
// Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details
|
|
11
|
+
// about supported directives.
|
|
12
|
+
//
|
|
13
|
+
//= require_tree .
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* This is a manifest file that'll be compiled into application.css, which will include all the files
|
|
3
|
+
* listed below.
|
|
4
|
+
*
|
|
5
|
+
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
|
|
6
|
+
* or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
|
|
7
|
+
*
|
|
8
|
+
* You're free to add application-wide styles to this file and they'll appear at the bottom of the
|
|
9
|
+
* compiled file so the styles you add here take precedence over styles defined in any styles
|
|
10
|
+
* defined in the other CSS/SCSS files in this directory. It is generally better to create a new
|
|
11
|
+
* file per style scope.
|
|
12
|
+
*
|
|
13
|
+
*= require_tree .
|
|
14
|
+
*= require_self
|
|
15
|
+
*/
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
require_dependency "empower/application_controller"
|
|
2
|
+
|
|
3
|
+
module Empower
|
|
4
|
+
class OmniauthCallbacksController < ApplicationController
|
|
5
|
+
|
|
6
|
+
def facebook
|
|
7
|
+
@user = User.from_omniauth(request.env["omniauth.auth"])
|
|
8
|
+
|
|
9
|
+
if @user.persisted?
|
|
10
|
+
if request.env['omniauth.origin'].split('/').last == 'login'
|
|
11
|
+
sign_in @user #this will throw if @user is not activated
|
|
12
|
+
redirect_to main_app.root_path
|
|
13
|
+
else
|
|
14
|
+
sign_in_and_redirect @user
|
|
15
|
+
end
|
|
16
|
+
else
|
|
17
|
+
session["devise.facebook_data"] = request.env["omniauth.auth"]
|
|
18
|
+
redirect_to main_app.root_path
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def failure
|
|
23
|
+
redirect_to(
|
|
24
|
+
(session[:redirect] || main_app.root_path),
|
|
25
|
+
:alert => "Could not authenticate your request."
|
|
26
|
+
)
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html>
|
|
3
|
+
<head>
|
|
4
|
+
<title>Empower</title>
|
|
5
|
+
<%= stylesheet_link_tag "empower/application", media: "all" %>
|
|
6
|
+
<%= javascript_include_tag "empower/application" %>
|
|
7
|
+
<%= csrf_meta_tags %>
|
|
8
|
+
</head>
|
|
9
|
+
<body>
|
|
10
|
+
|
|
11
|
+
<%= yield %>
|
|
12
|
+
|
|
13
|
+
</body>
|
|
14
|
+
</html>
|
data/bin/rails
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
# This command will automatically be run when you run "rails" with Rails 4 gems installed from the root of your application.
|
|
3
|
+
|
|
4
|
+
ENGINE_ROOT = File.expand_path('../..', __FILE__)
|
|
5
|
+
ENGINE_PATH = File.expand_path('../../lib/empower/engine', __FILE__)
|
|
6
|
+
|
|
7
|
+
# Set up gems listed in the Gemfile.
|
|
8
|
+
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
|
|
9
|
+
require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE'])
|
|
10
|
+
|
|
11
|
+
require 'rails/all'
|
|
12
|
+
require 'rails/engine/commands'
|
data/config/routes.rb
ADDED
data/empower.gemspec
CHANGED
|
@@ -1,23 +1,27 @@
|
|
|
1
|
-
|
|
2
|
-
lib = File.expand_path('../lib', __FILE__)
|
|
3
|
-
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
|
-
require 'empower/version'
|
|
1
|
+
$:.push File.expand_path("../lib", __FILE__)
|
|
5
2
|
|
|
3
|
+
# Maintain your gem's version:
|
|
4
|
+
require "empower/version"
|
|
5
|
+
|
|
6
|
+
# Describe your gem and declare its dependencies:
|
|
6
7
|
Gem::Specification.new do |spec|
|
|
7
|
-
spec.name
|
|
8
|
-
spec.version
|
|
9
|
-
spec.authors
|
|
10
|
-
spec.email
|
|
11
|
-
spec.
|
|
12
|
-
spec.
|
|
13
|
-
spec.
|
|
14
|
-
spec.license
|
|
8
|
+
spec.name = "empower"
|
|
9
|
+
spec.version = Empower::VERSION
|
|
10
|
+
spec.authors = ["Sean C Davis"]
|
|
11
|
+
spec.email = ["scdavis41@gmail.com"]
|
|
12
|
+
spec.homepage = "https://github.com/seancdavis/empower"
|
|
13
|
+
spec.summary = ""
|
|
14
|
+
spec.description = ""
|
|
15
|
+
spec.license = "MIT"
|
|
15
16
|
|
|
16
17
|
spec.files = `git ls-files -z`.split("\x0")
|
|
17
18
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
|
18
19
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
|
19
20
|
spec.require_paths = ["lib"]
|
|
20
21
|
|
|
21
|
-
spec.
|
|
22
|
-
spec.
|
|
22
|
+
spec.add_dependency "rails", "~> 4.1.0"
|
|
23
|
+
spec.add_dependency "devise"
|
|
24
|
+
spec.add_dependency 'omniauth-facebook'
|
|
25
|
+
|
|
26
|
+
spec.add_development_dependency "bundler", "~> 1.6"
|
|
23
27
|
end
|
data/lib/empower.rb
CHANGED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
module Empower
|
|
2
|
+
module OmniAuth
|
|
3
|
+
extend ActiveSupport::Concern
|
|
4
|
+
|
|
5
|
+
included do
|
|
6
|
+
devise :omniauthable, :omniauth_providers => [:facebook]
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
module ClassMethods
|
|
10
|
+
def from_omniauth(auth)
|
|
11
|
+
user = User.find_by_email(auth.info.email)
|
|
12
|
+
if user.nil?
|
|
13
|
+
user = User.create!(
|
|
14
|
+
:email => auth.info.email,
|
|
15
|
+
:password => Devise.friendly_token[0,20],
|
|
16
|
+
)
|
|
17
|
+
attrs = {}
|
|
18
|
+
if user.respond_to?(:name)
|
|
19
|
+
attrs[:name] = auth.info.name
|
|
20
|
+
end
|
|
21
|
+
if user.respond_to?(:image)
|
|
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 user.respond_to?(:name)
|
|
30
|
+
attrs[:name] = auth.info.name
|
|
31
|
+
end
|
|
32
|
+
if user.respond_to?(:image)
|
|
33
|
+
attrs[:image] = auth.info.image
|
|
34
|
+
end
|
|
35
|
+
if attrs.keys.size > 0
|
|
36
|
+
user.update_columns(attrs)
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
user
|
|
40
|
+
end
|
|
41
|
+
|
|
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
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
end
|
data/lib/empower/version.rb
CHANGED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
require 'rake'
|
|
2
|
+
require 'rails/generators'
|
|
3
|
+
|
|
4
|
+
module Empower
|
|
5
|
+
class InstallGenerator < Rails::Generators::Base
|
|
6
|
+
desc "Add OmniAuth config to Devise"
|
|
7
|
+
|
|
8
|
+
source_root File.expand_path('../../templates', __FILE__)
|
|
9
|
+
|
|
10
|
+
def verify_prereqs
|
|
11
|
+
perform_checks
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def add_devise_config
|
|
15
|
+
insert_into_file(
|
|
16
|
+
'config/initializers/devise.rb',
|
|
17
|
+
"\n config.omniauth :facebook, 'APP_ID', 'APP_SECRET'",
|
|
18
|
+
:after => 'Devise.setup do |config|'
|
|
19
|
+
)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def add_model_concern
|
|
23
|
+
insert_into_file(
|
|
24
|
+
'app/models/user.rb',
|
|
25
|
+
"\n\n include Empower::OmniAuth",
|
|
26
|
+
:after => 'ActiveRecord::Base'
|
|
27
|
+
)
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def add_gems
|
|
31
|
+
insert_into_file(
|
|
32
|
+
'Gemfile',
|
|
33
|
+
"\ngem 'omniauth-facebook'",
|
|
34
|
+
:after => /^source(.*)\n/
|
|
35
|
+
)
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def add_routes
|
|
39
|
+
insert_into_file(
|
|
40
|
+
'config/routes.rb',
|
|
41
|
+
', :controllers => { :omniauth_callbacks => "empower/omniauth_callbacks" }',
|
|
42
|
+
:after => 'devise_for :users'
|
|
43
|
+
)
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def add_helper
|
|
47
|
+
insert_into_file(
|
|
48
|
+
'app/controllers/application_controller.rb',
|
|
49
|
+
" helper Empower::OmniauthHelper\n",
|
|
50
|
+
:after => /class\ ApplicationController(.*)\n/
|
|
51
|
+
)
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
private
|
|
55
|
+
|
|
56
|
+
def perform_checks
|
|
57
|
+
# Devise config file
|
|
58
|
+
unless File.exists?("#{Rails.root}/config/initializers/devise.rb")
|
|
59
|
+
msg = "You need to run:\n bundle exec rails g devise:install"
|
|
60
|
+
msg += "\nbefore running this generator."
|
|
61
|
+
raise_error(msg)
|
|
62
|
+
end
|
|
63
|
+
# User model
|
|
64
|
+
unless File.exists?("#{Rails.root}/app/models/user.rb")
|
|
65
|
+
raise_error('You must have a user model to use Empower')
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
def raise_error(msg)
|
|
70
|
+
raise msg
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
end
|
|
74
|
+
end
|
metadata
CHANGED
|
@@ -1,59 +1,103 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: empower
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.1.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-
|
|
11
|
+
date: 2015-04-13 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
|
-
name:
|
|
14
|
+
name: rails
|
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
|
16
16
|
requirements:
|
|
17
17
|
- - "~>"
|
|
18
18
|
- !ruby/object:Gem::Version
|
|
19
|
-
version:
|
|
20
|
-
type: :
|
|
19
|
+
version: 4.1.0
|
|
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:
|
|
26
|
+
version: 4.1.0
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: devise
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - ">="
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: '0'
|
|
34
|
+
type: :runtime
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - ">="
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: '0'
|
|
27
41
|
- !ruby/object:Gem::Dependency
|
|
28
|
-
name:
|
|
42
|
+
name: omniauth-facebook
|
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
|
44
|
+
requirements:
|
|
45
|
+
- - ">="
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: '0'
|
|
48
|
+
type: :runtime
|
|
49
|
+
prerelease: false
|
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - ">="
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: '0'
|
|
55
|
+
- !ruby/object:Gem::Dependency
|
|
56
|
+
name: bundler
|
|
29
57
|
requirement: !ruby/object:Gem::Requirement
|
|
30
58
|
requirements:
|
|
31
59
|
- - "~>"
|
|
32
60
|
- !ruby/object:Gem::Version
|
|
33
|
-
version: '
|
|
61
|
+
version: '1.6'
|
|
34
62
|
type: :development
|
|
35
63
|
prerelease: false
|
|
36
64
|
version_requirements: !ruby/object:Gem::Requirement
|
|
37
65
|
requirements:
|
|
38
66
|
- - "~>"
|
|
39
67
|
- !ruby/object:Gem::Version
|
|
40
|
-
version: '
|
|
68
|
+
version: '1.6'
|
|
41
69
|
description: ''
|
|
42
70
|
email:
|
|
43
71
|
- scdavis41@gmail.com
|
|
44
|
-
executables:
|
|
72
|
+
executables:
|
|
73
|
+
- rails
|
|
45
74
|
extensions: []
|
|
46
75
|
extra_rdoc_files: []
|
|
47
76
|
files:
|
|
48
77
|
- ".gitignore"
|
|
49
78
|
- Gemfile
|
|
50
|
-
-
|
|
79
|
+
- Gemfile.lock
|
|
80
|
+
- LICENSE.md
|
|
51
81
|
- README.md
|
|
52
82
|
- Rakefile
|
|
83
|
+
- app/assets/images/empower/.keep
|
|
84
|
+
- app/assets/javascripts/empower/application.js
|
|
85
|
+
- app/assets/stylesheets/empower/application.css
|
|
86
|
+
- app/controllers/empower/application_controller.rb
|
|
87
|
+
- app/controllers/empower/omniauth_callbacks_controller.rb
|
|
88
|
+
- app/helpers/empower/application_helper.rb
|
|
89
|
+
- app/helpers/empower/omniauth_helper.rb
|
|
90
|
+
- app/views/layouts/empower/application.html.erb
|
|
91
|
+
- bin/rails
|
|
92
|
+
- config/routes.rb
|
|
53
93
|
- empower.gemspec
|
|
54
94
|
- lib/empower.rb
|
|
95
|
+
- lib/empower/engine.rb
|
|
96
|
+
- lib/empower/omniauth.rb
|
|
55
97
|
- lib/empower/version.rb
|
|
56
|
-
|
|
98
|
+
- lib/generators/empower/install_generator.rb
|
|
99
|
+
- lib/tasks/empower_tasks.rake
|
|
100
|
+
homepage: https://github.com/seancdavis/empower
|
|
57
101
|
licenses:
|
|
58
102
|
- MIT
|
|
59
103
|
metadata: {}
|