ateam-merb-auth-old 0.0.1

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.
Files changed (69) hide show
  1. data/LICENSE +44 -0
  2. data/README +212 -0
  3. data/Rakefile +50 -0
  4. data/TODO +14 -0
  5. data/activerecord_generators/ma_migration/ma_migration_generator.rb +41 -0
  6. data/activerecord_generators/ma_migration/templates/schema/migrations/%time_stamp%_add_ma_user.rb +21 -0
  7. data/app/controllers/application.rb +7 -0
  8. data/app/controllers/sessions.rb +3 -0
  9. data/app/controllers/users.rb +3 -0
  10. data/app/helpers/application_helper.rb +64 -0
  11. data/app/mailers/user_mailer.rb +24 -0
  12. data/app/mailers/views/user_mailer/activation.text.erb +1 -0
  13. data/app/mailers/views/user_mailer/forgot_password.text.erb +5 -0
  14. data/app/mailers/views/user_mailer/signup.text.erb +7 -0
  15. data/app/views/layout/merb_auth.html.erb +16 -0
  16. data/app/views/sessions/new.html.erb +13 -0
  17. data/app/views/users/new.html.erb +21 -0
  18. data/datamapper_generators/ma_migration/ma_migration_generator.rb +38 -0
  19. data/datamapper_generators/ma_migration/templates/schema/migrations/add_ma_user.rb +21 -0
  20. data/lib/ateam-merb-auth-old.rb +1 -0
  21. data/lib/merb-auth.rb +184 -0
  22. data/lib/merb-auth/adapters/activerecord/init.rb +26 -0
  23. data/lib/merb-auth/adapters/activerecord/map.rb +44 -0
  24. data/lib/merb-auth/adapters/activerecord/model.rb +81 -0
  25. data/lib/merb-auth/adapters/common.rb +161 -0
  26. data/lib/merb-auth/adapters/datamapper/init.rb +28 -0
  27. data/lib/merb-auth/adapters/datamapper/map.rb +35 -0
  28. data/lib/merb-auth/adapters/datamapper/model.rb +72 -0
  29. data/lib/merb-auth/adapters/map.rb +0 -0
  30. data/lib/merb-auth/adapters/sequel/init.rb +26 -0
  31. data/lib/merb-auth/adapters/sequel/map.rb +36 -0
  32. data/lib/merb-auth/adapters/sequel/model.rb +86 -0
  33. data/lib/merb-auth/controller/controller.rb +113 -0
  34. data/lib/merb-auth/controller/sessions_base.rb +41 -0
  35. data/lib/merb-auth/controller/users_base.rb +58 -0
  36. data/lib/merb-auth/initializer.rb +47 -0
  37. data/lib/merb-auth/merbtasks.rb +168 -0
  38. data/lib/merb-auth/slicetasks.rb +102 -0
  39. data/plugins/forgotten_password/app/controllers/passwords.rb +90 -0
  40. data/plugins/forgotten_password/app/models/user.rb +52 -0
  41. data/plugins/forgotten_password/app/views/passwords/edit.html.erb +9 -0
  42. data/plugins/forgotten_password/app/views/passwords/new.html.erb +4 -0
  43. data/plugins/forgotten_password/forgotten_password.rb +6 -0
  44. data/plugins/forgotten_password/init.rb +8 -0
  45. data/plugins/forgotten_password/spec/controller_spec.rb +236 -0
  46. data/plugins/forgotten_password/spec/model_spec.rb +52 -0
  47. data/plugins/forgotten_password/spec/spec_helper.rb +36 -0
  48. data/public/javascripts/master.js +0 -0
  49. data/public/stylesheets/master.css +2 -0
  50. data/spec/controllers/plugins/test_plugin.rb +17 -0
  51. data/spec/controllers/sessions_spec.rb +118 -0
  52. data/spec/controllers/users_spec.rb +119 -0
  53. data/spec/mailers/user_mailer_spec.rb +75 -0
  54. data/spec/merb_auth_spec.rb +231 -0
  55. data/spec/models/ar_model_spec.rb +50 -0
  56. data/spec/models/common_spec.rb +0 -0
  57. data/spec/models/model_spec.rb +23 -0
  58. data/spec/models/sq_model_spec.rb +50 -0
  59. data/spec/shared_specs/shared_model_spec.rb +445 -0
  60. data/spec/spec_helper.rb +114 -0
  61. data/spec/spec_helpers/helpers.rb +18 -0
  62. data/spec/spec_helpers/valid_model_hashes.rb +10 -0
  63. data/stubs/app/controllers/application.rb +2 -0
  64. data/stubs/app/controllers/main.rb +2 -0
  65. data/stubs/app/mailers/views/activation.text.erb +1 -0
  66. data/stubs/app/mailers/views/signup.text.erb +7 -0
  67. data/stubs/app/views/sessions/new.html.erb +14 -0
  68. data/stubs/app/views/users/new.html.erb +18 -0
  69. metadata +120 -0
