sorcery-couchbase 0.1.1-java

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 020836570ea049d8b5a2591e0720b8fb1b72b953
4
+ data.tar.gz: bad4523ce487ba79cb04b55ef4c7fb4961a3f1aa
5
+ SHA512:
6
+ metadata.gz: d1d8ef8b038f933e9c19452307e2f57c5d7ff2223688cad695217eea985881807388f7068ec2160b913a01c53fd09e4ee6a0dbc5f52f304c7a031547f93ab464
7
+ data.tar.gz: c13f946529c2bd88c212420302d3d715e55b50af94f67be40e86b10a0974ea21b26cc3413479cde98b6bc5f47ce835a35961dbcb99706e4c89f8a62a3d08f8af
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in sorcery-couchbase.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Mike Evans
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # Sorcery::Couchbase
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'sorcery-couchbase'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install sorcery-couchbase
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rake/testtask'
3
+
4
+ Rake::TestTask.new(:test) do |test|
5
+ test.libs << 'test'
6
+ test.pattern = 'test/**/test_*.rb'
7
+ test.verbose = true
8
+ end
9
+
10
+ task :default => :test
@@ -0,0 +1,94 @@
1
+ module Sorcery
2
+
3
+ module CouchbaseModel
4
+ def self.included(klass)
5
+ klass.class_eval do
6
+ class << self
7
+ alias :orig_authenticates_with_sorcery! :authenticates_with_sorcery!
8
+
9
+ def authenticates_with_sorcery!
10
+ orig_authenticates_with_sorcery!
11
+ init_couchbase_support! if defined?(Couchbase) && self.ancestors.include?(Couchbase::Model)
12
+ end
13
+
14
+ protected
15
+
16
+ def init_couchbase_support!
17
+ self.class_eval do
18
+ sorcery_config.username_attribute_names.each do |username|
19
+ attribute username
20
+ end
21
+ attribute sorcery_config.email_attribute_name unless sorcery_config.username_attribute_names.include?(sorcery_config.email_attribute_name)
22
+ attribute sorcery_config.crypted_password_attribute_name
23
+ attribute sorcery_config.salt_attribute_name
24
+ attribute sorcery_config.activation_token_attribute_name if sorcery_config.respond_to? :activation_token_attribute_name
25
+ attribute sorcery_config.activation_state_attribute_name if sorcery_config.respond_to? :activation_token_attribute_name
26
+ attribute sorcery_config.remember_me_token_attribute_name if sorcery_config.respond_to? :remember_me_token_attribute_name
27
+
28
+ if sorcery_config.respond_to? :remember_me_token_expires_at_attribute_name
29
+ attribute sorcery_config.remember_me_token_expires_at_attribute_name
30
+ define_method sorcery_config.remember_me_token_expires_at_attribute_name do
31
+ time = read_attribute(sorcery_config.remember_me_token_expires_at_attribute_name)
32
+ case time
33
+ when Array
34
+ Time.utc *time
35
+ when String
36
+ Time.new time
37
+ else
38
+ raise ArgumentError, 'Remember me token stored incorrectly'
39
+ end
40
+ end
41
+ end
42
+
43
+ view :all
44
+ view *_sorcery_view_attributes.map { |attr| "by_#{attr}" }
45
+ ensure_sorcery_design_document!
46
+ end
47
+ end
48
+
49
+ def ensure_sorcery_design_document!
50
+ bucket.save_design_doc(_sorcery_design_doc)
51
+ end
52
+
53
+ def _sorcery_design_doc
54
+ doc = {
55
+ '_id' => "_design/#{design_document}",
56
+ 'language' => 'javascript',
57
+ 'views' => {
58
+ 'all' => {
59
+ 'map' => <<-JS
60
+ function (doc, meta) {
61
+ if (doc.type && doc.type == '#{design_document}')
62
+ emit(meta.id, null);
63
+ }
64
+ JS
65
+ }
66
+ }
67
+ }
68
+
69
+ _sorcery_view_attributes.each do |attribute|
70
+ doc['views']["by_#{attribute}"] = {
71
+ 'map' => <<-JS
72
+ function (doc, meta) {
73
+ if (doc.type && doc.type == '#{design_document}')
74
+ emit(doc.#{attribute}, null);
75
+ }
76
+ JS
77
+ }
78
+ end
79
+
80
+ doc
81
+ end
82
+
83
+ def _sorcery_view_attributes
84
+ attributes = sorcery_config.username_attribute_names
85
+ attributes << sorcery_config.activation_token_attribute_name if sorcery_config.respond_to? :activation_token_attribute_name
86
+ attributes << sorcery_config.remember_me_token_attribute_name if sorcery_config.respond_to? :remember_me_token_attribute_name
87
+ attributes << sorcery_config.email_attribute_name
88
+ attributes.uniq
89
+ end
90
+ end
91
+ end
92
+ end
93
+ end
94
+ end
@@ -0,0 +1,79 @@
1
+ module Sorcery
2
+ module Model
3
+ module Adapters
4
+ module Couchbase
5
+ def self.included(klass)
6
+ klass.extend ClassMethods
7
+ klass.send(:include, InstanceMethods)
8
+ end
9
+
10
+ module InstanceMethods
11
+ def increment(attr)
12
+ self.write_attribute(attr, self.read_attribute(attr).to_i + 1 )
13
+ end
14
+
15
+ def update_many_attributes(attrs)
16
+ self.update(attrs)
17
+ end
18
+
19
+ def update_single_attribute(name, value)
20
+ update_many_attributes(name => value)
21
+ end
22
+ end
23
+
24
+ module ClassMethods
25
+
26
+ def sorcery_view(view)
27
+ ::Couchbase::View.new(bucket, "_design/#{design_document}/_view/by_#{view}", { wrapper_class: self, include_docs: true })
28
+ end
29
+
30
+ def credential_regex(credential)
31
+ @sorcery_config.downcase_username_before_authenticating ? credential.downcase : credential
32
+ end
33
+
34
+ def find_by_credentials(credentials)
35
+ user = nil
36
+ sorcery_config.username_attribute_names.each do |attribute|
37
+ user = sorcery_view(attribute).fetch(key: credential_regex(credentials[0]), stale: false).first
38
+ break if user
39
+ end
40
+ user
41
+ end
42
+
43
+ def find_by_provider_and_uid(provider, uid)
44
+ @user_klass ||= ::Sorcery::Controller::Config.user_class.to_s.constantize
45
+ where(@user_klass.sorcery_config.provider_attribute_name => provider, @user_klass.sorcery_config.provider_uid_attribute_name => uid).first
46
+ end
47
+
48
+ def find_by_activation_token(token)
49
+ sorcery_view(sorcery_config.activation_token_attribute_name).fetch(key: token, stale: false).first
50
+ end
51
+
52
+ def find_by_remember_me_token(token)
53
+ sorcery_view(sorcery_config.remember_me_token_attribute_name).fetch(key: token, stale: false).first
54
+ end
55
+
56
+ def find_by_username(username)
57
+ find_by_credentials(username)
58
+ end
59
+
60
+
61
+ def find_by_sorcery_token(token_attr_name, token)
62
+ where(token_attr_name => token).first
63
+ end
64
+
65
+ def find_by_email(email)
66
+ where(sorcery_config.email_attribute_name => email).first
67
+ end
68
+
69
+ # def get_current_users
70
+ # config = sorcery_config
71
+ # where(config.last_activity_at_attribute_name.ne => nil) \
72
+ # .where("this.#{config.last_logout_at_attribute_name} == null || this.#{config.last_activity_at_attribute_name} > this.#{config.last_logout_at_attribute_name}") \
73
+ # .where(config.last_activity_at_attribute_name.gt => config.activity_timeout.seconds.ago.utc).order_by([:_id,:asc])
74
+ # end
75
+ end
76
+ end
77
+ end
78
+ end
79
+ end
@@ -0,0 +1,11 @@
1
+ require 'active_model'
2
+ require 'couchbase'
3
+ require 'couchbase/model'
4
+ require 'sorcery_couchbase/version'
5
+ require 'sorcery'
6
+ require 'sorcery/model/adapters/couchbase'
7
+ require 'sorcery/couchbase_model'
8
+
9
+ Couchbase::Model.send(:include, Sorcery::Model)
10
+ Couchbase::Model.send(:include, Sorcery::CouchbaseModel)
11
+ Couchbase::Model.send(:include, Sorcery::Model::Adapters::Couchbase)
@@ -0,0 +1,3 @@
1
+ module SorceryCouchbase
2
+ VERSION = '0.1.1'
3
+ end
@@ -0,0 +1,34 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'sorcery_couchbase/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'sorcery-couchbase'
8
+ spec.version = SorceryCouchbase::VERSION
9
+ spec.authors = ['Mike Evans']
10
+ spec.email = ['mike@urlgonomics.com']
11
+ spec.description = %q{Couchbase backend for the Sorcery authentication framework}
12
+ spec.summary = %q{Couchbase backend for the Sorcery authentication framework}
13
+ spec.homepage = 'https://github.com/mje113/sorcery-couchbase'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ['lib']
20
+ spec.platform = 'java' if defined?(JRUBY_VERSION)
21
+
22
+ spec.add_dependency 'sorcery'
23
+ spec.add_dependency 'activemodel'
24
+ if defined?(JRUBY_VERSION)
25
+ spec.add_dependency 'couchbase-jruby-model', '>= 0.1.0'
26
+ else
27
+ spec.add_dependency 'couchbase-model', '>= 0.5.3'
28
+ end
29
+
30
+ spec.add_development_dependency 'bundler', '~> 1.3'
31
+ spec.add_development_dependency 'rake'
32
+ spec.add_development_dependency 'minitest', '>= 5.0'
33
+ spec.add_development_dependency 'pry'
34
+ end
data/test/helper.rb ADDED
@@ -0,0 +1,46 @@
1
+ gem 'minitest'
2
+ require 'minitest/autorun'
3
+ require 'sorcery_couchbase'
4
+ require 'pry'
5
+
6
+ class MockMailer
7
+ def self.activation_needed_email(user)
8
+ end
9
+
10
+ def self.activation_success_email(user)
11
+ end
12
+ end
13
+
14
+ Sorcery::Controller::Config.submodules = [ :user_activation, :remember_me, :reset_password ]
15
+ Sorcery::Controller::Config.user_config do |user|
16
+ user.user_activation_mailer = MockMailer
17
+ user.reset_password_mailer = MockMailer
18
+ end
19
+
20
+ class TestUser < Couchbase::Model
21
+ authenticates_with_sorcery!
22
+
23
+ attribute :role, default: 'user'
24
+ end
25
+
26
+ Couchbase.bucket.flush
27
+
28
+ Minitest.after_run { Couchbase.disconnect; TestUser.bucket.disconnect }
29
+
30
+ class Minitest::Test
31
+
32
+ def password
33
+ 's3cr3t'
34
+ end
35
+
36
+ def user
37
+ @@user ||= begin
38
+ TestUser.bucket.connect unless TestUser.bucket.connected?
39
+ user = TestUser.create(email: 'bar@example.com')
40
+ user.password = password
41
+ fail unless user.save
42
+ user.activate!
43
+ user
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,30 @@
1
+ require 'helper'
2
+
3
+ class TestCouchbaseAdapter < Minitest::Test
4
+
5
+ def setup
6
+ user
7
+ end
8
+
9
+ def test_initialization
10
+ assert TestUser.new
11
+ end
12
+
13
+ def test_find_by_credentials
14
+ assert_equal user.email, TestUser.find_by_credentials([ user.email ]).email
15
+ end
16
+
17
+ def test_not_found_credentials
18
+ assert_nil TestUser.find_by_credentials([ 'fu@example.com' ])
19
+ end
20
+
21
+ def test_can_authenticate
22
+ TestUser.authenticate(user.email, password)
23
+ assert_equal user.id, TestUser.authenticate(user.email, password).id
24
+ end
25
+
26
+ def test_can_update_atributes
27
+ assert user.update_many_attributes(role: 'admin')
28
+ assert_equal 'admin', user.role
29
+ end
30
+ end
metadata ADDED
@@ -0,0 +1,156 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sorcery-couchbase
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: java
6
+ authors:
7
+ - Mike Evans
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-01-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: sorcery
15
+ version_requirements: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ requirement: !ruby/object:Gem::Requirement
21
+ requirements:
22
+ - - '>='
23
+ - !ruby/object:Gem::Version
24
+ version: '0'
25
+ prerelease: false
26
+ type: :runtime
27
+ - !ruby/object:Gem::Dependency
28
+ name: activemodel
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ requirement: !ruby/object:Gem::Requirement
35
+ requirements:
36
+ - - '>='
37
+ - !ruby/object:Gem::Version
38
+ version: '0'
39
+ prerelease: false
40
+ type: :runtime
41
+ - !ruby/object:Gem::Dependency
42
+ name: couchbase-jruby-model
43
+ version_requirements: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: 0.1.0
48
+ requirement: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - '>='
51
+ - !ruby/object:Gem::Version
52
+ version: 0.1.0
53
+ prerelease: false
54
+ type: :runtime
55
+ - !ruby/object:Gem::Dependency
56
+ name: bundler
57
+ version_requirements: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '1.3'
62
+ requirement: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - ~>
65
+ - !ruby/object:Gem::Version
66
+ version: '1.3'
67
+ prerelease: false
68
+ type: :development
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ version_requirements: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ requirement: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - '>='
79
+ - !ruby/object:Gem::Version
80
+ version: '0'
81
+ prerelease: false
82
+ type: :development
83
+ - !ruby/object:Gem::Dependency
84
+ name: minitest
85
+ version_requirements: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '5.0'
90
+ requirement: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - '>='
93
+ - !ruby/object:Gem::Version
94
+ version: '5.0'
95
+ prerelease: false
96
+ type: :development
97
+ - !ruby/object:Gem::Dependency
98
+ name: pry
99
+ version_requirements: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ requirement: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - '>='
107
+ - !ruby/object:Gem::Version
108
+ version: '0'
109
+ prerelease: false
110
+ type: :development
111
+ description: Couchbase backend for the Sorcery authentication framework
112
+ email:
113
+ - mike@urlgonomics.com
114
+ executables: []
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - .gitignore
119
+ - Gemfile
120
+ - LICENSE.txt
121
+ - README.md
122
+ - Rakefile
123
+ - lib/sorcery/couchbase_model.rb
124
+ - lib/sorcery/model/adapters/couchbase.rb
125
+ - lib/sorcery_couchbase.rb
126
+ - lib/sorcery_couchbase/version.rb
127
+ - sorcery-couchbase.gemspec
128
+ - test/helper.rb
129
+ - test/test_couchbase_adapter.rb
130
+ homepage: https://github.com/mje113/sorcery-couchbase
131
+ licenses:
132
+ - MIT
133
+ metadata: {}
134
+ post_install_message:
135
+ rdoc_options: []
136
+ require_paths:
137
+ - lib
138
+ required_ruby_version: !ruby/object:Gem::Requirement
139
+ requirements:
140
+ - - '>='
141
+ - !ruby/object:Gem::Version
142
+ version: '0'
143
+ required_rubygems_version: !ruby/object:Gem::Requirement
144
+ requirements:
145
+ - - '>='
146
+ - !ruby/object:Gem::Version
147
+ version: '0'
148
+ requirements: []
149
+ rubyforge_project:
150
+ rubygems_version: 2.1.9
151
+ signing_key:
152
+ specification_version: 4
153
+ summary: Couchbase backend for the Sorcery authentication framework
154
+ test_files:
155
+ - test/helper.rb
156
+ - test/test_couchbase_adapter.rb