dailycred 0.1.30 → 0.1.31
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +4 -0
- data/README.md +102 -2
- data/Rakefile +10 -0
- data/app/controllers/sessions_controller.rb +32 -0
- data/app/views/sessions/info.html.erb +7 -0
- data/config/routes.rb +7 -0
- data/dailycred.gemspec +3 -3
- data/docs/lib/dailycred/acts_as_dailycred.html +42 -0
- data/docs/lib/dailycred/client.html +214 -0
- data/docs/lib/dailycred/engine.html +112 -0
- data/docs/lib/dailycred/helper.html +119 -0
- data/docs/lib/dailycred/middleware.html +42 -0
- data/docs/lib/dailycred/tests_helper.html +42 -0
- data/docs/lib/dailycred/user.html +133 -0
- data/docs/lib/dailycred.html +7 -177
- data/docs/lib/generators/dailycred_generator.html +7 -3
- data/docs/lib/generators/templates/migration_create_user.html +2 -1
- data/docs/lib/generators/templates/omniauth.html +36 -3
- data/docs/lib/generators/templates/sessions_controller.html +7 -2
- data/docs/lib/generators/templates/user.html +7 -3
- data/docs/lib/omniauth/strategies/dailycred.html +14 -9
- data/lib/dailycred/acts_as_dailycred.rb +25 -0
- data/lib/dailycred/client.rb +103 -0
- data/lib/dailycred/engine.rb +51 -0
- data/lib/dailycred/helper.rb +39 -1
- data/lib/{middleware → dailycred}/middleware.rb +12 -14
- data/lib/dailycred/tests_helper.rb +5 -0
- data/lib/dailycred/user.rb +2 -2
- data/lib/dailycred.rb +1 -106
- data/lib/generators/dailycred_generator.rb +3 -59
- data/lib/generators/templates/info.html.erb +1 -1
- data/lib/generators/templates/omniauth.rb +6 -17
- data/lib/generators/templates/user.rb +1 -16
- data/lib/omniauth/strategies/dailycred.rb +6 -5
- data/script/download_info.rb +11 -0
- data/spec/omniauth/strategies/dailycred_spec.rb +2 -2
- data/spec/support/dailycred_spec.rb +2 -2
- data/test/generator_test.rb +5 -36
- metadata +20 -6
- data/lib/omniauth-dailycred/version.rb +0 -5
@@ -3,7 +3,6 @@ require 'pp'
|
|
3
3
|
require 'json'
|
4
4
|
require 'faraday'
|
5
5
|
class DailycredGenerator < Rails::Generators::Base
|
6
|
-
require 'faraday'
|
7
6
|
source_root File.expand_path('../templates', __FILE__)
|
8
7
|
|
9
8
|
CLIENT_ID_DEFAULT = 'YOUR_CLIENT_ID'
|
@@ -11,14 +10,9 @@ class DailycredGenerator < Rails::Generators::Base
|
|
11
10
|
|
12
11
|
argument :client_id, :type => :string, :default => CLIENT_ID_DEFAULT, :banner => 'dailycred_client_id'
|
13
12
|
argument :secret_key, :type => :string, :default => CLIENT_SECRET_DEFAULT, :banner => 'dailycred_secret_key'
|
14
|
-
argument :get_input, type: :string, default: 'true', enum: ['true', 'false']
|
15
13
|
|
16
14
|
APP_ROUTES_LINES =<<-EOS
|
17
|
-
|
18
|
-
match "/logout" => "sessions#destroy", :as => :logout
|
19
|
-
match "/auth" => "sessions#info", :as => :auth
|
20
|
-
match "/auth/dailycred", :as => :login
|
21
|
-
match "/auth/failure" => "sessions#failure"
|
15
|
+
mount Dailycred::Engine => '/auth', :as => 'dailycred_engine'
|
22
16
|
EOS
|
23
17
|
|
24
18
|
APP_CONTROLLER_LINES =<<-EOS
|
@@ -34,72 +28,21 @@ class DailycredGenerator < Rails::Generators::Base
|
|
34
28
|
nil
|
35
29
|
end
|
36
30
|
end
|
37
|
-
|
38
|
-
# use as a before_filter to only allow signed in users
|
39
|
-
# example:
|
40
|
-
# before_filter :authenticate
|
41
|
-
def authenticate
|
42
|
-
redirect_to auth_path unless current_user
|
43
|
-
end
|
44
|
-
|
45
|
-
# helper method for getting an instance of dailycred
|
46
|
-
# example:
|
47
|
-
# dailycred.tagUser "user_id", "tag"
|
48
|
-
#
|
49
|
-
# for more documentation, visit https://www.dailycred.com/api/ruby
|
50
|
-
def dailycred
|
51
|
-
config = Rails.configuration
|
52
|
-
@dailycred ||= Dailycred.new(config.DAILYCRED_CLIENT_ID, config.DAILYCRED_SECRET_KEY, config.dc_options)
|
53
|
-
end
|
54
|
-
|
55
|
-
# when making oauth calls, we may need to redirect to our oauth callback url
|
56
|
-
# make sure we have the correct state passed back and forth
|
57
|
-
def set_state
|
58
|
-
@state = session["omniauth.state"] = SecureRandom.uuid
|
59
|
-
end
|
60
|
-
EOS
|
61
|
-
|
62
|
-
APP_HELPER_LINES = <<-EOS
|
63
|
-
def connect_path(provider)
|
64
|
-
url = "/auth/dailycred?identity_provider=\#{provider.to_s}"
|
65
|
-
url += "&referrer=\#{request.protocol}\#{request.host_with_port}\#{request.fullpath}"
|
66
|
-
end
|
67
31
|
EOS
|
68
32
|
|
69
33
|
def install
|
70
|
-
dailycred_ascii =<<-EOS
|
71
|
-
*****
|
72
|
-
*****
|
73
|
-
*****
|
74
|
-
*****
|
75
|
-
*****
|
76
|
-
***** Thanks for using dailycred!
|
77
|
-
*****
|
78
|
-
*****
|
79
|
-
*****
|
80
|
-
*****
|
81
|
-
*****
|
82
|
-
EOS
|
83
|
-
puts dailycred_ascii
|
84
|
-
@get_input = @get_input == "true" ? true : false
|
85
34
|
# copy initializer
|
86
35
|
template "omniauth.rb", "config/initializers/omniauth.rb"
|
87
36
|
# get client info from login if they didnt specify info
|
88
|
-
if @client_id == CLIENT_ID_DEFAULT
|
37
|
+
if @client_id == CLIENT_ID_DEFAULT
|
89
38
|
get_info
|
90
39
|
end
|
91
|
-
# session_controller
|
92
|
-
copy_file "sessions_controller.rb", "app/controllers/sessions_controller.rb"
|
93
40
|
# application controller
|
94
41
|
insert_into_file "app/controllers/application_controller.rb", APP_CONTROLLER_LINES, :after => /class ApplicationController\n|class ApplicationController .*\n/
|
95
|
-
# application helper
|
96
|
-
insert_into_file "app/helpers/application_helper.rb", APP_HELPER_LINES, :after => /module ApplicationHelper\n|module ApplicationHelper .*\n/
|
97
42
|
# add user_model
|
98
43
|
copy_file "user.rb", "app/models/user.rb"
|
99
44
|
# session_controller
|
100
45
|
copy_file "migration_create_user.rb", "db/migrate/#{Time.now.strftime('%Y%m%d%H%M%S')}_create_users.rb"
|
101
|
-
# auth page
|
102
|
-
copy_file "info.html.erb", "app/views/sessions/info.html.erb"
|
103
46
|
# config/routes
|
104
47
|
inject_into_file "config/routes.rb", APP_ROUTES_LINES, :after => ".draw do\n"
|
105
48
|
end
|
@@ -169,6 +112,7 @@ class DailycredGenerator < Rails::Generators::Base
|
|
169
112
|
ensure
|
170
113
|
%x[stty #{stty_settings}]
|
171
114
|
end
|
115
|
+
p ''
|
172
116
|
return email, password
|
173
117
|
end
|
174
118
|
|
@@ -3,5 +3,5 @@
|
|
3
3
|
<%= link_to 'Logout', logout_path %>
|
4
4
|
</p>
|
5
5
|
<% else %>
|
6
|
-
<%= link_to 'Login In', login_path(:action => 'signin') %> or <%= link_to 'Sign Up', login_path(
|
6
|
+
<%= link_to 'Login In', login_path(:action => 'signin') %> or <%= link_to 'Sign Up', login_path() %>
|
7
7
|
<% end %>
|
@@ -1,20 +1,9 @@
|
|
1
1
|
Rails.configuration.DAILYCRED_CLIENT_ID = "<%= client_id %>"
|
2
2
|
Rails.configuration.DAILYCRED_SECRET_KEY = "<%= secret_key %>"
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
dc_options[:client_options][:ssl] = { :ca_path => '/etc/ssl/certs'}
|
11
|
-
end
|
12
|
-
if File.exists?('/opt/local/share/curl/curl-ca-bundle.crt')
|
13
|
-
dc_options[:client_options][:ssl] = { :ca_file => '/opt/local/share/curl/curl-ca-bundle.crt' }
|
14
|
-
end
|
15
|
-
|
16
|
-
Rails.application.config.middleware.use OmniAuth::Builder do
|
17
|
-
provider :dailycred, dc_id, dc_secret, dc_options
|
18
|
-
end
|
19
|
-
|
20
|
-
Rails.application.config.middleware.use "Dailycred::Middleware", dc_id
|
4
|
+
# configure where users should be redirected after authentication
|
5
|
+
#
|
6
|
+
# Rails.configuration.DAILYCRED_OPTIONS = {
|
7
|
+
# :after_auth => '/hello', #after login
|
8
|
+
# :after_unauth => '/goodbye' #after logout
|
9
|
+
# }
|
@@ -1,18 +1,3 @@
|
|
1
1
|
class User < ActiveRecord::Base
|
2
|
-
|
3
|
-
serialize :twitter, Hash
|
4
|
-
serialize :google, Hash
|
5
|
-
serialize :github, Hash
|
6
|
-
serialize :tags, Array
|
7
|
-
serialize :referred, Array
|
8
|
-
|
9
|
-
attr_accessible :email, :username, :created, :verified, :admin, :referred_by, :referred,
|
10
|
-
:facebook, :tags, :provider, :uid, :token, :twitter, :google, :github
|
11
|
-
|
12
|
-
def self.find_or_create_with_omniauth(model)
|
13
|
-
@user = User.find_by_provider_and_uid(model[:provider], model[:uid]) || User.new
|
14
|
-
@user.update_attributes model[:info]
|
15
|
-
@user
|
16
|
-
end
|
17
|
-
|
2
|
+
acts_as_dailycred
|
18
3
|
end
|
@@ -12,7 +12,7 @@ module OmniAuth
|
|
12
12
|
# default options
|
13
13
|
option :client_options, {
|
14
14
|
:site => "https://www.dailycred.com",
|
15
|
-
:authorize_url => '/
|
15
|
+
:authorize_url => '/oauth/authorize',
|
16
16
|
:token_url => '/oauth/access_token'
|
17
17
|
}
|
18
18
|
|
@@ -41,6 +41,7 @@ module OmniAuth
|
|
41
41
|
|
42
42
|
# this step allows auth_params to be added to the url
|
43
43
|
def request_phase
|
44
|
+
p session['omniauth.state']
|
44
45
|
OmniAuth::Strategies::Dailycred::AUTH_PARAMS.each do |param|
|
45
46
|
val = session['omniauth.params'][param]
|
46
47
|
if val && !val.empty?
|
@@ -66,10 +67,10 @@ module OmniAuth
|
|
66
67
|
OmniAuth::Strategies::Dailycred::ATTRIBUTES.each do |attr|
|
67
68
|
@duser[attr] = json[attr]
|
68
69
|
end
|
69
|
-
|
70
|
-
@duser[
|
71
|
-
@duser[
|
72
|
-
end
|
70
|
+
json["identities"].each do |k, v|
|
71
|
+
@duser[k] = v
|
72
|
+
@duser[k][:access_token] = json["access_tokens"][k]
|
73
|
+
end if !json["identities"].nil?
|
73
74
|
# pp @duser
|
74
75
|
|
75
76
|
@duser
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'gems'
|
2
|
+
require 'pp'
|
3
|
+
total = 0
|
4
|
+
Gems.versions('dailycred').reverse.each_with_index do |v,i|
|
5
|
+
p "version: #{v['number']}"
|
6
|
+
p "downloads: #{v['downloads_count']}"
|
7
|
+
total += v['downloads_count']
|
8
|
+
p "total: #{total}"
|
9
|
+
p "release date: #{Date.parse(v['built_at']).to_time.strftime('%m/%d/%Y')}"
|
10
|
+
p "----------"
|
11
|
+
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
require_relative '../../helper_spec.rb'
|
2
2
|
require 'omniauth'
|
3
3
|
require 'dailycred'
|
4
4
|
describe OmniAuth::Strategies::Dailycred do
|
@@ -23,7 +23,7 @@ describe OmniAuth::Strategies::Dailycred do
|
|
23
23
|
subject.client.site.should eq("https://www.dailycred.com")
|
24
24
|
end
|
25
25
|
it 'should have the correct authorization url' do
|
26
|
-
subject.client.options[:authorize_url].should eq("/
|
26
|
+
subject.client.options[:authorize_url].should eq("/oauth/authorize")
|
27
27
|
end
|
28
28
|
|
29
29
|
it 'should have the correct token url' do
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'json'
|
2
2
|
require 'pp'
|
3
3
|
require 'dailycred'
|
4
|
-
describe Dailycred do
|
4
|
+
describe Dailycred::Client do
|
5
5
|
subject do
|
6
6
|
|
7
7
|
end
|
@@ -32,7 +32,7 @@ describe Dailycred do
|
|
32
32
|
dc_options[:client_options][:ssl] = { :ca_file => '/opt/local/share/curl/curl-ca-bundle.crt' }
|
33
33
|
end
|
34
34
|
|
35
|
-
@dc = Dailycred.new client_id, secret, dc_options
|
35
|
+
@dc = Dailycred::Client.new client_id, secret, dc_options
|
36
36
|
end
|
37
37
|
|
38
38
|
it "tags a user" do
|
data/test/generator_test.rb
CHANGED
@@ -31,10 +31,6 @@ class GeneratorTest < Rails::Generators::TestCase
|
|
31
31
|
File.open("#{RAILS_ROOT}/app/controllers/application_controller.rb", 'w') do |f|
|
32
32
|
f.puts "class ApplicationController < ActionController::Base\n\nend"
|
33
33
|
end
|
34
|
-
Dir.mkdir("#{RAILS_ROOT}/app/helpers")
|
35
|
-
File.open("#{RAILS_ROOT}/app/helpers/application_helper.rb", 'w') do |f|
|
36
|
-
f.puts "module ApplicationHelper\n\nend"
|
37
|
-
end
|
38
34
|
end
|
39
35
|
|
40
36
|
teardown do
|
@@ -59,44 +55,17 @@ class GeneratorTest < Rails::Generators::TestCase
|
|
59
55
|
def test_generator args=[]
|
60
56
|
run_generator args
|
61
57
|
assert_file "config/initializers/omniauth.rb" do |config|
|
62
|
-
assert_true config.include?
|
63
|
-
|
64
|
-
# assert_true config.include? 'Rails.configuration.DAILYCRED_SECRET_KEY = "YOUR_SECRET_KEY"'
|
58
|
+
assert_true config.include? 'Rails.configuration.DAILYCRED_CLIENT_ID ='
|
59
|
+
assert_true config.include? 'Rails.configuration.DAILYCRED_SECRET_KEY ='
|
65
60
|
end
|
66
61
|
|
67
|
-
assert_file "config/routes.rb", /(#{Regexp.escape('
|
68
|
-
assert_file "config/routes.rb", /(#{Regexp.escape('match "/logout" => "sessions#destroy", :as => :logout')})/
|
69
|
-
assert_file "config/routes.rb", /(#{Regexp.escape('match "/auth" => "sessions#info", :as => :auth')})/
|
70
|
-
assert_file "config/routes.rb", /(#{Regexp.escape('match "/auth/dailycred", :as => :login')})/
|
71
|
-
assert_file "config/routes.rb", /(#{Regexp.escape('match "/auth/failure" => "sessions#failure"')})/
|
62
|
+
assert_file "config/routes.rb", /(#{Regexp.escape("mount Dailycred::Engine => '/auth', :as => 'dailycred_engine'")})/
|
72
63
|
|
73
|
-
assert_file "app/
|
74
|
-
|
75
|
-
assert_instance_method :destroy, controller
|
76
|
-
assert_instance_method :failure, controller
|
77
|
-
assert_instance_method :info, controller
|
64
|
+
assert_file "app/models/user.rb" do |model|
|
65
|
+
assert_true model.include? "acts_as_dailycred"
|
78
66
|
end
|
79
67
|
|
80
68
|
assert_file "app/controllers/application_controller.rb" do |controller|
|
81
|
-
assert_instance_method :current_user, controller
|
82
|
-
assert_instance_method :set_state, controller
|
83
|
-
assert_instance_method :authenticate, controller
|
84
|
-
assert_instance_method :dailycred, controller
|
85
|
-
end
|
86
|
-
|
87
|
-
assert_file "app/helpers/application_helper.rb" do |helper|
|
88
|
-
assert_instance_method :connect_path, helper
|
89
|
-
end
|
90
|
-
|
91
|
-
assert_file "app/models/user.rb" do |model|
|
92
|
-
# assert_true model.include? "attr_accessible :email, :username, :created, :verified, :admin, :referred_by, :referred, :facebook, :tags, :provider, :uid, :token"
|
93
|
-
assert_class_method :find_or_create_with_omniauth, model
|
94
|
-
assert_true model.include? "serialize :facebook, Hash"
|
95
|
-
assert_true model.include? "serialize :tags, Array"
|
96
|
-
assert_true model.include? "serialize :referred, Array"
|
97
|
-
assert_true model.include? "serialize :twitter, Hash"
|
98
|
-
assert_true model.include? "serialize :google, Hash"
|
99
|
-
assert_true model.include? "serialize :github, Hash"
|
100
69
|
end
|
101
70
|
|
102
71
|
assert_migration "db/migrate/create_users.rb" do |migration|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dailycred
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.31
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-09-
|
12
|
+
date: 2012-09-25 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: omniauth
|
@@ -43,7 +43,7 @@ dependencies:
|
|
43
43
|
- - ! '>='
|
44
44
|
- !ruby/object:Gem::Version
|
45
45
|
version: '0'
|
46
|
-
description:
|
46
|
+
description: A Ruby on Rails engine for authentication with Dailycred.
|
47
47
|
email:
|
48
48
|
- hstove@gmail.com
|
49
49
|
executables: []
|
@@ -56,8 +56,18 @@ files:
|
|
56
56
|
- LICENSE
|
57
57
|
- README.md
|
58
58
|
- Rakefile
|
59
|
+
- app/controllers/sessions_controller.rb
|
60
|
+
- app/views/sessions/info.html.erb
|
61
|
+
- config/routes.rb
|
59
62
|
- dailycred.gemspec
|
60
63
|
- docs/lib/dailycred.html
|
64
|
+
- docs/lib/dailycred/acts_as_dailycred.html
|
65
|
+
- docs/lib/dailycred/client.html
|
66
|
+
- docs/lib/dailycred/engine.html
|
67
|
+
- docs/lib/dailycred/helper.html
|
68
|
+
- docs/lib/dailycred/middleware.html
|
69
|
+
- docs/lib/dailycred/tests_helper.html
|
70
|
+
- docs/lib/dailycred/user.html
|
61
71
|
- docs/lib/generators/dailycred_generator.html
|
62
72
|
- docs/lib/generators/templates/migration_create_user.html
|
63
73
|
- docs/lib/generators/templates/omniauth.html
|
@@ -68,7 +78,12 @@ files:
|
|
68
78
|
- docs/lib/omniauth/strategies/dailycred.html
|
69
79
|
- docs/lib/user/user.html
|
70
80
|
- lib/dailycred.rb
|
81
|
+
- lib/dailycred/acts_as_dailycred.rb
|
82
|
+
- lib/dailycred/client.rb
|
83
|
+
- lib/dailycred/engine.rb
|
71
84
|
- lib/dailycred/helper.rb
|
85
|
+
- lib/dailycred/middleware.rb
|
86
|
+
- lib/dailycred/tests_helper.rb
|
72
87
|
- lib/dailycred/user.rb
|
73
88
|
- lib/generators/USAGE
|
74
89
|
- lib/generators/dailycred_generator.rb
|
@@ -78,9 +93,8 @@ files:
|
|
78
93
|
- lib/generators/templates/omniauth.rb
|
79
94
|
- lib/generators/templates/sessions_controller.rb
|
80
95
|
- lib/generators/templates/user.rb
|
81
|
-
- lib/middleware/middleware.rb
|
82
|
-
- lib/omniauth-dailycred/version.rb
|
83
96
|
- lib/omniauth/strategies/dailycred.rb
|
97
|
+
- script/download_info.rb
|
84
98
|
- spec/helper_spec.rb
|
85
99
|
- spec/omniauth/strategies/dailycred_spec.rb
|
86
100
|
- spec/support/dailycred_spec.rb
|
@@ -110,7 +124,7 @@ rubyforge_project:
|
|
110
124
|
rubygems_version: 1.8.24
|
111
125
|
signing_key:
|
112
126
|
specification_version: 3
|
113
|
-
summary:
|
127
|
+
summary: ''
|
114
128
|
test_files:
|
115
129
|
- spec/helper_spec.rb
|
116
130
|
- spec/omniauth/strategies/dailycred_spec.rb
|