merb-auth-slice-password 0.9.9
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +20 -0
- data/README.textile +180 -0
- data/Rakefile +52 -0
- data/TODO +15 -0
- data/app/controllers/application.rb +5 -0
- data/app/controllers/exceptions.rb +26 -0
- data/app/controllers/sessions.rb +44 -0
- data/app/helpers/application_helper.rb +64 -0
- data/app/views/exceptions/unauthenticated.html.erb +24 -0
- data/app/views/layout/merb-auth-slice-password.html.erb +16 -0
- data/lib/merb-auth-slice-password.rb +88 -0
- data/lib/merb-auth-slice-password/merbtasks.rb +106 -0
- data/lib/merb-auth-slice-password/slicetasks.rb +18 -0
- data/lib/merb-auth-slice-password/spectasks.rb +66 -0
- data/public/javascripts/master.js +0 -0
- data/public/stylesheets/master.css +2 -0
- data/spec/merb-auth-slice-password_spec.rb +1 -0
- data/spec/spec_helper.rb +44 -0
- data/stubs/app/controllers/application.rb +2 -0
- data/stubs/app/controllers/main.rb +2 -0
- metadata +113 -0
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2008 Daniel Neighman
|
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.textile
ADDED
@@ -0,0 +1,180 @@
|
|
1
|
+
MerbAuthSlicePassword ==================
|
2
|
+
|
3
|
+
A slice for the Merb framework that uses the merb-auth-core authentication
|
4
|
+
framework. This provides basic form based login as well as basic auth login.
|
5
|
+
To see how to customize the authentication process, see merb-auth-core.
|
6
|
+
|
7
|
+
To use this slice you should supply a User type model that logs in via an
|
8
|
+
identifier and password. i.e. "email" and "password", or "login" & "password"
|
9
|
+
|
10
|
+
Additionally your model should implement a class level method,
|
11
|
+
authenticate(login, password) This should return the user object, or if not
|
12
|
+
found should return false or nil
|
13
|
+
|
14
|
+
For example
|
15
|
+
|
16
|
+
User.authenticate("fred", "sekrit") #=> The user object for the "fred" login
|
17
|
+
or nil / false if not found
|
18
|
+
|
19
|
+
You can use the salted_user mixin from merb-auth-more for use with this slice.
|
20
|
+
|
21
|
+
------------------------------------------------------------------------------
|
22
|
+
|
23
|
+
|-- LICENSE
|
24
|
+
|-- README.textile
|
25
|
+
|-- Rakefile
|
26
|
+
|-- TODO
|
27
|
+
|-- app
|
28
|
+
| |-- controllers
|
29
|
+
| | |-- application.rb
|
30
|
+
| | |-- exceptions.rb
|
31
|
+
| | `-- sessions.rb
|
32
|
+
| |-- helpers
|
33
|
+
| | `-- application_helper.rb
|
34
|
+
| `-- views
|
35
|
+
| |-- exceptions
|
36
|
+
| | `-- unauthenticated.html.erb
|
37
|
+
| `-- layout
|
38
|
+
| `-- mauth_password_slice.html.erb
|
39
|
+
|-- lib
|
40
|
+
| |-- merb-auth-slice-password
|
41
|
+
| | |-- merbtasks.rb
|
42
|
+
| | |-- slicetasks.rb
|
43
|
+
| | `-- spectasks.rb
|
44
|
+
| `-- merb-auth-slice-password.rb
|
45
|
+
|-- public
|
46
|
+
| |-- javascripts
|
47
|
+
| | `-- master.js
|
48
|
+
| `-- stylesheets
|
49
|
+
| `-- master.css
|
50
|
+
|-- spec
|
51
|
+
| |-- controllers
|
52
|
+
| | `-- main_spec.rb
|
53
|
+
| |-- mauth_password_slice_spec.rb
|
54
|
+
| `-- spec_helper.rb
|
55
|
+
`-- stubs
|
56
|
+
`-- app
|
57
|
+
`-- controllers
|
58
|
+
|-- application.rb
|
59
|
+
`-- main.rb
|
60
|
+
|
61
|
+
|
62
|
+
|
63
|
+
1. Rake tasks to package/install the gem - edit this to modify the manifest.
|
64
|
+
2. The slice application: controllers, models, helpers, views.
|
65
|
+
3. The default layout, as specified in Merb::Slices::config[:mauth_password_slice][:layout]
|
66
|
+
change this to :application to use the app's layout.
|
67
|
+
4. Standard rake tasks available to your application.
|
68
|
+
5. Your custom application rake tasks.
|
69
|
+
6. The main slice file - contains all slice setup logic/config.
|
70
|
+
7. Public assets you (optionally) install using rake slices:mauth_password_slice:install
|
71
|
+
8. Specs for basis slice behaviour - you usually adapt these for your slice.
|
72
|
+
9. Stubs of classes/views/files for the end-user to override - usually these
|
73
|
+
mimic the files in app/ and/or public/; use rake slices:mauth_password_slice:stubs to
|
74
|
+
get started with the override stubs. Also, slices:mauth_password_slice:patch will
|
75
|
+
copy over views to override in addition to the files found in /stubs.
|
76
|
+
|
77
|
+
|
78
|
+
To see all available tasks for MerbAuthSlicePassword run:
|
79
|
+
|
80
|
+
rake -T slices:mauth_password_slice
|
81
|
+
|
82
|
+
------------------------------------------------------------------------------
|
83
|
+
|
84
|
+
Instructions for installation:
|
85
|
+
|
86
|
+
file: config/init.rb
|
87
|
+
|
88
|
+
# add the slice as a regular dependency
|
89
|
+
|
90
|
+
dependency 'merb-auth-slice-password'
|
91
|
+
|
92
|
+
# if needed, configure which slices to load and in which order
|
93
|
+
|
94
|
+
Merb::Plugins.config[:merb_slices] = { :queue => ["MerbAuthSlicePassword", ...] }
|
95
|
+
|
96
|
+
# Setup your application to use MerbAuthSlicePassword in an after_app_loads block
|
97
|
+
|
98
|
+
# To change the login or password field to a field of your choice
|
99
|
+
Set
|
100
|
+
Merb::Plugin.config[:"merb-auth"][:login_param]
|
101
|
+
Merb::Plugin.config[:"merb-auth"][:password_param]
|
102
|
+
|
103
|
+
These are used to setup the login and password fields and the labels that are
|
104
|
+
shown. The defaults are shown
|
105
|
+
|
106
|
+
h3. Included Strategies
|
107
|
+
|
108
|
+
By default the password slice loads the :default_password_form strategy
|
109
|
+
from merb-auth-more. If you don't want to use this you should set the
|
110
|
+
MerbAutheSlicePassword[:no_default_strategies] = true
|
111
|
+
|
112
|
+
This will prevent it from loading any strategies.
|
113
|
+
|
114
|
+
|
115
|
+
file: config/router.rb
|
116
|
+
|
117
|
+
# Any of the options can be left out for the defaults
|
118
|
+
slice(:MerbAuthSlicePassword, :name_prefix => nil, :path_prefix => "auth", :default_routes => false )
|
119
|
+
|
120
|
+
Normally you should also run the following rake task:
|
121
|
+
|
122
|
+
rake slices:merb-auth-slice-password:install
|
123
|
+
|
124
|
+
------------------------------------------------------------------------------
|
125
|
+
|
126
|
+
You can put your application-level overrides in:
|
127
|
+
|
128
|
+
host-app/slices/merb-auth-slice-password/app - controllers, models, views ...
|
129
|
+
|
130
|
+
Templates are located in this order:
|
131
|
+
|
132
|
+
1. host-app/slices/merb-auth-slice-password/app/views/* 2.
|
133
|
+
gems/mauth_password_slice/app/views/* 3. host-app/app/views/*
|
134
|
+
|
135
|
+
To customize the login form, create a view in your host-app
|
136
|
+
|
137
|
+
host-app/app/views/exceptions/unauthenticated.html.haml
|
138
|
+
|
139
|
+
The host-app's application layout is used by default
|
140
|
+
|
141
|
+
You can use the host application's layout by configuring the
|
142
|
+
merb-auth-slice-password slice in a before_app_loads block:
|
143
|
+
|
144
|
+
You'll need to setup the Merb::Authentication::Manager#fetch_user and store_user
|
145
|
+
methods for your given user model.
|
146
|
+
|
147
|
+
------------------------------------------------------------------------------
|
148
|
+
|
149
|
+
About Slices ============
|
150
|
+
|
151
|
+
Merb-Slices is a Merb plugin for using and creating application 'slices' which
|
152
|
+
help you modularize your application. Usually these are reuseable extractions
|
153
|
+
from your main app. In effect, a Slice is just like a regular Merb MVC
|
154
|
+
application, both in functionality as well as in structure.
|
155
|
+
|
156
|
+
When you generate a Slice stub structure, a module is setup to serve as a
|
157
|
+
namespace for your controller, models, helpers etc. This ensures maximum
|
158
|
+
encapsulation. You could say a Slice is a mixture between a Merb plugin (a
|
159
|
+
Gem) and a Merb application, reaping the benefits of both.
|
160
|
+
|
161
|
+
A host application can 'mount' a Slice inside the router, which means you have
|
162
|
+
full over control how it integrates. By default a Slice's routes are prefixed
|
163
|
+
by its name (a router :namespace), but you can easily provide your own prefix
|
164
|
+
or leave it out, mounting it at the root of your url-schema. You can even
|
165
|
+
mount a Slice multiple times and give extra parameters to customize an
|
166
|
+
instance's behaviour.
|
167
|
+
|
168
|
+
A Slice's Application controller uses controller_for_slice to setup slice
|
169
|
+
specific behaviour, which mainly affects cascaded view handling. Additionaly,
|
170
|
+
this method is available to any kind of controller, so it can be used for Merb
|
171
|
+
Mailer too for example.
|
172
|
+
|
173
|
+
There are many ways which let you customize a Slice's functionality and
|
174
|
+
appearance without ever touching the Gem-level code itself. It's not only easy
|
175
|
+
to add template/layout overrides, you can also add/modify controllers, models
|
176
|
+
and other runtime code from within the host application.
|
177
|
+
|
178
|
+
To create your own Slice run this (somewhere outside of your merb app):
|
179
|
+
|
180
|
+
$ merb-gen slice <your-lowercase-slice-name>
|
data/Rakefile
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake/gempackagetask'
|
3
|
+
|
4
|
+
require 'merb-core'
|
5
|
+
require 'merb-core/tasks/merb'
|
6
|
+
|
7
|
+
GEM_NAME = "merb-auth-slice-password"
|
8
|
+
AUTHOR = "Your Name"
|
9
|
+
EMAIL = "Your Email"
|
10
|
+
HOMEPAGE = "http://merbivore.com/"
|
11
|
+
SUMMARY = "Merb Slice that provides ..."
|
12
|
+
GEM_VERSION = Merb::VERSION
|
13
|
+
|
14
|
+
spec = Gem::Specification.new do |s|
|
15
|
+
s.rubyforge_project = 'merb'
|
16
|
+
s.name = GEM_NAME
|
17
|
+
s.version = GEM_VERSION
|
18
|
+
s.platform = Gem::Platform::RUBY
|
19
|
+
s.has_rdoc = true
|
20
|
+
s.extra_rdoc_files = ["README.textile", "LICENSE", 'TODO']
|
21
|
+
s.summary = SUMMARY
|
22
|
+
s.description = s.summary
|
23
|
+
s.author = AUTHOR
|
24
|
+
s.email = EMAIL
|
25
|
+
s.homepage = HOMEPAGE
|
26
|
+
s.add_dependency('merb-slices', '>= 0.9.9')
|
27
|
+
s.add_dependency('merb-auth-core', "= #{Merb::VERSION}")
|
28
|
+
s.add_dependency('merb-auth-more', "= #{Merb::VERSION}")
|
29
|
+
s.require_path = 'lib'
|
30
|
+
s.files = %w(LICENSE README.textile Rakefile TODO) + Dir.glob("{lib,spec,app,public,stubs}/**/*")
|
31
|
+
end
|
32
|
+
|
33
|
+
Rake::GemPackageTask.new(spec) do |pkg|
|
34
|
+
pkg.gem_spec = spec
|
35
|
+
end
|
36
|
+
|
37
|
+
desc "Install MerbAuthSlicePassword as a gem"
|
38
|
+
task :install do
|
39
|
+
Merb::RakeHelper.install(GEM_NAME, :version => GEM_VERSION)
|
40
|
+
end
|
41
|
+
|
42
|
+
desc "Create a gemspec file"
|
43
|
+
task :gemspec do
|
44
|
+
File.open("#{GEM_NAME}.gemspec", "w") do |file|
|
45
|
+
file.puts spec.to_ruby
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
require 'spec/rake/spectask'
|
50
|
+
require 'merb-core/test/tasks/spectasks'
|
51
|
+
desc 'Default: run spec examples'
|
52
|
+
task :default => 'spec'
|
data/TODO
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
TODO:
|
2
|
+
|
3
|
+
- Fix MerbAuthSlicePassword.description and MerbAuthSlicePassword.version
|
4
|
+
- Fix LICENSE with your name
|
5
|
+
- Fix Rakefile with your name and contact info
|
6
|
+
- Add your code to lib/mauth_password_slice.rb
|
7
|
+
- Add your Merb rake tasks to lib/mauth_password_slice/merbtasks.rb
|
8
|
+
|
9
|
+
Remove anything that you don't need:
|
10
|
+
|
11
|
+
- app/controllers/main.rb MerbAuthSlicePassword::Main controller
|
12
|
+
- app/views/layout/mauth_password_slice.html.erb
|
13
|
+
- spec/controllers/main_spec.rb controller specs
|
14
|
+
- public/* any public files
|
15
|
+
- stubs/* any stub files
|
@@ -0,0 +1,26 @@
|
|
1
|
+
class Application < Merb::Controller; end
|
2
|
+
|
3
|
+
class Exceptions < Application
|
4
|
+
include Merb::Slices::Support # Required to provide slice_url
|
5
|
+
|
6
|
+
# # This stuff allows us to provide a default view
|
7
|
+
the_view_path = File.expand_path(File.dirname(__FILE__) / ".." / "views")
|
8
|
+
self._template_roots ||= []
|
9
|
+
self._template_roots << [the_view_path, :_template_location]
|
10
|
+
self._template_roots << [Merb.dir_for(:view), :_template_location]
|
11
|
+
|
12
|
+
def unauthenticated
|
13
|
+
provides :xml, :js, :json, :yaml
|
14
|
+
|
15
|
+
session.abandon!
|
16
|
+
|
17
|
+
case content_type
|
18
|
+
when :html
|
19
|
+
render
|
20
|
+
else
|
21
|
+
basic_authentication.request!
|
22
|
+
""
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
class MerbAuthSlicePassword::Sessions < MerbAuthSlicePassword::Application
|
2
|
+
|
3
|
+
before :_grab_return_to # Need to hang onto the redirection during the session.abandon!
|
4
|
+
after :_store_return_to_in_session # Need to hang onto the redirection during the session.abandon!
|
5
|
+
|
6
|
+
before(nil, :only => [:update, :destroy]) { session.abandon! }
|
7
|
+
before :ensure_authenticated
|
8
|
+
|
9
|
+
# redirect from an after filter for max flexibility
|
10
|
+
# We can then put it into a slice and ppl can easily
|
11
|
+
# customize the action
|
12
|
+
after :redirect_after_login, :only => :update, :if => lambda{ !(300..399).include?(status) }
|
13
|
+
after :redirect_after_logout, :only => :destroy
|
14
|
+
|
15
|
+
def update
|
16
|
+
"Add an after filter to do stuff after login"
|
17
|
+
end
|
18
|
+
|
19
|
+
def destroy
|
20
|
+
"Add an after filter to do stuff after logout"
|
21
|
+
end
|
22
|
+
|
23
|
+
|
24
|
+
private
|
25
|
+
# @overwritable
|
26
|
+
def redirect_after_login
|
27
|
+
redirect_back_or "/", :message => "Authenticated Successfully", :ignore => [url(:login), url(:logout)]
|
28
|
+
end
|
29
|
+
|
30
|
+
# @overwritable
|
31
|
+
def redirect_after_logout
|
32
|
+
redirect "/", :message => "Logged Out"
|
33
|
+
end
|
34
|
+
|
35
|
+
# @private
|
36
|
+
def _grab_return_to
|
37
|
+
session.authentication.return_to_url
|
38
|
+
end
|
39
|
+
|
40
|
+
# @private
|
41
|
+
def _store_return_to_in_session
|
42
|
+
session.authentication.return_to_url = session.authentication.return_to_url
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
module Merb
|
2
|
+
module MerbAuthSlicePassword
|
3
|
+
module ApplicationHelper
|
4
|
+
|
5
|
+
# @param *segments<Array[#to_s]> Path segments to append.
|
6
|
+
#
|
7
|
+
# @return <String>
|
8
|
+
# A path relative to the public directory, with added segments.
|
9
|
+
def image_path(*segments)
|
10
|
+
public_path_for(:image, *segments)
|
11
|
+
end
|
12
|
+
|
13
|
+
# @param *segments<Array[#to_s]> Path segments to append.
|
14
|
+
#
|
15
|
+
# @return <String>
|
16
|
+
# A path relative to the public directory, with added segments.
|
17
|
+
def javascript_path(*segments)
|
18
|
+
public_path_for(:javascript, *segments)
|
19
|
+
end
|
20
|
+
|
21
|
+
# @param *segments<Array[#to_s]> Path segments to append.
|
22
|
+
#
|
23
|
+
# @return <String>
|
24
|
+
# A path relative to the public directory, with added segments.
|
25
|
+
def stylesheet_path(*segments)
|
26
|
+
public_path_for(:stylesheet, *segments)
|
27
|
+
end
|
28
|
+
|
29
|
+
# Construct a path relative to the public directory
|
30
|
+
#
|
31
|
+
# @param <Symbol> The type of component.
|
32
|
+
# @param *segments<Array[#to_s]> Path segments to append.
|
33
|
+
#
|
34
|
+
# @return <String>
|
35
|
+
# A path relative to the public directory, with added segments.
|
36
|
+
def public_path_for(type, *segments)
|
37
|
+
::MerbAuthSlicePassword.public_path_for(type, *segments)
|
38
|
+
end
|
39
|
+
|
40
|
+
# Construct an app-level path.
|
41
|
+
#
|
42
|
+
# @param <Symbol> The type of component.
|
43
|
+
# @param *segments<Array[#to_s]> Path segments to append.
|
44
|
+
#
|
45
|
+
# @return <String>
|
46
|
+
# A path within the host application, with added segments.
|
47
|
+
def app_path_for(type, *segments)
|
48
|
+
::MerbAuthSlicePassword.app_path_for(type, *segments)
|
49
|
+
end
|
50
|
+
|
51
|
+
# Construct a slice-level path.
|
52
|
+
#
|
53
|
+
# @param <Symbol> The type of component.
|
54
|
+
# @param *segments<Array[#to_s]> Path segments to append.
|
55
|
+
#
|
56
|
+
# @return <String>
|
57
|
+
# A path within the slice source (Gem), with added segments.
|
58
|
+
def slice_path_for(type, *segments)
|
59
|
+
::MerbAuthSlicePassword.slice_path_for(type, *segments)
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
<h3>Login</h3>
|
2
|
+
|
3
|
+
<div>
|
4
|
+
|
5
|
+
<%= error_messages_for session.authentication %>
|
6
|
+
<% @login_param = Merb::Authentication::Strategies::Basic::Base.login_param %>
|
7
|
+
<% @password_param = Merb::Authentication::Strategies::Basic::Base.password_param %>
|
8
|
+
|
9
|
+
<form action="<%= slice_url(:merb_auth_slice_password, :perform_login) %>" method="POST" accept-charset="utf-8">
|
10
|
+
<input type="hidden" name="_method" value="PUT" />
|
11
|
+
<div class="formRow">
|
12
|
+
<label><%= @login_param.to_s.capitalize %>: <input type="text" name="<%= @login_param.to_s %>" value="" id="<%= @login_param.to_s %>"></label>
|
13
|
+
</div> <!-- close: formRow -->
|
14
|
+
<div class="formRow">
|
15
|
+
<label><%= @password_param.to_s.capitalize %>:<input type="password" name="<%= @password_param.to_s %>" value="" id="<%= @password_param.to_s %>"></label>
|
16
|
+
</div> <!-- close: formRow -->
|
17
|
+
<div class="formRow">
|
18
|
+
<input type="submit" name="Submit" value="Log In" id="Submit">
|
19
|
+
</div> <!-- close: formRow -->
|
20
|
+
</form>
|
21
|
+
</div>
|
22
|
+
|
23
|
+
|
24
|
+
|
@@ -0,0 +1,16 @@
|
|
1
|
+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
2
|
+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-us" lang="en-us">
|
3
|
+
<head>
|
4
|
+
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
|
5
|
+
<title>Fresh MerbAuthSlicePassword Slice</title>
|
6
|
+
<link href="<%= public_path_for :stylesheet, 'master.css' %>" type="text/css" charset="utf-8" rel="stylesheet" media="all" />
|
7
|
+
<script src="<%= public_path_for :javascript, 'master.js' %>" type="text/javascript" charset="utf-8"></script>
|
8
|
+
</head>
|
9
|
+
<!-- you can override this layout at slices/mauth_password_slice/app/views/layout/mauth_password_slice.html.erb -->
|
10
|
+
<body class="merb-auth-slice-password">
|
11
|
+
<div id="container">
|
12
|
+
<h1>MerbAuthSlicePassword Slice</h1>
|
13
|
+
<div id="main"><%= catch_content :for_layout %></div>
|
14
|
+
</div>
|
15
|
+
</body>
|
16
|
+
</html>
|
@@ -0,0 +1,88 @@
|
|
1
|
+
if defined?(Merb::Plugins)
|
2
|
+
|
3
|
+
$:.unshift File.dirname(__FILE__)
|
4
|
+
|
5
|
+
require 'merb-slices'
|
6
|
+
require 'merb-auth-core'
|
7
|
+
require 'merb-auth-more'
|
8
|
+
|
9
|
+
Merb::Plugins.add_rakefiles "merb-auth-slice-password/merbtasks", "merb-auth-slice-password/slicetasks", "merb-auth-slice-password/spectasks"
|
10
|
+
|
11
|
+
# Register the Slice for the current host application
|
12
|
+
Merb::Slices::register(__FILE__)
|
13
|
+
|
14
|
+
# Slice configuration - set this in a before_app_loads callback.
|
15
|
+
# By default a Slice uses its own layout, so you can swicht to
|
16
|
+
# the main application layout or no layout at all if needed.
|
17
|
+
#
|
18
|
+
# Configuration options:
|
19
|
+
# :layout - the layout to use; defaults to :mauth_password_slice
|
20
|
+
# :mirror - which path component types to use on copy operations; defaults to all
|
21
|
+
Merb::Slices::config[:"merb-auth-slice-password"][:layout] ||= :application
|
22
|
+
|
23
|
+
# All Slice code is expected to be namespaced inside a module
|
24
|
+
module MerbAuthSlicePassword
|
25
|
+
|
26
|
+
# Slice metadata
|
27
|
+
self.description = "MerbAuthSlicePassword is a merb slice that provides basic password based logins"
|
28
|
+
self.version = "0.9.9"
|
29
|
+
self.author = "Daniel Neighman"
|
30
|
+
|
31
|
+
# Stub classes loaded hook - runs before LoadClasses BootLoader
|
32
|
+
# right after a slice's classes have been loaded internally.
|
33
|
+
def self.loaded
|
34
|
+
end
|
35
|
+
|
36
|
+
# Initialization hook - runs before AfterAppLoads BootLoader
|
37
|
+
def self.init
|
38
|
+
require 'merb-auth-more/mixins/redirect_back'
|
39
|
+
unless MerbAuthSlicePassword[:no_default_strategies]
|
40
|
+
::Merb::Authentication.activate!(:default_password_form)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
# Activation hook - runs after AfterAppLoads BootLoader
|
45
|
+
def self.activate
|
46
|
+
# Load the default strategies
|
47
|
+
end
|
48
|
+
|
49
|
+
# Deactivation hook - triggered by Merb::Slices.deactivate(MerbAuthSlicePassword)
|
50
|
+
def self.deactivate
|
51
|
+
end
|
52
|
+
|
53
|
+
# Setup routes inside the host application
|
54
|
+
#
|
55
|
+
# @param scope<Merb::Router::Behaviour>
|
56
|
+
# Routes will be added within this scope (namespace). In fact, any
|
57
|
+
# router behaviour is a valid namespace, so you can attach
|
58
|
+
# routes at any level of your router setup.
|
59
|
+
#
|
60
|
+
# @note prefix your named routes with :mauth_password_slice_
|
61
|
+
# to avoid potential conflicts with global named routes.
|
62
|
+
def self.setup_router(scope)
|
63
|
+
# example of a named route
|
64
|
+
scope.match("/login", :method => :get ).to(:controller => "/exceptions", :action => "unauthenticated").name(:login)
|
65
|
+
scope.match("/login", :method => :put ).to(:controller => "sessions", :action => "update" ).name(:perform_login)
|
66
|
+
scope.match("/logout" ).to(:controller => "sessions", :action => "destroy" ).name(:logout)
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|
70
|
+
|
71
|
+
# Setup the slice layout for MerbAuthSlicePassword
|
72
|
+
#
|
73
|
+
# Use MerbAuthSlicePassword.push_path and MerbAuthSlicePassword.push_app_path
|
74
|
+
# to set paths to mauth_password_slice-level and app-level paths. Example:
|
75
|
+
#
|
76
|
+
# MerbAuthSlicePassword.push_path(:application, MerbAuthSlicePassword.root)
|
77
|
+
# MerbAuthSlicePassword.push_app_path(:application, Merb.root / 'slices' / 'mauth_password_slice')
|
78
|
+
# ...
|
79
|
+
#
|
80
|
+
# Any component path that hasn't been set will default to MerbAuthSlicePassword.root
|
81
|
+
#
|
82
|
+
# Or just call setup_default_structure! to setup a basic Merb MVC structure.
|
83
|
+
MerbAuthSlicePassword.setup_default_structure!
|
84
|
+
|
85
|
+
# Add dependencies for other MerbAuthSlicePassword classes below. Example:
|
86
|
+
# dependency "mauth_password_slice/other"
|
87
|
+
|
88
|
+
end
|
@@ -0,0 +1,106 @@
|
|
1
|
+
namespace :slices do
|
2
|
+
namespace :"merb-auth-slice-password" do
|
3
|
+
|
4
|
+
desc "Install MerbAuthSlicePassword"
|
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
|
+
MerbAuthSlicePassword.mirrored_components.each do |type|
|
15
|
+
if File.directory?(MerbAuthSlicePassword.dir_for(type))
|
16
|
+
if !File.directory?(dst_path = MerbAuthSlicePassword.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 MerbAuthSlicePassword - resolves any collisions"
|
28
|
+
copied, preserved = MerbAuthSlicePassword.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 MerbAuthSlicePassword - resolves any collisions"
|
40
|
+
copied, preserved = MerbAuthSlicePassword.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 MerbAuthSlicePassword into your app (only merb-auth-slice-password/app)"
|
51
|
+
task :freeze => [ "freeze:app" ]
|
52
|
+
|
53
|
+
namespace :freeze do
|
54
|
+
|
55
|
+
desc "Freezes MerbAuthSlicePassword 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-slice-password", ENV["UPDATE"], ENV["MODE"] || 'rubygems')
|
59
|
+
rescue NameError
|
60
|
+
puts "! dependency 'merb-freezer' missing"
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
desc "Freezes MerbAuthSlicePassword by copying all files from merb-auth-slice-password/app to your application"
|
65
|
+
task :app do
|
66
|
+
puts "Copying all merb-auth-slice-password/app files to your application - resolves any collisions"
|
67
|
+
copied, preserved = MerbAuthSlicePassword.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 = MerbAuthSlicePassword.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 = MerbAuthSlicePassword.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 MerbAuthSlicePassword as a gem and copies over merb-auth-slice-password/app"
|
92
|
+
task :app_with_gem => [:gem, :app]
|
93
|
+
|
94
|
+
desc "Freezes MerbAuthSlicePassword by unpacking all files into your application"
|
95
|
+
task :unpack do
|
96
|
+
puts "Unpacking MerbAuthSlicePassword files to your application - resolves any collisions"
|
97
|
+
copied, preserved = MerbAuthSlicePassword.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
|
+
end
|
106
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
namespace :slices do
|
2
|
+
namespace :"merb-auth-slice-password" do
|
3
|
+
|
4
|
+
# add your own merb-auth-slice-password tasks here
|
5
|
+
|
6
|
+
# implement this to test for structural/code dependencies
|
7
|
+
# like certain directories or availability of other files
|
8
|
+
desc "Test for any dependencies"
|
9
|
+
task :preflight do
|
10
|
+
end
|
11
|
+
|
12
|
+
# implement this to perform any database related setup steps
|
13
|
+
desc "Migrate the database"
|
14
|
+
task :migrate do
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
require "spec/rake/spectask"
|
2
|
+
namespace :slices do
|
3
|
+
namespace :"merb-auth-slice-password" do
|
4
|
+
|
5
|
+
desc "Run slice specs within the host application context"
|
6
|
+
task :spec => [ "spec:explain", "spec:default" ]
|
7
|
+
|
8
|
+
namespace :spec do
|
9
|
+
|
10
|
+
slice_root = File.expand_path(File.join(File.dirname(__FILE__), '..', '..'))
|
11
|
+
|
12
|
+
task :explain do
|
13
|
+
puts "\nNote: By running MerbAuthSlicePassword specs inside the application context any\n" +
|
14
|
+
"overrides could break existing specs. This isn't always a problem,\n" +
|
15
|
+
"especially in the case of views. Use these spec tasks to check how\n" +
|
16
|
+
"well your application conforms to the original slice implementation."
|
17
|
+
end
|
18
|
+
|
19
|
+
Spec::Rake::SpecTask.new('default') do |t|
|
20
|
+
t.spec_opts = ["--format", "specdoc", "--colour"]
|
21
|
+
t.spec_files = Dir["#{slice_root}/spec/**/*_spec.rb"].sort
|
22
|
+
end
|
23
|
+
|
24
|
+
desc "Run all model specs, run a spec for a specific Model with MODEL=MyModel"
|
25
|
+
Spec::Rake::SpecTask.new('model') do |t|
|
26
|
+
t.spec_opts = ["--format", "specdoc", "--colour"]
|
27
|
+
if(ENV['MODEL'])
|
28
|
+
t.spec_files = Dir["#{slice_root}/spec/models/**/#{ENV['MODEL']}_spec.rb"].sort
|
29
|
+
else
|
30
|
+
t.spec_files = Dir["#{slice_root}/spec/models/**/*_spec.rb"].sort
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
desc "Run all controller specs, run a spec for a specific Controller with CONTROLLER=MyController"
|
35
|
+
Spec::Rake::SpecTask.new('controller') do |t|
|
36
|
+
t.spec_opts = ["--format", "specdoc", "--colour"]
|
37
|
+
if(ENV['CONTROLLER'])
|
38
|
+
t.spec_files = Dir["#{slice_root}/spec/controllers/**/#{ENV['CONTROLLER']}_spec.rb"].sort
|
39
|
+
else
|
40
|
+
t.spec_files = Dir["#{slice_root}/spec/controllers/**/*_spec.rb"].sort
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
desc "Run all view specs, run specs for a specific controller (and view) with CONTROLLER=MyController (VIEW=MyView)"
|
45
|
+
Spec::Rake::SpecTask.new('view') do |t|
|
46
|
+
t.spec_opts = ["--format", "specdoc", "--colour"]
|
47
|
+
if(ENV['CONTROLLER'] and ENV['VIEW'])
|
48
|
+
t.spec_files = Dir["#{slice_root}/spec/views/**/#{ENV['CONTROLLER']}/#{ENV['VIEW']}*_spec.rb"].sort
|
49
|
+
elsif(ENV['CONTROLLER'])
|
50
|
+
t.spec_files = Dir["#{slice_root}/spec/views/**/#{ENV['CONTROLLER']}/*_spec.rb"].sort
|
51
|
+
else
|
52
|
+
t.spec_files = Dir["#{slice_root}/spec/views/**/*_spec.rb"].sort
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
desc "Run all specs and output the result in html"
|
57
|
+
Spec::Rake::SpecTask.new('html') do |t|
|
58
|
+
t.spec_opts = ["--format", "html"]
|
59
|
+
t.libs = ['lib', 'server/lib' ]
|
60
|
+
t.spec_files = Dir["#{slice_root}/spec/**/*_spec.rb"].sort
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
66
|
+
end
|
File without changes
|
@@ -0,0 +1 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'merb-core'
|
3
|
+
require 'merb-slices'
|
4
|
+
require 'spec'
|
5
|
+
require 'merb-auth-core'
|
6
|
+
# Add mauth_password_slice.rb to the search path
|
7
|
+
Merb::Plugins.config[:merb_slices][:auto_register] = true
|
8
|
+
Merb::Plugins.config[:merb_slices][:search_path] = File.join(File.dirname(__FILE__), '..', 'lib', 'merb-auth-slice-password.rb')
|
9
|
+
|
10
|
+
# Using Merb.root below makes sure that the correct root is set for
|
11
|
+
# - testing standalone, without being installed as a gem and no host application
|
12
|
+
# - testing from within the host application; its root will be used
|
13
|
+
Merb.start_environment(
|
14
|
+
:testing => true,
|
15
|
+
:adapter => 'runner',
|
16
|
+
:environment => ENV['MERB_ENV'] || 'test',
|
17
|
+
:merb_root => Merb.root,
|
18
|
+
:session_store => 'memory'
|
19
|
+
)
|
20
|
+
|
21
|
+
module Merb
|
22
|
+
module Test
|
23
|
+
module SliceHelper
|
24
|
+
|
25
|
+
# The absolute path to the current slice
|
26
|
+
def current_slice_root
|
27
|
+
@current_slice_root ||= File.expand_path(File.join(File.dirname(__FILE__), '..'))
|
28
|
+
end
|
29
|
+
|
30
|
+
# Whether the specs are being run from a host application or standalone
|
31
|
+
def standalone?
|
32
|
+
Merb.root == ::MerbAuthSlicePassword.root
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
Spec::Runner.configure do |config|
|
40
|
+
config.include(Merb::Test::ViewHelper)
|
41
|
+
config.include(Merb::Test::RouteHelper)
|
42
|
+
config.include(Merb::Test::ControllerHelper)
|
43
|
+
config.include(Merb::Test::SliceHelper)
|
44
|
+
end
|
metadata
ADDED
@@ -0,0 +1,113 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: merb-auth-slice-password
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.9.9
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Your Name
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2008-10-13 00:00:00 -07:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: merb-slices
|
17
|
+
type: :runtime
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 0.9.9
|
24
|
+
version:
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: merb-auth-core
|
27
|
+
type: :runtime
|
28
|
+
version_requirement:
|
29
|
+
version_requirements: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.9.9
|
34
|
+
version:
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: merb-auth-more
|
37
|
+
type: :runtime
|
38
|
+
version_requirement:
|
39
|
+
version_requirements: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - "="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: 0.9.9
|
44
|
+
version:
|
45
|
+
description: Merb Slice that provides ...
|
46
|
+
email: Your Email
|
47
|
+
executables: []
|
48
|
+
|
49
|
+
extensions: []
|
50
|
+
|
51
|
+
extra_rdoc_files:
|
52
|
+
- README.textile
|
53
|
+
- LICENSE
|
54
|
+
- TODO
|
55
|
+
files:
|
56
|
+
- LICENSE
|
57
|
+
- README.textile
|
58
|
+
- Rakefile
|
59
|
+
- TODO
|
60
|
+
- lib/merb-auth-slice-password
|
61
|
+
- lib/merb-auth-slice-password/merbtasks.rb
|
62
|
+
- lib/merb-auth-slice-password/slicetasks.rb
|
63
|
+
- lib/merb-auth-slice-password/spectasks.rb
|
64
|
+
- lib/merb-auth-slice-password.rb
|
65
|
+
- spec/merb-auth-slice-password_spec.rb
|
66
|
+
- spec/spec_helper.rb
|
67
|
+
- app/controllers
|
68
|
+
- app/controllers/application.rb
|
69
|
+
- app/controllers/exceptions.rb
|
70
|
+
- app/controllers/sessions.rb
|
71
|
+
- app/helpers
|
72
|
+
- app/helpers/application_helper.rb
|
73
|
+
- app/views
|
74
|
+
- app/views/exceptions
|
75
|
+
- app/views/exceptions/unauthenticated.html.erb
|
76
|
+
- app/views/layout
|
77
|
+
- app/views/layout/merb-auth-slice-password.html.erb
|
78
|
+
- public/javascripts
|
79
|
+
- public/javascripts/master.js
|
80
|
+
- public/stylesheets
|
81
|
+
- public/stylesheets/master.css
|
82
|
+
- stubs/app
|
83
|
+
- stubs/app/controllers
|
84
|
+
- stubs/app/controllers/application.rb
|
85
|
+
- stubs/app/controllers/main.rb
|
86
|
+
has_rdoc: true
|
87
|
+
homepage: http://merbivore.com/
|
88
|
+
post_install_message:
|
89
|
+
rdoc_options: []
|
90
|
+
|
91
|
+
require_paths:
|
92
|
+
- lib
|
93
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - ">="
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: "0"
|
98
|
+
version:
|
99
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: "0"
|
104
|
+
version:
|
105
|
+
requirements: []
|
106
|
+
|
107
|
+
rubyforge_project: merb
|
108
|
+
rubygems_version: 1.2.0
|
109
|
+
signing_key:
|
110
|
+
specification_version: 2
|
111
|
+
summary: Merb Slice that provides ...
|
112
|
+
test_files: []
|
113
|
+
|