sorcery 0.7.0 → 0.7.4
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.
- data/Gemfile +1 -3
- data/Gemfile.lock +47 -57
- data/README.rdoc +19 -57
- data/Rakefile +27 -1
- data/VERSION +1 -1
- data/lib/generators/sorcery/USAGE +22 -0
- data/lib/generators/sorcery/install_generator.rb +72 -0
- data/lib/{sorcery/initializers → generators/sorcery/templates}/initializer.rb +4 -4
- data/lib/generators/sorcery/templates/migration/activity_logging.rb +17 -0
- data/lib/generators/sorcery/templates/migration/brute_force_protection.rb +11 -0
- data/lib/generators/{sorcery_migration/templates → sorcery/templates/migration}/core.rb +2 -2
- data/lib/generators/{sorcery_migration/templates → sorcery/templates/migration}/external.rb +1 -1
- data/lib/generators/sorcery/templates/migration/remember_me.rb +15 -0
- data/lib/generators/sorcery/templates/migration/reset_password.rb +17 -0
- data/lib/generators/sorcery/templates/migration/user_activation.rb +17 -0
- data/lib/sorcery/controller/submodules/activity_logging.rb +8 -11
- data/lib/sorcery/controller/submodules/brute_force_protection.rb +2 -2
- data/lib/sorcery/controller/submodules/external/protocols/oauth2.rb +23 -8
- data/lib/sorcery/controller/submodules/external/providers/twitter.rb +1 -1
- data/lib/sorcery/controller/submodules/remember_me.rb +16 -14
- data/lib/sorcery/controller/submodules/session_timeout.rb +3 -3
- data/lib/sorcery/controller.rb +40 -39
- data/lib/sorcery/model/adapters/mongo_mapper.rb +49 -0
- data/lib/sorcery/model/adapters/mongoid.rb +3 -1
- data/lib/sorcery/model/submodules/brute_force_protection.rb +14 -6
- data/lib/sorcery/model/submodules/remember_me.rb +9 -2
- data/lib/sorcery/model/submodules/reset_password.rb +12 -2
- data/lib/sorcery/model/submodules/user_activation.rb +13 -1
- data/lib/sorcery/model/temporary_token.rb +4 -2
- data/lib/sorcery/model.rb +21 -4
- data/lib/sorcery.rb +5 -7
- data/sorcery.gemspec +83 -216
- data/spec/Gemfile +1 -1
- data/spec/Gemfile.lock +20 -17
- data/spec/README.md +6 -1
- data/spec/rails3/Gemfile +2 -2
- data/spec/rails3/Gemfile.lock +36 -51
- data/spec/rails3/spec/controller_activity_logging_spec.rb +6 -6
- data/spec/rails3/spec/controller_brute_force_protection_spec.rb +2 -2
- data/spec/rails3/spec/controller_oauth2_spec.rb +5 -3
- data/spec/rails3/spec/controller_session_timeout_spec.rb +4 -4
- data/spec/rails3/spec/spec_helper.rb +1 -3
- data/spec/rails3_mongo_mapper/.gitignore +4 -0
- data/spec/rails3_mongo_mapper/.rspec +1 -0
- data/spec/{sinatra_modular → rails3_mongo_mapper}/Gemfile +5 -5
- data/spec/rails3_mongo_mapper/Gemfile.lock +158 -0
- data/spec/{sinatra → rails3_mongo_mapper}/Rakefile +3 -3
- data/spec/rails3_mongo_mapper/app/controllers/application_controller.rb +108 -0
- data/spec/rails3_mongo_mapper/app/helpers/application_helper.rb +2 -0
- data/spec/rails3_mongo_mapper/app/models/authentication.rb +6 -0
- data/spec/rails3_mongo_mapper/app/models/user.rb +5 -0
- data/spec/rails3_mongo_mapper/app/views/layouts/application.html.erb +14 -0
- data/spec/rails3_mongo_mapper/app/views/sorcery_mailer/activation_email.html.erb +17 -0
- data/spec/rails3_mongo_mapper/app/views/sorcery_mailer/activation_email.text.erb +9 -0
- data/spec/rails3_mongo_mapper/app/views/sorcery_mailer/activation_success_email.html.erb +17 -0
- data/spec/rails3_mongo_mapper/app/views/sorcery_mailer/activation_success_email.text.erb +9 -0
- data/spec/rails3_mongo_mapper/app/views/sorcery_mailer/reset_password_email.html.erb +16 -0
- data/spec/rails3_mongo_mapper/app/views/sorcery_mailer/reset_password_email.text.erb +8 -0
- data/spec/rails3_mongo_mapper/config/application.rb +51 -0
- data/spec/rails3_mongo_mapper/config/boot.rb +13 -0
- data/spec/rails3_mongo_mapper/config/environment.rb +5 -0
- data/spec/rails3_mongo_mapper/config/environments/development.rb +30 -0
- data/spec/rails3_mongo_mapper/config/environments/in_memory.rb +0 -0
- data/spec/rails3_mongo_mapper/config/environments/production.rb +49 -0
- data/spec/rails3_mongo_mapper/config/environments/test.rb +35 -0
- data/spec/rails3_mongo_mapper/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/rails3_mongo_mapper/config/initializers/inflections.rb +10 -0
- data/spec/rails3_mongo_mapper/config/initializers/mime_types.rb +5 -0
- data/spec/rails3_mongo_mapper/config/initializers/mongo.rb +2 -0
- data/spec/rails3_mongo_mapper/config/initializers/secret_token.rb +7 -0
- data/spec/rails3_mongo_mapper/config/initializers/session_store.rb +8 -0
- data/spec/rails3_mongo_mapper/config/locales/en.yml +5 -0
- data/spec/rails3_mongo_mapper/config/routes.rb +59 -0
- data/spec/rails3_mongo_mapper/config.ru +4 -0
- data/spec/rails3_mongo_mapper/db/schema.rb +23 -0
- data/spec/rails3_mongo_mapper/db/seeds.rb +7 -0
- data/spec/rails3_mongo_mapper/lib/tasks/.gitkeep +0 -0
- data/spec/rails3_mongo_mapper/public/404.html +26 -0
- data/spec/rails3_mongo_mapper/public/422.html +26 -0
- data/spec/rails3_mongo_mapper/public/500.html +26 -0
- data/spec/rails3_mongo_mapper/public/favicon.ico +0 -0
- data/spec/rails3_mongo_mapper/public/images/rails.png +0 -0
- data/spec/rails3_mongo_mapper/public/javascripts/application.js +2 -0
- data/spec/rails3_mongo_mapper/public/javascripts/controls.js +965 -0
- data/spec/rails3_mongo_mapper/public/javascripts/dragdrop.js +974 -0
- data/spec/rails3_mongo_mapper/public/javascripts/effects.js +1123 -0
- data/spec/rails3_mongo_mapper/public/javascripts/prototype.js +6001 -0
- data/spec/rails3_mongo_mapper/public/javascripts/rails.js +175 -0
- data/spec/rails3_mongo_mapper/public/robots.txt +5 -0
- data/spec/rails3_mongo_mapper/public/stylesheets/.gitkeep +0 -0
- data/spec/rails3_mongo_mapper/script/rails +6 -0
- data/spec/{sinatra → rails3_mongo_mapper}/spec/controller_spec.rb +45 -42
- data/spec/rails3_mongo_mapper/spec/spec_helper.orig.rb +27 -0
- data/spec/rails3_mongo_mapper/spec/spec_helper.rb +55 -0
- data/spec/rails3_mongo_mapper/spec/user_activation_spec.rb +9 -0
- data/spec/rails3_mongo_mapper/spec/user_activity_logging_spec.rb +8 -0
- data/spec/rails3_mongo_mapper/spec/user_brute_force_protection_spec.rb +8 -0
- data/spec/rails3_mongo_mapper/spec/user_oauth_spec.rb +8 -0
- data/spec/rails3_mongo_mapper/spec/user_remember_me_spec.rb +8 -0
- data/spec/rails3_mongo_mapper/spec/user_reset_password_spec.rb +8 -0
- data/spec/rails3_mongo_mapper/spec/user_spec.rb +37 -0
- data/spec/rails3_mongo_mapper/vendor/plugins/.gitkeep +0 -0
- data/spec/rails3_mongoid/Gemfile +1 -1
- data/spec/rails3_mongoid/Gemfile.lock +38 -36
- data/spec/rails3_mongoid/script/rails +0 -0
- data/spec/rails3_mongoid/spec/controller_activity_logging_spec.rb +98 -0
- data/spec/rails3_mongoid/spec/controller_spec.rb +11 -0
- data/spec/rails3_mongoid/spec/user_spec.rb +1 -0
- data/spec/shared_examples/user_activation_shared_examples.rb +1 -1
- data/spec/shared_examples/user_remember_me_shared_examples.rb +1 -1
- data/spec/shared_examples/user_reset_password_shared_examples.rb +2 -2
- data/spec/shared_examples/user_shared_examples.rb +29 -1
- metadata +105 -251
- data/lib/generators/sorcery_migration/sorcery_migration_generator.rb +0 -24
- data/lib/generators/sorcery_migration/templates/activity_logging.rb +0 -17
- data/lib/generators/sorcery_migration/templates/brute_force_protection.rb +0 -11
- data/lib/generators/sorcery_migration/templates/remember_me.rb +0 -15
- data/lib/generators/sorcery_migration/templates/reset_password.rb +0 -17
- data/lib/generators/sorcery_migration/templates/user_activation.rb +0 -17
- data/lib/sorcery/controller/adapters/sinatra.rb +0 -115
- data/lib/sorcery/sinatra.rb +0 -4
- data/lib/sorcery/test_helpers/internal/sinatra.rb +0 -74
- data/lib/sorcery/test_helpers/internal/sinatra_modular.rb +0 -74
- data/lib/sorcery/test_helpers/sinatra.rb +0 -88
- data/spec/rails3/Rakefile.unused +0 -7
- data/spec/sinatra/Gemfile +0 -15
- data/spec/sinatra/Gemfile.lock +0 -115
- data/spec/sinatra/authentication.rb +0 -3
- data/spec/sinatra/db/migrate/activation/20101224223622_add_activation_to_users.rb +0 -17
- data/spec/sinatra/db/migrate/activity_logging/20101224223624_add_activity_logging_to_users.rb +0 -17
- data/spec/sinatra/db/migrate/brute_force_protection/20101224223626_add_brute_force_protection_to_users.rb +0 -11
- data/spec/sinatra/db/migrate/core/20101224223620_create_users.rb +0 -16
- data/spec/sinatra/db/migrate/external/20101224223628_create_authentications.rb +0 -14
- data/spec/sinatra/db/migrate/remember_me/20101224223623_add_remember_me_token_to_users.rb +0 -15
- data/spec/sinatra/db/migrate/reset_password/20101224223622_add_reset_password_to_users.rb +0 -13
- data/spec/sinatra/filters.rb +0 -27
- data/spec/sinatra/modular.rb +0 -157
- data/spec/sinatra/myapp.rb +0 -133
- data/spec/sinatra/spec/controller_activity_logging_spec.rb +0 -85
- data/spec/sinatra/spec/controller_brute_force_protection_spec.rb +0 -70
- data/spec/sinatra/spec/controller_http_basic_auth_spec.rb +0 -53
- data/spec/sinatra/spec/controller_oauth2_spec.rb +0 -96
- data/spec/sinatra/spec/controller_oauth_spec.rb +0 -100
- data/spec/sinatra/spec/controller_remember_me_spec.rb +0 -64
- data/spec/sinatra/spec/controller_session_timeout_spec.rb +0 -57
- data/spec/sinatra/spec/spec_helper.rb +0 -45
- data/spec/sinatra/user.rb +0 -6
- data/spec/sinatra/views/test_login.erb +0 -4
- data/spec/sinatra_modular/Gemfile.lock +0 -115
- data/spec/sinatra_modular/Rakefile +0 -11
- data/spec/sinatra_modular/authentication.rb +0 -3
- data/spec/sinatra_modular/db/migrate/activation/20101224223622_add_activation_to_users.rb +0 -17
- data/spec/sinatra_modular/db/migrate/activity_logging/20101224223624_add_activity_logging_to_users.rb +0 -17
- data/spec/sinatra_modular/db/migrate/brute_force_protection/20101224223626_add_brute_force_protection_to_users.rb +0 -11
- data/spec/sinatra_modular/db/migrate/core/20101224223620_create_users.rb +0 -16
- data/spec/sinatra_modular/db/migrate/external/20101224223628_create_authentications.rb +0 -14
- data/spec/sinatra_modular/db/migrate/remember_me/20101224223623_add_remember_me_token_to_users.rb +0 -15
- data/spec/sinatra_modular/db/migrate/reset_password/20101224223622_add_reset_password_to_users.rb +0 -13
- data/spec/sinatra_modular/filters.rb +0 -27
- data/spec/sinatra_modular/modular.rb +0 -157
- data/spec/sinatra_modular/myapp.rb +0 -133
- data/spec/sinatra_modular/sorcery_mailer.rb +0 -25
- data/spec/sinatra_modular/spec_modular/controller_activity_logging_spec.rb +0 -85
- data/spec/sinatra_modular/spec_modular/controller_brute_force_protection_spec.rb +0 -70
- data/spec/sinatra_modular/spec_modular/controller_http_basic_auth_spec.rb +0 -53
- data/spec/sinatra_modular/spec_modular/controller_oauth2_spec.rb +0 -96
- data/spec/sinatra_modular/spec_modular/controller_oauth_spec.rb +0 -100
- data/spec/sinatra_modular/spec_modular/controller_remember_me_spec.rb +0 -64
- data/spec/sinatra_modular/spec_modular/controller_session_timeout_spec.rb +0 -57
- data/spec/sinatra_modular/spec_modular/controller_spec.rb +0 -116
- data/spec/sinatra_modular/spec_modular/spec.opts +0 -2
- data/spec/sinatra_modular/spec_modular/spec_helper.rb +0 -51
- data/spec/sinatra_modular/user.rb +0 -6
- data/spec/sinatra_modular/views/test_login.erb +0 -4
- /data/spec/{sinatra → rails3_mongo_mapper/app/mailers}/sorcery_mailer.rb +0 -0
- /data/spec/{sinatra → rails3_mongo_mapper}/spec/spec.opts +0 -0
|
@@ -1,115 +0,0 @@
|
|
|
1
|
-
module Sorcery
|
|
2
|
-
module Controller
|
|
3
|
-
module Adapters
|
|
4
|
-
# This module does the magic of translating Rails commands to Sinatra.
|
|
5
|
-
# This way the Rails code doesn't change, but it actually now calls Sinatra calls.
|
|
6
|
-
module Sinatra
|
|
7
|
-
def self.included(base)
|
|
8
|
-
base.class_eval do
|
|
9
|
-
class << self
|
|
10
|
-
# prepend a filter
|
|
11
|
-
def prepend_filter(type, path = nil, options = {}, &block)
|
|
12
|
-
return filters[type].unshift block unless path
|
|
13
|
-
path, options = //, path if path.respond_to?(:each_pair)
|
|
14
|
-
block, *arguments = compile!(type, path, block, options)
|
|
15
|
-
prepend_filter(type) do
|
|
16
|
-
process_route(*arguments) { instance_eval(&block) }
|
|
17
|
-
end
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
def after_filter(filter)
|
|
21
|
-
after do
|
|
22
|
-
send(filter)
|
|
23
|
-
end
|
|
24
|
-
end
|
|
25
|
-
end
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
::Sinatra::Request.class_eval do
|
|
29
|
-
def authorization
|
|
30
|
-
env['HTTP_AUTHORIZATION'] ||
|
|
31
|
-
env['X-HTTP_AUTHORIZATION'] ||
|
|
32
|
-
env['X_HTTP_AUTHORIZATION'] ||
|
|
33
|
-
env['REDIRECT_X_HTTP_AUTHORIZATION'] || nil
|
|
34
|
-
end
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
base.send(:include, SorceryHelpers)
|
|
38
|
-
base.send(:include, InstanceMethods)
|
|
39
|
-
base.extend(ClassMethods)
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
module SorceryHelpers
|
|
43
|
-
|
|
44
|
-
def request_http_basic_authentication(realm)
|
|
45
|
-
response.header['WWW-Authenticate'] = %(Basic realm="#{realm}")
|
|
46
|
-
response.status = 401
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
def authenticate_with_http_basic(&blk)
|
|
50
|
-
@auth ||= Rack::Auth::Basic::Request.new(request.env)
|
|
51
|
-
yield @auth.credentials if (@auth.provided? && @auth.basic? && @auth.credentials)
|
|
52
|
-
end
|
|
53
|
-
|
|
54
|
-
end
|
|
55
|
-
|
|
56
|
-
module InstanceMethods
|
|
57
|
-
def reset_session
|
|
58
|
-
session.clear
|
|
59
|
-
end
|
|
60
|
-
|
|
61
|
-
def redirect_to(*args)
|
|
62
|
-
args.pop if args.last.is_a?(Hash)
|
|
63
|
-
redirect(*args)
|
|
64
|
-
end
|
|
65
|
-
|
|
66
|
-
def root_path
|
|
67
|
-
'/'
|
|
68
|
-
end
|
|
69
|
-
|
|
70
|
-
::Sinatra.helpers do
|
|
71
|
-
include SorceryHelpers
|
|
72
|
-
end
|
|
73
|
-
|
|
74
|
-
def cookies
|
|
75
|
-
@cookie_proxy ||= CookieProxy.new(request, response)
|
|
76
|
-
end
|
|
77
|
-
end
|
|
78
|
-
|
|
79
|
-
class CookieProxy
|
|
80
|
-
def initialize(request, response)
|
|
81
|
-
@request = request
|
|
82
|
-
@response = response
|
|
83
|
-
@secure = false
|
|
84
|
-
end
|
|
85
|
-
|
|
86
|
-
def [](key)
|
|
87
|
-
value = @request.cookies[key.to_s]
|
|
88
|
-
end
|
|
89
|
-
|
|
90
|
-
def []=(key, value)
|
|
91
|
-
if @secure
|
|
92
|
-
value.merge(:secret => Config.sinatra_cookie_secret)
|
|
93
|
-
@secure = false
|
|
94
|
-
end
|
|
95
|
-
@response.set_cookie(key, value)
|
|
96
|
-
end
|
|
97
|
-
|
|
98
|
-
# mark cookie as signed, which will light a flag, which will cause the next set_cookie to be encrypted.
|
|
99
|
-
def signed
|
|
100
|
-
@secure = true
|
|
101
|
-
self
|
|
102
|
-
end
|
|
103
|
-
end
|
|
104
|
-
|
|
105
|
-
module ClassMethods
|
|
106
|
-
def prepend_before_filter(filter)
|
|
107
|
-
prepend_filter(:before) do
|
|
108
|
-
send(filter)
|
|
109
|
-
end
|
|
110
|
-
end
|
|
111
|
-
end
|
|
112
|
-
end
|
|
113
|
-
end
|
|
114
|
-
end
|
|
115
|
-
end
|
data/lib/sorcery/sinatra.rb
DELETED
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
module Sorcery
|
|
2
|
-
module TestHelpers
|
|
3
|
-
module Internal
|
|
4
|
-
module Sinatra
|
|
5
|
-
include ::Sorcery::TestHelpers::Sinatra::CookieSessionMethods
|
|
6
|
-
include ::Sorcery::TestHelpers::Sinatra::InstanceMethods
|
|
7
|
-
|
|
8
|
-
class ::Sinatra::Application
|
|
9
|
-
class << self
|
|
10
|
-
attr_accessor :sorcery_vars
|
|
11
|
-
end
|
|
12
|
-
@sorcery_vars = {}
|
|
13
|
-
|
|
14
|
-
# NOTE: see before and after test filters in filters.rb
|
|
15
|
-
|
|
16
|
-
def save_instance_vars
|
|
17
|
-
instance_variables.each do |var|
|
|
18
|
-
self.class.sorcery_vars[:"#{var.to_s.delete("@")}"] = instance_variable_get(var)
|
|
19
|
-
end
|
|
20
|
-
end
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
::RSpec::Matchers.define :redirect_to do |expected|
|
|
24
|
-
match do |actual|
|
|
25
|
-
actual.status == 302 && actual.location == expected
|
|
26
|
-
end
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
def clear_user_without_logout
|
|
30
|
-
get_sinatra_app(subject).instance_variable_set(:@current_user, nil)
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
def assigns
|
|
34
|
-
::Sinatra::Application.sorcery_vars
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
def sorcery_reload!(submodules = [], options = {})
|
|
38
|
-
reload_user_class
|
|
39
|
-
|
|
40
|
-
# return to no-module configuration
|
|
41
|
-
::Sorcery::Controller::Config.init!
|
|
42
|
-
::Sorcery::Controller::Config.reset!
|
|
43
|
-
|
|
44
|
-
# clear all filters
|
|
45
|
-
::Sinatra::Application.instance_variable_set(:@filters, {:before => [], :after => []})
|
|
46
|
-
load File.join(File.dirname(__FILE__), '..', '..', '..', '..', 'spec', 'sinatra', 'filters.rb')
|
|
47
|
-
::Sinatra::Application.send(:include, ::Filters)
|
|
48
|
-
|
|
49
|
-
# configure
|
|
50
|
-
::Sorcery::Controller::Config.submodules = submodules
|
|
51
|
-
::Sorcery::Controller::Config.user_class = nil
|
|
52
|
-
::Sinatra::Application.send(:include, Sorcery::Controller::Adapters::Sinatra)
|
|
53
|
-
::Sinatra::Application.send(:include, Sorcery::Controller)
|
|
54
|
-
::Sorcery::Controller::Config.user_class = "User"
|
|
55
|
-
|
|
56
|
-
::Sorcery::Controller::Config.user_config do |user|
|
|
57
|
-
options.each do |property, value|
|
|
58
|
-
user.send(:"#{property}=", value)
|
|
59
|
-
end
|
|
60
|
-
end
|
|
61
|
-
User.authenticates_with_sorcery!
|
|
62
|
-
end
|
|
63
|
-
|
|
64
|
-
def sorcery_controller_property_set(property, value)
|
|
65
|
-
::Sorcery::Controller::Config.send(:"#{property}=", value)
|
|
66
|
-
end
|
|
67
|
-
|
|
68
|
-
def sorcery_controller_external_property_set(provider, property, value)
|
|
69
|
-
::Sorcery::Controller::Config.send(provider).send(:"#{property}=", value)
|
|
70
|
-
end
|
|
71
|
-
end
|
|
72
|
-
end
|
|
73
|
-
end
|
|
74
|
-
end
|
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
module Sorcery
|
|
2
|
-
module TestHelpers
|
|
3
|
-
module Internal
|
|
4
|
-
module SinatraModular
|
|
5
|
-
include ::Sorcery::TestHelpers::Sinatra::CookieSessionMethods
|
|
6
|
-
include ::Sorcery::TestHelpers::Sinatra::InstanceMethods
|
|
7
|
-
|
|
8
|
-
class ::Modular
|
|
9
|
-
class << self
|
|
10
|
-
attr_accessor :sorcery_vars
|
|
11
|
-
end
|
|
12
|
-
@sorcery_vars = {}
|
|
13
|
-
|
|
14
|
-
# NOTE: see before and after test filters in filters.rb
|
|
15
|
-
|
|
16
|
-
def save_instance_vars
|
|
17
|
-
instance_variables.each do |var|
|
|
18
|
-
self.class.sorcery_vars[:"#{var.to_s.delete("@")}"] = instance_variable_get(var)
|
|
19
|
-
end
|
|
20
|
-
end
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
::RSpec::Matchers.define :redirect_to do |expected|
|
|
24
|
-
match do |actual|
|
|
25
|
-
actual.status == 302 && actual.location == expected
|
|
26
|
-
end
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
def clear_user_without_logout
|
|
30
|
-
get_sinatra_app(subject).instance_variable_set(:@current_user, nil)
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
def assigns
|
|
34
|
-
::Modular.sorcery_vars
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
def sorcery_reload!(submodules = [], options = {})
|
|
38
|
-
reload_user_class
|
|
39
|
-
|
|
40
|
-
# return to no-module configuration
|
|
41
|
-
::Sorcery::Controller::Config.init!
|
|
42
|
-
::Sorcery::Controller::Config.reset!
|
|
43
|
-
|
|
44
|
-
# clear all filters
|
|
45
|
-
::Sinatra::Base.instance_variable_set(:@filters, {:before => [], :after => []})
|
|
46
|
-
require File.join(File.dirname(__FILE__), '..', '..', '..', '..', 'spec', 'sinatra', 'filters')
|
|
47
|
-
::Sinatra::Base.send(:include, ::Filters)
|
|
48
|
-
|
|
49
|
-
# configure
|
|
50
|
-
::Sorcery::Controller::Config.submodules = submodules
|
|
51
|
-
::Sorcery::Controller::Config.user_class = nil
|
|
52
|
-
::Sinatra::Base.send(:include, Sorcery::Controller::Adapters::Sinatra)
|
|
53
|
-
::Sinatra::Base.send(:include, Sorcery::Controller)
|
|
54
|
-
::Sorcery::Controller::Config.user_class = "User"
|
|
55
|
-
|
|
56
|
-
::Sorcery::Controller::Config.user_config do |user|
|
|
57
|
-
options.each do |property, value|
|
|
58
|
-
user.send(:"#{property}=", value)
|
|
59
|
-
end
|
|
60
|
-
end
|
|
61
|
-
User.authenticates_with_sorcery!
|
|
62
|
-
end
|
|
63
|
-
|
|
64
|
-
def sorcery_controller_property_set(property, value)
|
|
65
|
-
::Sorcery::Controller::Config.send(:"#{property}=", value)
|
|
66
|
-
end
|
|
67
|
-
|
|
68
|
-
def sorcery_controller_external_property_set(provider, property, value)
|
|
69
|
-
::Sorcery::Controller::Config.send(provider).send(:"#{property}=", value)
|
|
70
|
-
end
|
|
71
|
-
end
|
|
72
|
-
end
|
|
73
|
-
end
|
|
74
|
-
end
|
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
module Sorcery
|
|
2
|
-
module TestHelpers
|
|
3
|
-
module Sinatra
|
|
4
|
-
def self.included(base)
|
|
5
|
-
base.send(:include, InstanceMethods)
|
|
6
|
-
base.send(:include, CookieSessionMethods)
|
|
7
|
-
::Sinatra::Base.class_eval do
|
|
8
|
-
class << self
|
|
9
|
-
attr_accessor :rack_test_session
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
def self.inherited(subclass)
|
|
13
|
-
super
|
|
14
|
-
subclass.class_eval do
|
|
15
|
-
class << self
|
|
16
|
-
attr_accessor :rack_test_session
|
|
17
|
-
end
|
|
18
|
-
end
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
include CookieSessionMethods
|
|
22
|
-
|
|
23
|
-
def rack_test_session
|
|
24
|
-
self.class.rack_test_session
|
|
25
|
-
end
|
|
26
|
-
end
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
module InstanceMethods
|
|
30
|
-
def get_sinatra_app(app)
|
|
31
|
-
while !app.kind_of? ::Sinatra::Base do
|
|
32
|
-
app = app.instance_variable_get(:@app)
|
|
33
|
-
end
|
|
34
|
-
app
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
def login_user(user=nil)
|
|
38
|
-
user ||= @user
|
|
39
|
-
get_sinatra_app(app).send(:login_user, user)
|
|
40
|
-
get_sinatra_app(app).send(:after_login!, user, [user.send(user.sorcery_config.username_attribute_names.first), 'secret'])
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
def logout_user
|
|
44
|
-
get_sinatra_app(app).send(:logout)
|
|
45
|
-
end
|
|
46
|
-
end
|
|
47
|
-
|
|
48
|
-
module CookieSessionMethods
|
|
49
|
-
class SessionData
|
|
50
|
-
def initialize(cookies)
|
|
51
|
-
@cookies = cookies
|
|
52
|
-
@data = cookies['rack.session']
|
|
53
|
-
if @data
|
|
54
|
-
@data = @data.unpack("m*").first
|
|
55
|
-
@data = Marshal.load(@data)
|
|
56
|
-
else
|
|
57
|
-
@data = {}
|
|
58
|
-
end
|
|
59
|
-
end
|
|
60
|
-
|
|
61
|
-
def [](key)
|
|
62
|
-
@data[key]
|
|
63
|
-
end
|
|
64
|
-
|
|
65
|
-
def []=(key, value)
|
|
66
|
-
@data[key] = value
|
|
67
|
-
session_data = Marshal.dump(@data)
|
|
68
|
-
session_data = [session_data].pack("m*")
|
|
69
|
-
@cookies.merge("rack.session=#{Rack::Utils.escape(session_data)}", URI.parse("//example.org//"))
|
|
70
|
-
raise "session variable not set" unless @cookies['rack.session'] == session_data
|
|
71
|
-
end
|
|
72
|
-
|
|
73
|
-
def clear
|
|
74
|
-
@data = {}
|
|
75
|
-
end
|
|
76
|
-
end
|
|
77
|
-
|
|
78
|
-
def session
|
|
79
|
-
SessionData.new(cookies)
|
|
80
|
-
end
|
|
81
|
-
|
|
82
|
-
def cookies
|
|
83
|
-
rack_test_session.instance_variable_get(:@rack_mock_session).cookie_jar
|
|
84
|
-
end
|
|
85
|
-
end
|
|
86
|
-
end
|
|
87
|
-
end
|
|
88
|
-
end
|
data/spec/rails3/Rakefile.unused
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
# Add your own tasks in files placed in lib/tasks ending in .rake,
|
|
2
|
-
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
|
|
3
|
-
|
|
4
|
-
require File.expand_path('../config/application', __FILE__)
|
|
5
|
-
require 'rake'
|
|
6
|
-
|
|
7
|
-
AppRoot::Application.load_tasks
|
data/spec/sinatra/Gemfile
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
source 'http://rubygems.org'
|
|
2
|
-
|
|
3
|
-
gem 'sinatra', '>= 1.2.0'
|
|
4
|
-
gem 'sqlite3-ruby', :require => 'sqlite3'
|
|
5
|
-
gem 'activerecord', '>= 3.0.3'
|
|
6
|
-
gem 'actionmailer', '>= 3.0.3'
|
|
7
|
-
gem "sorcery", '>= 0.1.0', :path => '../../'
|
|
8
|
-
|
|
9
|
-
group :development, :test do
|
|
10
|
-
gem "rake"
|
|
11
|
-
gem "rspec", "~> 2.5.0"
|
|
12
|
-
gem 'ruby-debug19'
|
|
13
|
-
gem 'simplecov', '>= 0.3.8', :require => false # Will install simplecov-html as a dependency
|
|
14
|
-
gem 'timecop'
|
|
15
|
-
end
|
data/spec/sinatra/Gemfile.lock
DELETED
|
@@ -1,115 +0,0 @@
|
|
|
1
|
-
PATH
|
|
2
|
-
remote: ../../
|
|
3
|
-
specs:
|
|
4
|
-
sorcery (0.6.1)
|
|
5
|
-
bcrypt-ruby (~> 3.0.0)
|
|
6
|
-
oauth (~> 0.4.4)
|
|
7
|
-
oauth2 (~> 0.5.0)
|
|
8
|
-
|
|
9
|
-
GEM
|
|
10
|
-
remote: http://rubygems.org/
|
|
11
|
-
specs:
|
|
12
|
-
abstract (1.0.0)
|
|
13
|
-
actionmailer (3.0.5)
|
|
14
|
-
actionpack (= 3.0.5)
|
|
15
|
-
mail (~> 2.2.15)
|
|
16
|
-
actionpack (3.0.5)
|
|
17
|
-
activemodel (= 3.0.5)
|
|
18
|
-
activesupport (= 3.0.5)
|
|
19
|
-
builder (~> 2.1.2)
|
|
20
|
-
erubis (~> 2.6.6)
|
|
21
|
-
i18n (~> 0.4)
|
|
22
|
-
rack (~> 1.2.1)
|
|
23
|
-
rack-mount (~> 0.6.13)
|
|
24
|
-
rack-test (~> 0.5.7)
|
|
25
|
-
tzinfo (~> 0.3.23)
|
|
26
|
-
activemodel (3.0.5)
|
|
27
|
-
activesupport (= 3.0.5)
|
|
28
|
-
builder (~> 2.1.2)
|
|
29
|
-
i18n (~> 0.4)
|
|
30
|
-
activerecord (3.0.5)
|
|
31
|
-
activemodel (= 3.0.5)
|
|
32
|
-
activesupport (= 3.0.5)
|
|
33
|
-
arel (~> 2.0.2)
|
|
34
|
-
tzinfo (~> 0.3.23)
|
|
35
|
-
activesupport (3.0.5)
|
|
36
|
-
addressable (2.2.6)
|
|
37
|
-
archive-tar-minitar (0.5.2)
|
|
38
|
-
arel (2.0.7)
|
|
39
|
-
bcrypt-ruby (3.0.1)
|
|
40
|
-
builder (2.1.2)
|
|
41
|
-
columnize (0.3.2)
|
|
42
|
-
diff-lcs (1.1.2)
|
|
43
|
-
erubis (2.6.6)
|
|
44
|
-
abstract (>= 1.0.0)
|
|
45
|
-
faraday (0.7.4)
|
|
46
|
-
addressable (~> 2.2.6)
|
|
47
|
-
multipart-post (~> 1.1.0)
|
|
48
|
-
rack (< 2, >= 1.1.0)
|
|
49
|
-
i18n (0.5.0)
|
|
50
|
-
linecache19 (0.5.11)
|
|
51
|
-
ruby_core_source (>= 0.1.4)
|
|
52
|
-
mail (2.2.15)
|
|
53
|
-
activesupport (>= 2.3.6)
|
|
54
|
-
i18n (>= 0.4.0)
|
|
55
|
-
mime-types (~> 1.16)
|
|
56
|
-
treetop (~> 1.4.8)
|
|
57
|
-
mime-types (1.16)
|
|
58
|
-
multi_json (1.0.3)
|
|
59
|
-
multipart-post (1.1.3)
|
|
60
|
-
oauth (0.4.5)
|
|
61
|
-
oauth2 (0.5.1)
|
|
62
|
-
faraday (~> 0.7.4)
|
|
63
|
-
multi_json (~> 1.0.3)
|
|
64
|
-
polyglot (0.3.1)
|
|
65
|
-
rack (1.2.1)
|
|
66
|
-
rack-mount (0.6.14)
|
|
67
|
-
rack (>= 1.0.0)
|
|
68
|
-
rack-test (0.5.7)
|
|
69
|
-
rack (>= 1.0)
|
|
70
|
-
rake (0.8.7)
|
|
71
|
-
rspec (2.5.0)
|
|
72
|
-
rspec-core (~> 2.5.0)
|
|
73
|
-
rspec-expectations (~> 2.5.0)
|
|
74
|
-
rspec-mocks (~> 2.5.0)
|
|
75
|
-
rspec-core (2.5.1)
|
|
76
|
-
rspec-expectations (2.5.0)
|
|
77
|
-
diff-lcs (~> 1.1.2)
|
|
78
|
-
rspec-mocks (2.5.0)
|
|
79
|
-
ruby-debug-base19 (0.11.24)
|
|
80
|
-
columnize (>= 0.3.1)
|
|
81
|
-
linecache19 (>= 0.5.11)
|
|
82
|
-
ruby_core_source (>= 0.1.4)
|
|
83
|
-
ruby-debug19 (0.11.6)
|
|
84
|
-
columnize (>= 0.3.1)
|
|
85
|
-
linecache19 (>= 0.5.11)
|
|
86
|
-
ruby-debug-base19 (>= 0.11.19)
|
|
87
|
-
ruby_core_source (0.1.4)
|
|
88
|
-
archive-tar-minitar (>= 0.5.2)
|
|
89
|
-
simplecov (0.3.9)
|
|
90
|
-
simplecov-html (>= 0.3.7)
|
|
91
|
-
simplecov-html (0.3.9)
|
|
92
|
-
sinatra (1.2.0)
|
|
93
|
-
rack (~> 1.1)
|
|
94
|
-
tilt (< 2.0, >= 1.2.2)
|
|
95
|
-
sqlite3-ruby (1.3.2)
|
|
96
|
-
tilt (1.2.2)
|
|
97
|
-
timecop (0.3.5)
|
|
98
|
-
treetop (1.4.9)
|
|
99
|
-
polyglot (>= 0.3.1)
|
|
100
|
-
tzinfo (0.3.24)
|
|
101
|
-
|
|
102
|
-
PLATFORMS
|
|
103
|
-
ruby
|
|
104
|
-
|
|
105
|
-
DEPENDENCIES
|
|
106
|
-
actionmailer (>= 3.0.3)
|
|
107
|
-
activerecord (>= 3.0.3)
|
|
108
|
-
rake
|
|
109
|
-
rspec (~> 2.5.0)
|
|
110
|
-
ruby-debug19
|
|
111
|
-
simplecov (>= 0.3.8)
|
|
112
|
-
sinatra (>= 1.2.0)
|
|
113
|
-
sorcery (>= 0.1.0)!
|
|
114
|
-
sqlite3-ruby
|
|
115
|
-
timecop
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
class AddActivationToUsers < ActiveRecord::Migration
|
|
2
|
-
def self.up
|
|
3
|
-
add_column :users, :activation_state, :string, :default => nil
|
|
4
|
-
add_column :users, :activation_token, :string, :default => nil
|
|
5
|
-
add_column :users, :activation_token_expires_at, :datetime, :default => nil
|
|
6
|
-
|
|
7
|
-
add_index :users, :activation_token
|
|
8
|
-
end
|
|
9
|
-
|
|
10
|
-
def self.down
|
|
11
|
-
remove_index :users, :activation_token
|
|
12
|
-
|
|
13
|
-
remove_column :users, :activation_token_expires_at
|
|
14
|
-
remove_column :users, :activation_token
|
|
15
|
-
remove_column :users, :activation_state
|
|
16
|
-
end
|
|
17
|
-
end
|
data/spec/sinatra/db/migrate/activity_logging/20101224223624_add_activity_logging_to_users.rb
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
class AddActivityLoggingToUsers < ActiveRecord::Migration
|
|
2
|
-
def self.up
|
|
3
|
-
add_column :users, :last_login_at, :datetime, :default => nil
|
|
4
|
-
add_column :users, :last_logout_at, :datetime, :default => nil
|
|
5
|
-
add_column :users, :last_activity_at, :datetime, :default => nil
|
|
6
|
-
|
|
7
|
-
add_index :users, [:last_logout_at, :last_activity_at]
|
|
8
|
-
end
|
|
9
|
-
|
|
10
|
-
def self.down
|
|
11
|
-
remove_index :users, [:last_logout_at, :last_activity_at]
|
|
12
|
-
|
|
13
|
-
remove_column :users, :last_activity_at
|
|
14
|
-
remove_column :users, :last_logout_at
|
|
15
|
-
remove_column :users, :last_login_at
|
|
16
|
-
end
|
|
17
|
-
end
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
class AddBruteForceProtectionToUsers < ActiveRecord::Migration
|
|
2
|
-
def self.up
|
|
3
|
-
add_column :users, :failed_logins_count, :integer, :default => 0
|
|
4
|
-
add_column :users, :lock_expires_at, :datetime, :default => nil
|
|
5
|
-
end
|
|
6
|
-
|
|
7
|
-
def self.down
|
|
8
|
-
remove_column :users, :lock_expires_at
|
|
9
|
-
remove_column :users, :failed_logins_count
|
|
10
|
-
end
|
|
11
|
-
end
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
class CreateUsers < ActiveRecord::Migration
|
|
2
|
-
def self.up
|
|
3
|
-
create_table :users do |t|
|
|
4
|
-
t.string :username, :null => false
|
|
5
|
-
t.string :email, :default => nil
|
|
6
|
-
t.string :crypted_password, :default => nil
|
|
7
|
-
t.string :salt, :default => nil
|
|
8
|
-
|
|
9
|
-
t.timestamps
|
|
10
|
-
end
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
def self.down
|
|
14
|
-
drop_table :users
|
|
15
|
-
end
|
|
16
|
-
end
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
class CreateAuthentications < ActiveRecord::Migration
|
|
2
|
-
def self.up
|
|
3
|
-
create_table :authentications do |t|
|
|
4
|
-
t.integer :user_id, :null => false
|
|
5
|
-
t.string :provider, :uid, :null => false
|
|
6
|
-
|
|
7
|
-
t.timestamps
|
|
8
|
-
end
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
def self.down
|
|
12
|
-
drop_table :authentications
|
|
13
|
-
end
|
|
14
|
-
end
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
class AddRememberMeTokenToUsers < ActiveRecord::Migration
|
|
2
|
-
def self.up
|
|
3
|
-
add_column :users, :remember_me_token, :string, :default => nil
|
|
4
|
-
add_column :users, :remember_me_token_expires_at, :datetime, :default => nil
|
|
5
|
-
|
|
6
|
-
add_index :users, :remember_me_token
|
|
7
|
-
end
|
|
8
|
-
|
|
9
|
-
def self.down
|
|
10
|
-
remove_index :users, :remember_me_token
|
|
11
|
-
|
|
12
|
-
remove_column :users, :remember_me_token_expires_at
|
|
13
|
-
remove_column :users, :remember_me_token
|
|
14
|
-
end
|
|
15
|
-
end
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
class AddResetPasswordToUsers < ActiveRecord::Migration
|
|
2
|
-
def self.up
|
|
3
|
-
add_column :users, :reset_password_token, :string, :default => nil
|
|
4
|
-
add_column :users, :reset_password_token_expires_at, :datetime, :default => nil
|
|
5
|
-
add_column :users, :reset_password_email_sent_at, :datetime, :default => nil
|
|
6
|
-
end
|
|
7
|
-
|
|
8
|
-
def self.down
|
|
9
|
-
remove_column :users, :reset_password_email_sent_at
|
|
10
|
-
remove_column :users, :reset_password_token_expires_at
|
|
11
|
-
remove_column :users, :reset_password_token
|
|
12
|
-
end
|
|
13
|
-
end
|
data/spec/sinatra/filters.rb
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
# --- before filters
|
|
2
|
-
module Filters
|
|
3
|
-
|
|
4
|
-
def self.included(klass)
|
|
5
|
-
klass.class_eval do
|
|
6
|
-
['/test_logout', '/some_action', '/test_should_be_logged_in'].each do |pattern|
|
|
7
|
-
before pattern do
|
|
8
|
-
require_login
|
|
9
|
-
end
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
before '/test_http_basic_auth' do
|
|
13
|
-
require_login_from_http_basic
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
# ----- test filters
|
|
17
|
-
|
|
18
|
-
before do
|
|
19
|
-
self.class.sorcery_vars = {}
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
after do
|
|
23
|
-
save_instance_vars
|
|
24
|
-
end
|
|
25
|
-
end
|
|
26
|
-
end
|
|
27
|
-
end
|