deadbolt 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'http://rubygems.org'
2
+
3
+ gem 'mongo_mapper'
4
+ gem 'bcrypt-ruby'
data/Gemfile.lock ADDED
@@ -0,0 +1,27 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ activemodel (3.0.7)
5
+ activesupport (= 3.0.7)
6
+ builder (~> 2.1.2)
7
+ i18n (~> 0.5.0)
8
+ activesupport (3.0.7)
9
+ bcrypt-ruby (2.1.4)
10
+ bson (1.3.0)
11
+ builder (2.1.2)
12
+ i18n (0.5.0)
13
+ mongo (1.3.0)
14
+ bson (>= 1.3.0)
15
+ mongo_mapper (0.9.0)
16
+ activemodel (~> 3.0.0)
17
+ activesupport (~> 3.0.0)
18
+ plucky (~> 0.3.6)
19
+ plucky (0.3.8)
20
+ mongo (~> 1.3)
21
+
22
+ PLATFORMS
23
+ ruby
24
+
25
+ DEPENDENCIES
26
+ bcrypt-ruby
27
+ mongo_mapper
data/LICENSE.txt ADDED
@@ -0,0 +1,19 @@
1
+ Copyright (c) 2011 J-P Teti
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in
11
+ all copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ THE SOFTWARE.
data/Manifest ADDED
@@ -0,0 +1,8 @@
1
+ Gemfile
2
+ Gemfile.lock
3
+ LICENSE.txt
4
+ Manifest
5
+ README.md
6
+ README.rdoc
7
+ Rakefile
8
+ lib/deadbolt.rb
data/README.md ADDED
@@ -0,0 +1,42 @@
1
+ deadbolt
2
+ ===================================================
3
+
4
+ Deadbolt is a plugin for MongoMapper that lets you easily create super simple (and secure) user models.
5
+
6
+ Usage
7
+ ---------------------------
8
+
9
+ Using deadbolt is really easy. Just require it in your gemfile (gem 'deadbolt'). Then write your user model like this:
10
+
11
+ require 'bcrypt'
12
+
13
+ class User
14
+ include MongoMapper::Document
15
+ plugin Deadbolt
16
+ end
17
+
18
+ That's all you have to do.
19
+
20
+ Assumptions
21
+ ---------------------------
22
+ Deadbolt assumes that:
23
+
24
+ * You want users to confirm their password.
25
+ * Your users are identified by their email address.
26
+
27
+ It **does not** assume that you want to validate the uniqueness of each user's email address. If do you want to, simply add the line `validates_uniqueness_of :email` to your model. You can add whatever other keys and validations you want to your model.
28
+
29
+ To check that a user successfully logged in, use `User.authenticate(email, password)`. Assuming that the email and password match up, this will return the full user object, including any custom data you've defined. If the email and password do not match up, it will return `nil`.
30
+
31
+ Contributing
32
+ ---------------------------
33
+
34
+ 1. Fork the project.
35
+ 2. Make whatever changes you plan on making.
36
+ 3. Submit a pull request that accurately describes what you've added or changed and why. NOTE: This does not mean to say *how* you did it. I can read the code.
37
+
38
+ Credits
39
+ ---------------------------
40
+ Original code by J-P Teti.
41
+
42
+ Special thanks to John Nunemaker for creating MongoMapper and to everyone who has contributed to that project.
data/README.rdoc ADDED
@@ -0,0 +1,40 @@
1
+ = deadbolt
2
+
3
+ Deadbolt is a plugin for MongoMapper that lets you easily create super simple (and secure) user models.
4
+
5
+ = Usage
6
+
7
+ Using deadbolt is really easy. Just require it in your gemfile (<tt>gem 'deadbolt'</tt>). Then write your user model like this:
8
+
9
+ require 'bcrypt'
10
+
11
+ class User
12
+ include MongoMapper::Document
13
+ plugin Deadbolt
14
+ end
15
+
16
+ That's it!
17
+
18
+ = Assumptions
19
+ Deadbolt assumes that:
20
+
21
+ * You want users to confirm their password.
22
+ * Your users are identified by their email address.
23
+
24
+ It **does not** assume that you want to validate the uniqueness of each user's email address. If do you want to, simply add the line <tt>validates_uniqueness_of :email</tt> to your model. You can add whatever other keys and validations you want to your model.
25
+
26
+ To check that a user successfully logged in, use <tt>User.authenticate(email, password)</tt>. Assuming that the email and password match up, this will return the full user object, including any custom data you've defined. If the email and password do not match up, it will return <tt>nil</tt>.
27
+
28
+ = Contributing
29
+
30
+ 1. Fork the project.
31
+ 2. Make whatever changes you plan on making.
32
+ 3. Submit a pull request that accurately describes what you've added or changed and why. NOTE: This does not mean to say <i>how</i> you did it. I can read the code.
33
+
34
+ = Credits
35
+
36
+ Written by J-P Teti.
37
+ Special thanks to John Nunemaker for creating MongoMapper and to everyone who has contributed to that project.
38
+
39
+ = License
40
+ Licensed under the MIT License, which is found in the file LICENSE.txt. In short: do whatever you feel like with this code.
data/Rakefile ADDED
@@ -0,0 +1,15 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+ require 'echoe'
4
+
5
+ Echoe.new('deadbolt', '0.1.1') do |g|
6
+ g.description = 'Very basic user model as a MongoMapper plugin'
7
+ g.url = 'http://github.com/roboteti/deadbolt'
8
+ g.author = 'J-P Teti'
9
+ g.email = 'roboteti@gmail.com'
10
+ g.ignore_pattern = []
11
+ g.development_dependencies = ['mongo_mapper', 'bcrypt-ruby']
12
+ g.runtime_dependencies = ['mongo_mapper', 'bcrypt-ruby']
13
+ end
14
+
15
+ Dir["#{File.dirname(__FILE__)}/tasks/*.rake"].sort.each { |ext| load ext }
data/deadbolt.gemspec ADDED
@@ -0,0 +1,41 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{deadbolt}
5
+ s.version = "0.1.1"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["J-P Teti"]
9
+ s.date = %q{2011-04-27}
10
+ s.description = %q{Very basic user model as a MongoMapper plugin}
11
+ s.email = %q{roboteti@gmail.com}
12
+ s.extra_rdoc_files = ["LICENSE.txt", "README.md", "README.rdoc", "lib/deadbolt.rb"]
13
+ s.files = ["Gemfile", "Gemfile.lock", "LICENSE.txt", "Manifest", "README.md", "README.rdoc", "Rakefile", "lib/deadbolt.rb", "deadbolt.gemspec"]
14
+ s.homepage = %q{http://github.com/roboteti/deadbolt}
15
+ s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Deadbolt", "--main", "README.md"]
16
+ s.require_paths = ["lib"]
17
+ s.rubyforge_project = %q{deadbolt}
18
+ s.rubygems_version = %q{1.7.2}
19
+ s.summary = %q{Very basic user model as a MongoMapper plugin}
20
+
21
+ if s.respond_to? :specification_version then
22
+ s.specification_version = 3
23
+
24
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
25
+ s.add_runtime_dependency(%q<mongo_mapper>, [">= 0"])
26
+ s.add_runtime_dependency(%q<bcrypt-ruby>, [">= 0"])
27
+ s.add_development_dependency(%q<mongo_mapper>, [">= 0"])
28
+ s.add_development_dependency(%q<bcrypt-ruby>, [">= 0"])
29
+ else
30
+ s.add_dependency(%q<mongo_mapper>, [">= 0"])
31
+ s.add_dependency(%q<bcrypt-ruby>, [">= 0"])
32
+ s.add_dependency(%q<mongo_mapper>, [">= 0"])
33
+ s.add_dependency(%q<bcrypt-ruby>, [">= 0"])
34
+ end
35
+ else
36
+ s.add_dependency(%q<mongo_mapper>, [">= 0"])
37
+ s.add_dependency(%q<bcrypt-ruby>, [">= 0"])
38
+ s.add_dependency(%q<mongo_mapper>, [">= 0"])
39
+ s.add_dependency(%q<bcrypt-ruby>, [">= 0"])
40
+ end
41
+ end
data/lib/deadbolt.rb ADDED
@@ -0,0 +1,36 @@
1
+ module Deadbolt
2
+ extend ActiveSupport::Concern
3
+
4
+ included do
5
+ attr_accessor :password
6
+ attr_protected :password_hash, :password_salt
7
+
8
+ before_save :encrypt_password
9
+
10
+ key :email, String, :required => true
11
+ key :password_hash, String
12
+ key :password_salt, String
13
+
14
+ validates_presence_of :password
15
+ validates_confirmation_of :password
16
+
17
+ self.ensure_index(:email)
18
+
19
+ def self.authenticate(email, password)
20
+ user = find_by_email(email)
21
+ if user && user.password_hash == BCrypt::Engine.hash_secret(password, user.password_salt)
22
+ user
23
+ else
24
+ nil
25
+ end
26
+ end
27
+
28
+ def encrypt_password
29
+ if password.present?
30
+ self.password_salt = BCrypt::Engine.generate_salt
31
+ self.password_hash = BCrypt::Engine.hash_secret(password, password_salt)
32
+ end
33
+ end
34
+ end
35
+
36
+ end
metadata ADDED
@@ -0,0 +1,137 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: deadbolt
3
+ version: !ruby/object:Gem::Version
4
+ hash: 25
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 1
10
+ version: 0.1.1
11
+ platform: ruby
12
+ authors:
13
+ - J-P Teti
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-04-27 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: mongo_mapper
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ hash: 3
29
+ segments:
30
+ - 0
31
+ version: "0"
32
+ type: :runtime
33
+ version_requirements: *id001
34
+ - !ruby/object:Gem::Dependency
35
+ name: bcrypt-ruby
36
+ prerelease: false
37
+ requirement: &id002 !ruby/object:Gem::Requirement
38
+ none: false
39
+ requirements:
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ hash: 3
43
+ segments:
44
+ - 0
45
+ version: "0"
46
+ type: :runtime
47
+ version_requirements: *id002
48
+ - !ruby/object:Gem::Dependency
49
+ name: mongo_mapper
50
+ prerelease: false
51
+ requirement: &id003 !ruby/object:Gem::Requirement
52
+ none: false
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ hash: 3
57
+ segments:
58
+ - 0
59
+ version: "0"
60
+ type: :development
61
+ version_requirements: *id003
62
+ - !ruby/object:Gem::Dependency
63
+ name: bcrypt-ruby
64
+ prerelease: false
65
+ requirement: &id004 !ruby/object:Gem::Requirement
66
+ none: false
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ hash: 3
71
+ segments:
72
+ - 0
73
+ version: "0"
74
+ type: :development
75
+ version_requirements: *id004
76
+ description: Very basic user model as a MongoMapper plugin
77
+ email: roboteti@gmail.com
78
+ executables: []
79
+
80
+ extensions: []
81
+
82
+ extra_rdoc_files:
83
+ - LICENSE.txt
84
+ - README.md
85
+ - README.rdoc
86
+ - lib/deadbolt.rb
87
+ files:
88
+ - Gemfile
89
+ - Gemfile.lock
90
+ - LICENSE.txt
91
+ - Manifest
92
+ - README.md
93
+ - README.rdoc
94
+ - Rakefile
95
+ - lib/deadbolt.rb
96
+ - deadbolt.gemspec
97
+ homepage: http://github.com/roboteti/deadbolt
98
+ licenses: []
99
+
100
+ post_install_message:
101
+ rdoc_options:
102
+ - --line-numbers
103
+ - --inline-source
104
+ - --title
105
+ - Deadbolt
106
+ - --main
107
+ - README.md
108
+ require_paths:
109
+ - lib
110
+ required_ruby_version: !ruby/object:Gem::Requirement
111
+ none: false
112
+ requirements:
113
+ - - ">="
114
+ - !ruby/object:Gem::Version
115
+ hash: 3
116
+ segments:
117
+ - 0
118
+ version: "0"
119
+ required_rubygems_version: !ruby/object:Gem::Requirement
120
+ none: false
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ hash: 11
125
+ segments:
126
+ - 1
127
+ - 2
128
+ version: "1.2"
129
+ requirements: []
130
+
131
+ rubyforge_project: deadbolt
132
+ rubygems_version: 1.7.2
133
+ signing_key:
134
+ specification_version: 3
135
+ summary: Very basic user model as a MongoMapper plugin
136
+ test_files: []
137
+