merb-auth 0.1.0 → 0.9.9
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +1 -1
- data/README.textile +90 -0
- data/Rakefile +82 -38
- data/TODO +0 -0
- data/lib/merb-auth.rb +4 -72
- metadata +48 -50
- data/README +0 -64
- data/app/controllers/application.rb +0 -4
- data/app/controllers/controller_mixin.rb +0 -150
- data/app/controllers/users.rb +0 -41
- data/app/helpers/application_helper.rb +0 -64
- data/app/views/layout/merb_auth.html.erb +0 -47
- data/app/views/users/login.html.erb +0 -31
- data/app/views/users/signup.html.erb +0 -29
- data/lib/merb-auth/adapter/activerecord.rb +0 -52
- data/lib/merb-auth/adapter/datamapper.rb +0 -78
- data/lib/merb-auth/merbtasks.rb +0 -166
- data/lib/merb-auth/model.rb +0 -80
- data/lib/merb-auth/slicetasks.rb +0 -18
- data/public/stylesheets/master.css +0 -157
- data/spec/controllers/router_spec.rb +0 -29
- data/spec/controllers/session_spec.rb +0 -87
- data/spec/controllers/users_spec.rb +0 -41
- data/spec/controllers/view_helper_spec.rb +0 -27
- data/spec/merb-auth_spec.rb +0 -52
- data/spec/models/ar_user_spec.rb +0 -20
- data/spec/models/dm_user_spec.rb +0 -22
- data/spec/models/shared_user_spec.rb +0 -251
- data/spec/spec_helper.rb +0 -42
data/lib/merb-auth/merbtasks.rb
DELETED
@@ -1,166 +0,0 @@
|
|
1
|
-
namespace :slices do
|
2
|
-
namespace :merb_auth do
|
3
|
-
|
4
|
-
desc "Install MerbAuth"
|
5
|
-
task :install => [:preflight, :setup_directories, :copy_assets, :migrate]
|
6
|
-
|
7
|
-
desc "Test for any dependencies"
|
8
|
-
task :preflight do # see slicetasks.rb
|
9
|
-
end
|
10
|
-
|
11
|
-
desc "Setup directories"
|
12
|
-
task :setup_directories do
|
13
|
-
puts "Creating directories for host application"
|
14
|
-
MerbAuth.mirrored_components.each do |type|
|
15
|
-
if File.directory?(MerbAuth.dir_for(type))
|
16
|
-
if !File.directory?(dst_path = MerbAuth.app_dir_for(type))
|
17
|
-
relative_path = dst_path.relative_path_from(Merb.root)
|
18
|
-
puts "- creating directory :#{type} #{File.basename(Merb.root) / relative_path}"
|
19
|
-
mkdir_p(dst_path)
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
desc "Copy stub files to host application"
|
26
|
-
task :stubs do
|
27
|
-
puts "Copying stubs for MerbAuth - resolves any collisions"
|
28
|
-
copied, preserved = MerbAuth.mirror_stubs!
|
29
|
-
puts "- no files to copy" if copied.empty? && preserved.empty?
|
30
|
-
copied.each { |f| puts "- copied #{f}" }
|
31
|
-
preserved.each { |f| puts "! preserved override as #{f}" }
|
32
|
-
end
|
33
|
-
|
34
|
-
desc "Copy stub files and views to host application"
|
35
|
-
task :patch => [ "stubs", "freeze:views" ]
|
36
|
-
|
37
|
-
desc "Copy public assets to host application"
|
38
|
-
task :copy_assets do
|
39
|
-
puts "Copying assets for MerbAuth - resolves any collisions"
|
40
|
-
copied, preserved = MerbAuth.mirror_public!
|
41
|
-
puts "- no files to copy" if copied.empty? && preserved.empty?
|
42
|
-
copied.each { |f| puts "- copied #{f}" }
|
43
|
-
preserved.each { |f| puts "! preserved override as #{f}" }
|
44
|
-
end
|
45
|
-
|
46
|
-
desc "Migrate the database"
|
47
|
-
task :migrate do # see slicetasks.rb
|
48
|
-
end
|
49
|
-
|
50
|
-
desc "Freeze MerbAuth into your app (only merb-auth/app)"
|
51
|
-
task :freeze => [ "freeze:app" ]
|
52
|
-
|
53
|
-
namespace :freeze do
|
54
|
-
|
55
|
-
desc "Freezes MerbAuth by installing the gem into application/gems using merb-freezer"
|
56
|
-
task :gem do
|
57
|
-
begin
|
58
|
-
Object.const_get(:Freezer).freeze(ENV["GEM"] || "merb-auth", ENV["UPDATE"], ENV["MODE"] || 'rubygems')
|
59
|
-
rescue NameError
|
60
|
-
puts "! dependency 'merb-freezer' missing"
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
desc "Freezes MerbAuth by copying all files from merb-auth/app to your application"
|
65
|
-
task :app do
|
66
|
-
puts "Copying all merb-auth/app files to your application - resolves any collisions"
|
67
|
-
copied, preserved = MerbAuth.mirror_app!
|
68
|
-
puts "- no files to copy" if copied.empty? && preserved.empty?
|
69
|
-
copied.each { |f| puts "- copied #{f}" }
|
70
|
-
preserved.each { |f| puts "! preserved override as #{f}" }
|
71
|
-
end
|
72
|
-
|
73
|
-
desc "Freeze all views into your application for easy modification"
|
74
|
-
task :views do
|
75
|
-
puts "Copying all view templates to your application - resolves any collisions"
|
76
|
-
copied, preserved = MerbAuth.mirror_files_for :view
|
77
|
-
puts "- no files to copy" if copied.empty? && preserved.empty?
|
78
|
-
copied.each { |f| puts "- copied #{f}" }
|
79
|
-
preserved.each { |f| puts "! preserved override as #{f}" }
|
80
|
-
end
|
81
|
-
|
82
|
-
desc "Freeze all models into your application for easy modification"
|
83
|
-
task :models do
|
84
|
-
puts "Copying all models to your application - resolves any collisions"
|
85
|
-
copied, preserved = MerbAuth.mirror_files_for :model
|
86
|
-
puts "- no files to copy" if copied.empty? && preserved.empty?
|
87
|
-
copied.each { |f| puts "- copied #{f}" }
|
88
|
-
preserved.each { |f| puts "! preserved override as #{f}" }
|
89
|
-
end
|
90
|
-
|
91
|
-
desc "Freezes MerbAuth as a gem and copies over merb-auth/app"
|
92
|
-
task :app_with_gem => [:gem, :app]
|
93
|
-
|
94
|
-
desc "Freezes MerbAuth by unpacking all files into your application"
|
95
|
-
task :unpack do
|
96
|
-
puts "Unpacking MerbAuth files to your application - resolves any collisions"
|
97
|
-
copied, preserved = MerbAuth.unpack_slice!
|
98
|
-
puts "- no files to copy" if copied.empty? && preserved.empty?
|
99
|
-
copied.each { |f| puts "- copied #{f}" }
|
100
|
-
preserved.each { |f| puts "! preserved override as #{f}" }
|
101
|
-
end
|
102
|
-
|
103
|
-
end
|
104
|
-
|
105
|
-
desc "Run slice specs within the host application context"
|
106
|
-
task :spec => [ "spec:explain", "spec:default" ]
|
107
|
-
|
108
|
-
namespace :spec do
|
109
|
-
|
110
|
-
slice_root = File.expand_path(File.join(File.dirname(__FILE__), '..', '..'))
|
111
|
-
|
112
|
-
task :explain do
|
113
|
-
puts "\nNote: By running MerbAuth specs inside the application context any\n" +
|
114
|
-
"overrides could break existing specs. This isn't always a problem,\n" +
|
115
|
-
"especially in the case of views. Use these spec tasks to check how\n" +
|
116
|
-
"well your application conforms to the original slice implementation."
|
117
|
-
end
|
118
|
-
|
119
|
-
Spec::Rake::SpecTask.new('default') do |t|
|
120
|
-
t.spec_opts = ["--format", "specdoc", "--colour"]
|
121
|
-
t.spec_files = Dir["#{slice_root}/spec/**/*_spec.rb"].sort
|
122
|
-
end
|
123
|
-
|
124
|
-
desc "Run all model specs, run a spec for a specific Model with MODEL=MyModel"
|
125
|
-
Spec::Rake::SpecTask.new('model') do |t|
|
126
|
-
t.spec_opts = ["--format", "specdoc", "--colour"]
|
127
|
-
if(ENV['MODEL'])
|
128
|
-
t.spec_files = Dir["#{slice_root}/spec/models/**/#{ENV['MODEL']}_spec.rb"].sort
|
129
|
-
else
|
130
|
-
t.spec_files = Dir["#{slice_root}/spec/models/**/*_spec.rb"].sort
|
131
|
-
end
|
132
|
-
end
|
133
|
-
|
134
|
-
desc "Run all controller specs, run a spec for a specific Controller with CONTROLLER=MyController"
|
135
|
-
Spec::Rake::SpecTask.new('controller') do |t|
|
136
|
-
t.spec_opts = ["--format", "specdoc", "--colour"]
|
137
|
-
if(ENV['CONTROLLER'])
|
138
|
-
t.spec_files = Dir["#{slice_root}/spec/controllers/**/#{ENV['CONTROLLER']}_spec.rb"].sort
|
139
|
-
else
|
140
|
-
t.spec_files = Dir["#{slice_root}/spec/controllers/**/*_spec.rb"].sort
|
141
|
-
end
|
142
|
-
end
|
143
|
-
|
144
|
-
desc "Run all view specs, run specs for a specific controller (and view) with CONTROLLER=MyController (VIEW=MyView)"
|
145
|
-
Spec::Rake::SpecTask.new('view') do |t|
|
146
|
-
t.spec_opts = ["--format", "specdoc", "--colour"]
|
147
|
-
if(ENV['CONTROLLER'] and ENV['VIEW'])
|
148
|
-
t.spec_files = Dir["#{slice_root}/spec/views/**/#{ENV['CONTROLLER']}/#{ENV['VIEW']}*_spec.rb"].sort
|
149
|
-
elsif(ENV['CONTROLLER'])
|
150
|
-
t.spec_files = Dir["#{slice_root}/spec/views/**/#{ENV['CONTROLLER']}/*_spec.rb"].sort
|
151
|
-
else
|
152
|
-
t.spec_files = Dir["#{slice_root}/spec/views/**/*_spec.rb"].sort
|
153
|
-
end
|
154
|
-
end
|
155
|
-
|
156
|
-
desc "Run all specs and output the result in html"
|
157
|
-
Spec::Rake::SpecTask.new('html') do |t|
|
158
|
-
t.spec_opts = ["--format", "html"]
|
159
|
-
t.libs = ['lib', 'server/lib' ]
|
160
|
-
t.spec_files = Dir["#{slice_root}/spec/**/*_spec.rb"].sort
|
161
|
-
end
|
162
|
-
|
163
|
-
end
|
164
|
-
|
165
|
-
end
|
166
|
-
end
|
data/lib/merb-auth/model.rb
DELETED
@@ -1,80 +0,0 @@
|
|
1
|
-
require 'digest/sha1'
|
2
|
-
|
3
|
-
module MerbAuth
|
4
|
-
def self.use_adapter(adapter)
|
5
|
-
require File.join(File.dirname(__FILE__), "adapter", adapter.to_s)
|
6
|
-
end
|
7
|
-
|
8
|
-
module BaseModel
|
9
|
-
def self.included(base)
|
10
|
-
base.send(:include, InstanceMethods)
|
11
|
-
base.send(:extend, ClassMethods)
|
12
|
-
|
13
|
-
base.class_eval do
|
14
|
-
attr_accessor :password, :password_confirmation
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
module InstanceMethods
|
19
|
-
def authenticated?(password)
|
20
|
-
crypted_password == encrypt(password)
|
21
|
-
end
|
22
|
-
|
23
|
-
# before filter
|
24
|
-
def encrypt_password
|
25
|
-
return if password.blank?
|
26
|
-
self.salt = Digest::SHA1.hexdigest("--#{Time.now.to_s}--#{username}--") if new_record?
|
27
|
-
self.crypted_password = encrypt(password)
|
28
|
-
end
|
29
|
-
|
30
|
-
# Encrypts the password with the user salt
|
31
|
-
def encrypt(password)
|
32
|
-
self.class.encrypt(password, salt)
|
33
|
-
end
|
34
|
-
|
35
|
-
def remember_token?
|
36
|
-
remember_token_expires_at && Date.today < remember_token_expires_at
|
37
|
-
end
|
38
|
-
|
39
|
-
def remember_me_until(time)
|
40
|
-
self.remember_token_expires_at = time
|
41
|
-
self.remember_token = encrypt("#{email}--#{remember_token_expires_at}")
|
42
|
-
save
|
43
|
-
end
|
44
|
-
|
45
|
-
def remember_me_for(days)
|
46
|
-
remember_me_until (Date.today + days)
|
47
|
-
end
|
48
|
-
|
49
|
-
# These create and unset the fields required for remembering users between browser closes
|
50
|
-
# Default of 2 weeks
|
51
|
-
def remember_me
|
52
|
-
remember_me_for(14)
|
53
|
-
end
|
54
|
-
|
55
|
-
def forget_me
|
56
|
-
self.remember_token_expires_at = nil
|
57
|
-
self.remember_token = nil
|
58
|
-
self.save
|
59
|
-
end
|
60
|
-
|
61
|
-
protected
|
62
|
-
def password_required?
|
63
|
-
crypted_password.blank? || !password.blank?
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
module ClassMethods
|
68
|
-
# Encrypts some data with the salt.
|
69
|
-
def encrypt(password, salt)
|
70
|
-
Digest::SHA1.hexdigest("--#{salt}--#{password}--")
|
71
|
-
end
|
72
|
-
|
73
|
-
# Authenticates a user by their username and unencrypted password. Returns the user or nil.
|
74
|
-
def authenticate(username, password)
|
75
|
-
u = find_by_username(username) # need to get the salt
|
76
|
-
u && u.authenticated?(password) ? u : nil
|
77
|
-
end
|
78
|
-
end
|
79
|
-
end
|
80
|
-
end
|
data/lib/merb-auth/slicetasks.rb
DELETED
@@ -1,18 +0,0 @@
|
|
1
|
-
namespace :slices do
|
2
|
-
namespace :merb_auth do
|
3
|
-
# add your own tasks here
|
4
|
-
|
5
|
-
# implement this to test for structural/code dependencies
|
6
|
-
# like certain directories or availability of other files
|
7
|
-
desc "Test for any dependencies"
|
8
|
-
task :preflight do
|
9
|
-
end
|
10
|
-
|
11
|
-
# implement this to perform any database related setup steps
|
12
|
-
desc "Migrate the database"
|
13
|
-
task :migrate do
|
14
|
-
MerbAuth::User.create_db_table
|
15
|
-
end
|
16
|
-
|
17
|
-
end
|
18
|
-
end
|
@@ -1,157 +0,0 @@
|
|
1
|
-
body {
|
2
|
-
font-family: Arial, Verdana, sans-serif;
|
3
|
-
font-size: 14px;
|
4
|
-
background-color: #fff;
|
5
|
-
color: #000;
|
6
|
-
background-color: #fff;
|
7
|
-
}
|
8
|
-
|
9
|
-
html {
|
10
|
-
height: 100%;
|
11
|
-
}
|
12
|
-
|
13
|
-
hr {
|
14
|
-
border: 0px;
|
15
|
-
color: #ccc;
|
16
|
-
background-color: #cdcdcd;
|
17
|
-
height: 1px;
|
18
|
-
width: 100%;
|
19
|
-
text-align: left;
|
20
|
-
}
|
21
|
-
|
22
|
-
h1, h2, h3 {
|
23
|
-
color: #003399;
|
24
|
-
color: #09579A;
|
25
|
-
background-color: #fff;
|
26
|
-
font-family: Arial, Verdana, sans-serif;
|
27
|
-
font-weight: 300;
|
28
|
-
}
|
29
|
-
|
30
|
-
h1 {
|
31
|
-
font-size: 20px;
|
32
|
-
}
|
33
|
-
h2 {
|
34
|
-
font-size: 15px;
|
35
|
-
}
|
36
|
-
h3 {
|
37
|
-
font-size: 15px;
|
38
|
-
}
|
39
|
-
|
40
|
-
p {
|
41
|
-
line-height: 20px;
|
42
|
-
padding: 5px;
|
43
|
-
}
|
44
|
-
|
45
|
-
a, a:hover {
|
46
|
-
color: #0033CC;
|
47
|
-
background-color: #fff;
|
48
|
-
text-decoration: underline;
|
49
|
-
}
|
50
|
-
|
51
|
-
#container {
|
52
|
-
width: 95%;
|
53
|
-
text-align: left;
|
54
|
-
background-color: #fff;
|
55
|
-
margin-right: auto;
|
56
|
-
margin-left: auto;
|
57
|
-
}
|
58
|
-
|
59
|
-
#header-container {
|
60
|
-
width: 100%;
|
61
|
-
padding-top: 15px;
|
62
|
-
}
|
63
|
-
|
64
|
-
#header-container h1, #header-container h2 {
|
65
|
-
margin-left: 6px;
|
66
|
-
margin-bottom: 6px;
|
67
|
-
}
|
68
|
-
|
69
|
-
#main-container {
|
70
|
-
padding: 15px;
|
71
|
-
min-height: 400px;
|
72
|
-
}
|
73
|
-
|
74
|
-
#footer-container {
|
75
|
-
clear: both;
|
76
|
-
font-size: 12px;
|
77
|
-
font-family: Verdana, Arial, sans-serif;
|
78
|
-
}
|
79
|
-
|
80
|
-
#main-container ul {
|
81
|
-
margin-left: 3.0em;
|
82
|
-
}
|
83
|
-
|
84
|
-
.right {
|
85
|
-
float: right;
|
86
|
-
font-size: 100%;
|
87
|
-
margin-top: 5px;
|
88
|
-
color: #999;
|
89
|
-
background-color: #fff;
|
90
|
-
}
|
91
|
-
.left {
|
92
|
-
float: left;
|
93
|
-
font-size: 100%;
|
94
|
-
margin-top: 5px;
|
95
|
-
color: #999;
|
96
|
-
background-color: #fff;
|
97
|
-
}
|
98
|
-
|
99
|
-
a#google_signup {
|
100
|
-
background:transparent url(/images/btn-google-signup.png) no-repeat scroll 0% 0%;
|
101
|
-
color:#FFFFFF;
|
102
|
-
display:block;
|
103
|
-
font-size:14px;
|
104
|
-
height:67px;
|
105
|
-
line-height:22px;
|
106
|
-
margin:0pt;
|
107
|
-
padding:0px;
|
108
|
-
text-align:center;
|
109
|
-
text-decoration:none;
|
110
|
-
width:151px;
|
111
|
-
}
|
112
|
-
|
113
|
-
a#google_signup div {
|
114
|
-
padding-top:8px;
|
115
|
-
}
|
116
|
-
|
117
|
-
#openid_url, .openid_link {
|
118
|
-
background:#FFFFFF url(/images/openid-login.gif) no-repeat scroll 2px 50%;
|
119
|
-
padding-left:25px;
|
120
|
-
width:14.25em;
|
121
|
-
}
|
122
|
-
|
123
|
-
/** Form inputs **/
|
124
|
-
label {
|
125
|
-
font-weight: bold;
|
126
|
-
display: block;
|
127
|
-
}
|
128
|
-
|
129
|
-
#remember_me {
|
130
|
-
margin: 2px 5px 0px 0px;
|
131
|
-
float: left;
|
132
|
-
}
|
133
|
-
|
134
|
-
div.error {
|
135
|
-
background-color:#FCECEC;
|
136
|
-
}
|
137
|
-
|
138
|
-
div.error ul {
|
139
|
-
padding-bottom:20px;
|
140
|
-
}
|
141
|
-
|
142
|
-
.error {
|
143
|
-
background-color:#FCECEC;
|
144
|
-
}
|
145
|
-
|
146
|
-
.error h2 {
|
147
|
-
background: #CC0000 no-repeat scroll left center;
|
148
|
-
border-color: #CC9999;
|
149
|
-
color:#FFFFFF;
|
150
|
-
border:1px solid #CCCCCC;
|
151
|
-
font-size:14px;
|
152
|
-
padding:5px 5px 5px 10px;
|
153
|
-
}
|
154
|
-
|
155
|
-
.error li {
|
156
|
-
color: #CC0000;
|
157
|
-
}
|
@@ -1,29 +0,0 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__), '..', 'spec_helper.rb')
|
2
|
-
|
3
|
-
prefix = 'merb-auth'
|
4
|
-
|
5
|
-
describe "Router.add_slice(:MerbAuth)" do
|
6
|
-
include Merb::Test::Rspec::RouteMatchers
|
7
|
-
|
8
|
-
before(:all) do
|
9
|
-
Merb::Router.prepare { |r| r.add_slice(:MerbAuth) } if standalone?
|
10
|
-
end
|
11
|
-
|
12
|
-
it "should have named routes for :login, :logout and :signup" do
|
13
|
-
[:login, :logout, :signup].each do |name|
|
14
|
-
url(name).should == "/#{prefix}/#{name}"
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
it "should route /#{prefix}/login to Session#new" do
|
19
|
-
request_to("/#{prefix}/login", :get).should route_to(MerbAuth::Users, :login)
|
20
|
-
end
|
21
|
-
|
22
|
-
it "should route /#{prefix}/login via post to Session#create" do
|
23
|
-
request_to("/#{prefix}/login", :post).should route_to(MerbAuth::Users, :login)
|
24
|
-
end
|
25
|
-
|
26
|
-
it "should route /#{prefix}/logout via delete to Session#destroy" do
|
27
|
-
request_to("/#{prefix}/logout", :delete).should route_to(MerbAuth::Users, :logout)
|
28
|
-
end
|
29
|
-
end
|