data/LICENSE ADDED
@@ -0,0 +1,44 @@
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.
21
+
22
+ Based on the Rails plugin by Rick Olsen
23
+
24
+ Licence of restful_authentication
25
+
26
+ Copyright (c) 2005 Rick Olson
27
+
28
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
29
+ this software and associated documentation files (the "Software"), to deal in
30
+ the Software without restriction, including without limitation the rights to
31
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
32
+ the Software, and to permit persons to whom the Software is furnished to do so,
33
+ subject to the following conditions:
34
+
35
+ The above copyright notice and this permission notice shall be included in all
36
+ copies or substantial portions of the Software.
37
+
38
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
39
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
40
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
41
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
42
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
43
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
44
+ =======
data/README ADDED
@@ -0,0 +1,212 @@
1
+ MerbAuth
2
+ =====================
3
+
4
+ A slice for the Merb framework.
5
+
6
+ MerbAuth is an authentication framework for the Merb Web Framework.
7
+
8
+ Currently DataMapper and ActiveRecord supportis available. It should be pretty easy to add your own.
9
+
10
+ MerbAuth provides your model with a mixin that gives your model all the required behavior
11
+ and links it to the controllers.
12
+
13
+ As an example. In your normal applications model directory create your user model.
14
+
15
+ class User
16
+ include MerbAuth::Adapter::DataMapper
17
+ include MerbAuth::Adapter::DataMapper::DefaultModelSetup
18
+ end
19
+
20
+ This will give the User class the required behavior and provide access to the class through
21
+ MerbAuth[:user] for other slice authors. To save key presses a handy constant is available
22
+ MA.
23
+
24
+ So using the MA constant you can declare your class like this
25
+
26
+ class Person
27
+ include MA::Adapter::DataMapper
28
+ include MerbAuth::Adapter::DataMapper::DefaultModelSetup
29
+ end
30
+
31
+ And in your custom slice, get access to the user class with MA[:user]
32
+
33
+ If you don't want to use the default setup for options. i.e. you want to see the properties in your model, change the
34
+ validations or whatever, you can just enter them into your model. To find out the required properties and validations that the
35
+ default uses use the rake task to get a print out that you can paste into your model.
36
+
37
+ rake slices:merb_auth:dm:setup # Datamapper defaults
38
+
39
+ rake slices:merb_auth:ar:setup # ActiveRecord defaults
40
+
41
+ ===Useful Helpers
42
+
43
+ The normal merb-auth helpers are available for your application, but also there is some consistent
44
+ helpers for other slice authors. Most notably is the controller helper
45
+
46
+ :current_ma_user also aliased as :current_person, or :current_user or whatever your user class name is.
47
+
48
+ === Controllers
49
+
50
+ The controllers that drive MerbAuth are always named MA::Users, and MA::Sessions
51
+
52
+ These are then mapped to appropriately named routes.
53
+
54
+ === Options
55
+
56
+ See notes after installation instructions
57
+
58
+ ------------------------------------------------------------------------------
59
+
60
+ Instructions for installation:
61
+
62
+ === Quick Install
63
+ # config/init.rb
64
+ dependency "merb-slices"
65
+ dependency "merb-auth"
66
+
67
+ # router
68
+ r.add_slice(:MerbAuth, "path/to/mount/at")
69
+
70
+ # Boot strap to your app
71
+ rake slices:merb_auth:install
72
+
73
+
74
+ === Long Install INstructions
75
+
76
+ # add the slice as a regular dependency
77
+
78
+ dependency 'merb-auth'
79
+
80
+ # if needed, configure which slices to load and in which order
81
+
82
+ Merb::Plugins.config[:merb_slices] = { :queue => ["MerbAuth", ...] }
83
+
84
+
85
+
86
+ === Configure Your Router
87
+
88
+ In config/router.rb you need to activate your brand new MerbAuth Slice. You can do this a number of ways.
89
+
90
+ The easiest way is like this:
91
+
92
+ r.add_slices
93
+
94
+ If you'd like to specify MerbAuth for mounting or other routeing options given in slices
95
+
96
+ r.add_slice(:MerbAuth)
97
+
98
+ By default this will mount the slice at /merb-auth. So your login url will be at
99
+
100
+ /merb-auth/login
101
+
102
+ If you'd like to specify a different mount point in your application do it like this.
103
+
104
+ r.add_slice(:MerbAuth, 'authentcation')
105
+
106
+ Your login url will now be /authentication/login, your signup url will be at /authentication/users/new
107
+
108
+ Alternatively you can just mount merb-auth directly onto your application. (Recommended)
109
+
110
+ r.add_slice(:MerbAuth, :path => "", :default_routes => false)
111
+
112
+ If you'd like to set more options, I suggest you look up the merb-slices documentation.
113
+
114
+
115
+
116
+ === Install your slice
117
+
118
+ You need to install the slice.
119
+
120
+ rake slices:merb_auth:install
121
+
122
+ === Configuring your install.
123
+
124
+ If you don't have any configuration applied some simple defaults will be assumed. You configure your installation
125
+ by writing it to the config/slices.yml file
126
+
127
+ ==== Login Field
128
+
129
+ By default merb-auth uses the "email" field to login. If you want to use a different field, even one of your own,
130
+ you can use the
131
+ \:login_field: jid
132
+
133
+ option. This example will set the "jid" field to be the default field used for logging in. One thing to bear in mind is
134
+ that this needs to actually be a field in the database.
135
+
136
+ ==== Routing options
137
+
138
+ \:route_path_model: first choice for model route path. defaults to "users" (used to make single_model_path and
139
+
140
+ \:route_path_session: first choice for the sessions route path. Defaults to "sessions"
141
+
142
+
143
+ ===== Named routes for the MA::Users resource
144
+
145
+ \:user:
146
+ \:new: # ||= :"new_#{single_model_name}"
147
+ \:show: # ||= :"#{single_model_name}"
148
+ \:edit: # ||= :"edit_#{single_model_name}"
149
+ \:delete: # ||= :"delete_#{single_model_name}"
150
+ \:index: # ||= :"#{plural_model_path}"
151
+ \:activate: # ||= :"#{single_model_name}_activation"
152
+
153
+
154
+ A named route called :login, :logout and :signup are also included.
155
+
156
+
157
+ === Including activation emails for account verification
158
+
159
+ To include activation email to your uses use the
160
+
161
+ \:use_activation: true option
162
+
163
+
164
+ To not use it either leave it out, or set it false like this
165
+
166
+ \:use_activation: false
167
+
168
+
169
+ If this option is turned off, it will just automatically complete the relevant fields
170
+ to have an activated user. This way, if you decide later that you'd like to include activation
171
+ then the previously signed up users are already fully active and ready to fit into the new behavior :)
172
+
173
+ There is also the subjects that you can setup for your emails
174
+
175
+ \:from_email
176
+ \:welcome_subject: # ||= "Welcome"
177
+ \:activation_subject: # ||= "Please Activate Your Account"
178
+
179
+ ------------------------------------------------------------------------------
180
+
181
+ === Override the Views
182
+
183
+ You can override the views MerbAuth provides. Lets face it. They're pretty basic.
184
+
185
+ To do this, you need to edit the files in the bootstrapped directories in your application.
186
+
187
+ Merb.root/slices/merb-auth/app/views/
188
+
189
+ ==== Example
190
+
191
+ To change the login form you'd head on over to
192
+
193
+ Merb.root/slices/merb-auth/app/views/users/new.html.(haml|erb)
194
+
195
+ And put in your own view there. The same is available for any of the components of merbful authentication
196
+
197
+ You can also add your own overrides to the controllers similarly.
198
+
199
+ === Using Your own Layout
200
+
201
+ To setup merbful authentication to use your own layout use a before_app_loads block.
202
+
203
+ ==== Example
204
+
205
+ Merb::Slices.config[:merb_auth] = { :layout => :application }
206
+
207
+ === Migrations
208
+
209
+ There is a migration task for merb-auth to generate your migrations. Make sure you have use_orm selected so that
210
+ it knows which generator to use. Then from your host application
211
+
212
+ rake slices:merb_auth:generate_migration
data/Rakefile ADDED
@@ -0,0 +1,50 @@
1
+ require 'rubygems'
2
+ require 'rake/gempackagetask'
3
+ require 'spec/rake/spectask'
4
+ require 'merb-core/version'
5
+ require 'merb-core/test/tasks/spectasks'
6
+ require 'merb-core/tasks/merb_rake_helper'
7
+
8
+ NAME = "a-team-merb-auth"
9
+ AUTHOR = "Merb Core"
10
+ EMAIL = "has.sox@gmail.com"
11
+ HOMEPAGE = "http://merbivore.com/"
12
+ SUMMARY = "Merb Slice that provides authentication"
13
+ GEM_VERSION = "0.1.0"
14
+
15
+ spec = Gem::Specification.new do |s|
16
+ s.rubyforge_project = 'merb'
17
+ s.name = NAME
18
+ s.version = GEM_VERSION
19
+ s.platform = Gem::Platform::RUBY
20
+ s.has_rdoc = true
21
+ s.extra_rdoc_files = ["README", "LICENSE", 'TODO']
22
+ s.summary = SUMMARY
23
+ s.description = s.summary
24
+ s.author = AUTHOR
25
+ s.email = EMAIL
26
+ s.homepage = HOMEPAGE
27
+ s.add_dependency('merb-slices', '>= 0.9.4')
28
+ s.add_dependency('merb-mailer', '>= 0.9.4')
29
+ s.add_dependency('merb_helpers', '>= 0.9.4')
30
+ s.require_path = 'lib'
31
+ s.files = %w(LICENSE README Rakefile TODO) + Dir.glob("{lib,spec,app,public,stubs,activerecord_generators,datamapper_generators,plugins}/**/*")
32
+ end
33
+
34
+ Rake::GemPackageTask.new(spec) do |pkg|
35
+ pkg.gem_spec = spec
36
+ end
37
+
38
+ desc "Install MerbAuth as a gem"
39
+ task :install => [:package] do
40
+ sh %{sudo gem install pkg/#{NAME}-#{GEM_VERSION} --no-update-sources}
41
+ end
42
+
43
+ namespace :jruby do
44
+
45
+ desc "Run :package and install the resulting .gem with jruby"
46
+ task :install => :package do
47
+ sh %{#{sudo} jruby -S gem install #{install_home} pkg/#{NAME}-#{GEM_VERSION}.gem --no-rdoc --no-ri}
48
+ end
49
+
50
+ end
data/TODO ADDED
@@ -0,0 +1,14 @@
1
+ TODO:
2
+
3
+ - Fix MerbAuth.description and MerbAuth.version
4
+ - Fix LICENSE with your name
5
+ - Fix Rakefile with your name and contact info
6
+ - Add your code to lib/merb_auth.rb
7
+ - Add your Merb rake tasks to lib/merb_auth/merbtasks.rb
8
+
9
+ Remove anything that you don't need:
10
+
11
+ - app/controllers/main.rb MerbAuth::Main controller
12
+ - app/views/layout/merb_auth.html.erb
13
+ - spec/controllers/main_spec.rb controller specs
14
+ - public/* any public files
@@ -0,0 +1,41 @@
1
+ class MaMigrationGenerator < Merb::GeneratorBase
2
+
3
+ attr_accessor :plural_name, :single_name, :time_stamp
4
+
5
+ def initialize(runtime_args, runtime_options = {})
6
+ @base = File.dirname(__FILE__)
7
+ super
8
+ @name = args.shift
9
+ end
10
+
11
+ def manifest
12
+ record do |m|
13
+ @m = m
14
+
15
+ @time_stamp = Time.now.utc.strftime("%Y%m%d%H%M%S")
16
+ @table_name = @name.split("::").last.snake_case.singularize.pluralize
17
+
18
+ @assigns = {
19
+ :time_stamp => @time_stamp,
20
+ :class_name => @name,
21
+ :table_name => @table_name
22
+ }
23
+
24
+ copy_dirs
25
+ copy_files
26
+ end
27
+
28
+ end
29
+
30
+ protected
31
+ def banner
32
+ <<-EOS
33
+ Creates a migration for merb-auth user model
34
+
35
+ USAGE: #{$0} #{spec.name} name"
36
+ EOS
37
+ end
38
+
39
+ end
40
+
41
+
@@ -0,0 +1,21 @@
1
+ class AddMaUser < ActiveRecord::Migration
2
+ def self.up
3
+ create_table "<%= table_name %>", :force => true do |t|
4
+ t.column :login, :string
5
+ t.column :email, :string
6
+ t.column :crypted_password, :string, :limit => 40
7
+ t.column :salt, :string, :limit => 40
8
+ t.column :created_at, :datetime
9
+ t.column :updated_at, :datetime
10
+ t.column :remember_token, :string
11
+ t.column :remember_token_expires_at, :datetime
12
+ t.column :activation_code, :string, :limit => 40
13
+ t.column :activated_at, :datetime
14
+ t.column :password_reset_key, :string
15
+ end
16
+ end
17
+
18
+ def self.down
19
+ drop_table "<%= table_name %>"
20
+ end
21
+ end
@@ -0,0 +1,7 @@
1
+ module MerbAuth
2
+ class Application < Merb::Controller
3
+
4
+ controller_for_slice
5
+
6
+ end
7
+ end
@@ -0,0 +1,3 @@
1
+ class MerbAuth::Sessions < MerbAuth::Application
2
+
3
+ end
@@ -0,0 +1,3 @@
1
+ class MerbAuth::Users < MerbAuth::Application
2
+
3
+ end
@@ -0,0 +1,64 @@
1
+ module Merb
2
+ module MerbAuth
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
+ File.join(::MerbAuth.public_dir_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
+ File.join(::MerbAuth.app_dir_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
+ File.join(::MerbAuth.dir_for(type), *segments)
60
+ end
61
+
62
+ end
63
+ end
64
+ end