hobo_devise 0.0.2
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/.document +5 -0
- data/.gitignore +21 -0
- data/LICENSE +20 -0
- data/README +40 -0
- data/Rakefile +54 -0
- data/VERSION +1 -0
- data/hobo_devise.gemspec +62 -0
- data/lib/hobo_devise/database_authenticable.rb +45 -0
- data/lib/hobo_devise/devise_oauth2_facebook.rb +11 -0
- data/lib/hobo_devise.rb +54 -0
- data/test/helper.rb +10 -0
- data/test/test_hobo_devise.rb +7 -0
- metadata +126 -0
data/.document
ADDED
data/.gitignore
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Joachim Filip Ignacy Bartosik
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
For now there is a number of things you need to do to use this gem:
|
2
|
+
1) Create your hobo application
|
3
|
+
2) In your user model rename field
|
4
|
+
|
5
|
+
email_address
|
6
|
+
|
7
|
+
to
|
8
|
+
|
9
|
+
email
|
10
|
+
|
11
|
+
3) Edit your mailers and lifecycles to use
|
12
|
+
|
13
|
+
email
|
14
|
+
|
15
|
+
field, not
|
16
|
+
|
17
|
+
email_address
|
18
|
+
|
19
|
+
4) In your user model replace
|
20
|
+
|
21
|
+
hobo_devise_user_model
|
22
|
+
|
23
|
+
with
|
24
|
+
|
25
|
+
hobo_devise_user_model :auth_methods => [:database_authenticable,
|
26
|
+
:devise_oauth2_facebook]
|
27
|
+
|
28
|
+
5) In your users controller replace
|
29
|
+
|
30
|
+
hobo_user_controller
|
31
|
+
|
32
|
+
with
|
33
|
+
|
34
|
+
hobo_devise_oauth2_facebook_controller(YourUserModelName)
|
35
|
+
|
36
|
+
6) Add routes in config/routes.rb
|
37
|
+
|
38
|
+
match 'user_fb_auth', :controller => 'your_model_name', :action => 'auth', :as => "user_fb_auth"
|
39
|
+
match 'user_fb_callback', :controller => 'your_model_name', :action => 'callback', :as => "user_fb_callback"
|
40
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "hobo_devise"
|
8
|
+
gem.summary = "Gem that adds devise based authentication to hobo-based applications"
|
9
|
+
gem.description = ""
|
10
|
+
gem.email = "jbartosik@gmail.com"
|
11
|
+
gem.homepage = "http://github.com/ahenobarbi/hobo_devise"
|
12
|
+
gem.authors = ["Joachim Filip Ignacy Bartosik"]
|
13
|
+
gem.add_dependency "hobo", ">= 1.3.0.pre28"
|
14
|
+
gem.add_dependency "devise", ">= 1.1.7"
|
15
|
+
gem.add_dependency "devise_oauth2_facebook"
|
16
|
+
end
|
17
|
+
Jeweler::GemcutterTasks.new
|
18
|
+
rescue LoadError
|
19
|
+
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
20
|
+
end
|
21
|
+
|
22
|
+
require 'rake/testtask'
|
23
|
+
Rake::TestTask.new(:test) do |test|
|
24
|
+
test.libs << 'lib' << 'test'
|
25
|
+
test.pattern = 'test/**/test_*.rb'
|
26
|
+
test.verbose = true
|
27
|
+
end
|
28
|
+
|
29
|
+
begin
|
30
|
+
require 'rcov/rcovtask'
|
31
|
+
Rcov::RcovTask.new do |test|
|
32
|
+
test.libs << 'test'
|
33
|
+
test.pattern = 'test/**/test_*.rb'
|
34
|
+
test.verbose = true
|
35
|
+
end
|
36
|
+
rescue LoadError
|
37
|
+
task :rcov do
|
38
|
+
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
task :test => :check_dependencies
|
43
|
+
|
44
|
+
task :default => :test
|
45
|
+
|
46
|
+
require 'rake/rdoctask'
|
47
|
+
Rake::RDocTask.new do |rdoc|
|
48
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
49
|
+
|
50
|
+
rdoc.rdoc_dir = 'rdoc'
|
51
|
+
rdoc.title = "hobo_devise #{version}"
|
52
|
+
rdoc.rdoc_files.include('README')
|
53
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
54
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.2
|
data/hobo_devise.gemspec
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{hobo_devise}
|
8
|
+
s.version = "0.0.2"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Joachim Filip Ignacy Bartosik"]
|
12
|
+
s.date = %q{2011-05-10}
|
13
|
+
s.description = %q{}
|
14
|
+
s.email = %q{jbartosik@gmail.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE",
|
17
|
+
"README"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
".gitignore",
|
22
|
+
"LICENSE",
|
23
|
+
"README",
|
24
|
+
"Rakefile",
|
25
|
+
"VERSION",
|
26
|
+
"hobo_devise.gemspec",
|
27
|
+
"lib/hobo_devise.rb",
|
28
|
+
"lib/hobo_devise/database_authenticable.rb",
|
29
|
+
"lib/hobo_devise/devise_oauth2_facebook.rb",
|
30
|
+
"test/helper.rb",
|
31
|
+
"test/test_hobo_devise.rb"
|
32
|
+
]
|
33
|
+
s.homepage = %q{http://github.com/ahenobarbi/hobo_devise}
|
34
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
35
|
+
s.require_paths = ["lib"]
|
36
|
+
s.rubygems_version = %q{1.3.7}
|
37
|
+
s.summary = %q{Gem that adds devise based authentication to hobo-based applications}
|
38
|
+
s.test_files = [
|
39
|
+
"test/test_hobo_devise.rb",
|
40
|
+
"test/helper.rb"
|
41
|
+
]
|
42
|
+
|
43
|
+
if s.respond_to? :specification_version then
|
44
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
45
|
+
s.specification_version = 3
|
46
|
+
|
47
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
48
|
+
s.add_runtime_dependency(%q<hobo>, [">= 1.3.0.pre28"])
|
49
|
+
s.add_runtime_dependency(%q<devise>, [">= 1.1.7"])
|
50
|
+
s.add_runtime_dependency(%q<devise_oauth2_facebook>, [">= 0"])
|
51
|
+
else
|
52
|
+
s.add_dependency(%q<hobo>, [">= 1.3.0.pre28"])
|
53
|
+
s.add_dependency(%q<devise>, [">= 1.1.7"])
|
54
|
+
s.add_dependency(%q<devise_oauth2_facebook>, [">= 0"])
|
55
|
+
end
|
56
|
+
else
|
57
|
+
s.add_dependency(%q<hobo>, [">= 1.3.0.pre28"])
|
58
|
+
s.add_dependency(%q<devise>, [">= 1.1.7"])
|
59
|
+
s.add_dependency(%q<devise_oauth2_facebook>, [">= 0"])
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
@@ -0,0 +1,45 @@
|
|
1
|
+
module HoboDevise
|
2
|
+
def self.database_authenticable(model)
|
3
|
+
model.class_eval do
|
4
|
+
devise :database_authenticatable
|
5
|
+
|
6
|
+
# Devise uses longer fields then Hobo for passwords
|
7
|
+
fields do
|
8
|
+
crypted_password :string, :limit => 60
|
9
|
+
end
|
10
|
+
|
11
|
+
def password=(new_password)
|
12
|
+
@password = new_password
|
13
|
+
self.encrypted_password = password_digest(@password) if @password.present?
|
14
|
+
end
|
15
|
+
|
16
|
+
# Hobo shouldn't be able to access crypted_password or perform it's own password validation
|
17
|
+
def crypted_password; end
|
18
|
+
def crypted_password=(n); end
|
19
|
+
def validate_current_password_when_changing_password; end
|
20
|
+
|
21
|
+
# Some aliases for devise
|
22
|
+
def password_salt; salt; end
|
23
|
+
def password_salt=(n); salt=n; end
|
24
|
+
def encrypted_password; read_attribute(:crypted_password); end
|
25
|
+
def encrypted_password=(n); write_attribute(:crypted_password, n); end
|
26
|
+
|
27
|
+
## This is c&p from devise sources. I'm not sure why, but it's necessary
|
28
|
+
require 'bcrypt'
|
29
|
+
def password_digest(password)
|
30
|
+
::BCrypt::Password.create("#{password}#{self.class.pepper}", :cost => self.class.stretches).to_s
|
31
|
+
end
|
32
|
+
|
33
|
+
def valid_password?(password)
|
34
|
+
bcrypt = ::BCrypt::Password.new(self.encrypted_password)
|
35
|
+
password = ::BCrypt::Engine.hash_secret("#{password}#{self.class.pepper}", bcrypt.salt)
|
36
|
+
Devise.secure_compare(password, self.encrypted_password)
|
37
|
+
end
|
38
|
+
|
39
|
+
def authenticated?(password)
|
40
|
+
self.valid_password?(password)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
end
|
data/lib/hobo_devise.rb
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'hobo_devise/database_authenticable.rb'
|
2
|
+
require 'hobo_devise/devise_oauth2_facebook.rb'
|
3
|
+
|
4
|
+
class ActiveRecord::Base
|
5
|
+
def self.hobo_devise_user_model(opts={})
|
6
|
+
|
7
|
+
self.class_eval do
|
8
|
+
hobo_user_model
|
9
|
+
fields do
|
10
|
+
email :email_address, :login => true
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
opts.reverse_merge!({ :auth_methods => :database_authenticatable })
|
15
|
+
|
16
|
+
user_class = self
|
17
|
+
|
18
|
+
if opts[:auth_methods].is_a? Array
|
19
|
+
for auth_method in opts[:auth_methods]
|
20
|
+
HoboDevise.send(auth_method, user_class) if HoboDevise.methods.include? auth_method.to_s
|
21
|
+
end
|
22
|
+
else
|
23
|
+
auth_method = opts[:auth_methods]
|
24
|
+
HoboDevise.send(auth_method, user_class) if HoboDevise.methods.include? auth_method.to_s
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
class ActionController::Base
|
31
|
+
def self.hobo_devise_oauth2_facebook_controller(model)
|
32
|
+
@@model = model
|
33
|
+
self.class_eval do
|
34
|
+
hobo_user_controller
|
35
|
+
include DeviseOauth2Facebook::FacebookConsumerHelper
|
36
|
+
include DeviseOauth2Facebook::ControllerMethods
|
37
|
+
|
38
|
+
def resource_name; @@model.to_s.downcase; end
|
39
|
+
def resource_class; @@model; end
|
40
|
+
def initialize; action_methods.add "callback"; end
|
41
|
+
|
42
|
+
def set_flash_message(type, message)
|
43
|
+
flash[type] = message
|
44
|
+
end
|
45
|
+
|
46
|
+
def sign_in_and_redirect(resource_name, user)
|
47
|
+
redirect_to "/"
|
48
|
+
options = {:notice => ht(:"#{model.to_s.underscore}.messages.logout", :default=>["You have logged out."]),
|
49
|
+
:redirect_to => base_url}
|
50
|
+
sign_user_in(user, options)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
data/test/helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,126 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: hobo_devise
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 27
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 2
|
10
|
+
version: 0.0.2
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Joachim Filip Ignacy Bartosik
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-05-10 00:00:00 +02:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: hobo
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: -1637108434
|
30
|
+
segments:
|
31
|
+
- 1
|
32
|
+
- 3
|
33
|
+
- 0
|
34
|
+
- pre28
|
35
|
+
version: 1.3.0.pre28
|
36
|
+
type: :runtime
|
37
|
+
version_requirements: *id001
|
38
|
+
- !ruby/object:Gem::Dependency
|
39
|
+
name: devise
|
40
|
+
prerelease: false
|
41
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
42
|
+
none: false
|
43
|
+
requirements:
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
hash: 29
|
47
|
+
segments:
|
48
|
+
- 1
|
49
|
+
- 1
|
50
|
+
- 7
|
51
|
+
version: 1.1.7
|
52
|
+
type: :runtime
|
53
|
+
version_requirements: *id002
|
54
|
+
- !ruby/object:Gem::Dependency
|
55
|
+
name: devise_oauth2_facebook
|
56
|
+
prerelease: false
|
57
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
58
|
+
none: false
|
59
|
+
requirements:
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
hash: 3
|
63
|
+
segments:
|
64
|
+
- 0
|
65
|
+
version: "0"
|
66
|
+
type: :runtime
|
67
|
+
version_requirements: *id003
|
68
|
+
description: ""
|
69
|
+
email: jbartosik@gmail.com
|
70
|
+
executables: []
|
71
|
+
|
72
|
+
extensions: []
|
73
|
+
|
74
|
+
extra_rdoc_files:
|
75
|
+
- LICENSE
|
76
|
+
- README
|
77
|
+
files:
|
78
|
+
- .document
|
79
|
+
- .gitignore
|
80
|
+
- LICENSE
|
81
|
+
- README
|
82
|
+
- Rakefile
|
83
|
+
- VERSION
|
84
|
+
- hobo_devise.gemspec
|
85
|
+
- lib/hobo_devise.rb
|
86
|
+
- lib/hobo_devise/database_authenticable.rb
|
87
|
+
- lib/hobo_devise/devise_oauth2_facebook.rb
|
88
|
+
- test/helper.rb
|
89
|
+
- test/test_hobo_devise.rb
|
90
|
+
has_rdoc: true
|
91
|
+
homepage: http://github.com/ahenobarbi/hobo_devise
|
92
|
+
licenses: []
|
93
|
+
|
94
|
+
post_install_message:
|
95
|
+
rdoc_options:
|
96
|
+
- --charset=UTF-8
|
97
|
+
require_paths:
|
98
|
+
- lib
|
99
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
100
|
+
none: false
|
101
|
+
requirements:
|
102
|
+
- - ">="
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
hash: 3
|
105
|
+
segments:
|
106
|
+
- 0
|
107
|
+
version: "0"
|
108
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
109
|
+
none: false
|
110
|
+
requirements:
|
111
|
+
- - ">="
|
112
|
+
- !ruby/object:Gem::Version
|
113
|
+
hash: 3
|
114
|
+
segments:
|
115
|
+
- 0
|
116
|
+
version: "0"
|
117
|
+
requirements: []
|
118
|
+
|
119
|
+
rubyforge_project:
|
120
|
+
rubygems_version: 1.3.7
|
121
|
+
signing_key:
|
122
|
+
specification_version: 3
|
123
|
+
summary: Gem that adds devise based authentication to hobo-based applications
|
124
|
+
test_files:
|
125
|
+
- test/test_hobo_devise.rb
|
126
|
+
- test/helper.rb
|