rules_engine_users 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.
- data/.document +5 -0
- data/.gitignore +22 -0
- data/LICENSE +20 -0
- data/README.rdoc +17 -0
- data/Rakefile +47 -0
- data/VERSION +1 -0
- data/init.rb +1 -0
- data/lib/rules_engine/controller_user_mail.rb +29 -0
- data/lib/rules_engine/controller_users.rb +170 -0
- data/lib/rules_engine_users.rb +4 -0
- data/rails_generators/USAGE +97 -0
- data/rails_generators/manifests/rules_engine_users.rb +79 -0
- data/rails_generators/manifests/rules_engine_users.yml +32 -0
- data/rails_generators/rules_engine_users_generator.rb +21 -0
- data/rails_generators/templates/app/controllers/admin/users_controller.rb +64 -0
- data/rails_generators/templates/app/controllers/users_controller.rb +215 -0
- data/rails_generators/templates/app/models/user.rb +113 -0
- data/rails_generators/templates/app/models/user_mailer.rb +26 -0
- data/rails_generators/templates/app/models/user_observer.rb +19 -0
- data/rails_generators/templates/app/views/admin/users/_form.html.erb +6 -0
- data/rails_generators/templates/app/views/admin/users/edit.html.erb +18 -0
- data/rails_generators/templates/app/views/admin/users/index.html.erb +52 -0
- data/rails_generators/templates/app/views/admin/users/new.html.erb +17 -0
- data/rails_generators/templates/app/views/admin/users/show.html.erb +15 -0
- data/rails_generators/templates/app/views/user_mailer/forgot_password.html.erb +11 -0
- data/rails_generators/templates/app/views/user_mailer/welcome_message.html.erb +11 -0
- data/rails_generators/templates/app/views/users/change_form.html.erb +22 -0
- data/rails_generators/templates/app/views/users/details.html.erb +11 -0
- data/rails_generators/templates/app/views/users/login_form.html.erb +35 -0
- data/rails_generators/templates/app/views/users/pswd_change_form.html.erb +20 -0
- data/rails_generators/templates/app/views/users/pswd_forgot_form.html.erb +18 -0
- data/rails_generators/templates/app/views/users/pswd_reset_form.html.erb +22 -0
- data/rails_generators/templates/app/views/users/welcome_form.html.erb +21 -0
- data/rails_generators/templates/db/migrate/20100104014507_create_users.rb +41 -0
- data/rails_generators/templates/doc/README.rules_engine_users +122 -0
- data/rails_generators/templates/doc/README.rules_engine_users_paths +12 -0
- data/rails_generators/templates/features/admin/user/edit.feature +46 -0
- data/rails_generators/templates/features/admin/user/index.feature +78 -0
- data/rails_generators/templates/features/admin/user/new.feature +26 -0
- data/rails_generators/templates/features/admin/user/show.feature +22 -0
- data/rails_generators/templates/features/admin/user/step_definitions/edit_steps.rb +3 -0
- data/rails_generators/templates/features/admin/user/step_definitions/index_steps.rb +13 -0
- data/rails_generators/templates/features/admin/user/step_definitions/show_steps.rb +3 -0
- data/rails_generators/templates/features/support/blueprint_users.rb +14 -0
- data/rails_generators/templates/features/user/change.feature +37 -0
- data/rails_generators/templates/features/user/details.feature +15 -0
- data/rails_generators/templates/features/user/login.feature +65 -0
- data/rails_generators/templates/features/user/pswd_change.feature +46 -0
- data/rails_generators/templates/features/user/pswd_forgot.feature +32 -0
- data/rails_generators/templates/features/user/pswd_reset.feature +52 -0
- data/rails_generators/templates/features/user/step_definitions/login_steps.rb +46 -0
- data/rails_generators/templates/features/user/step_definitions/pswd_reset_steps.rb +15 -0
- data/rails_generators/templates/features/user/step_definitions/welcome_steps.rb +15 -0
- data/rails_generators/templates/features/user/welcome.feature +52 -0
- data/rails_generators/templates/spec/controllers/admin/users_controller_spec.rb +191 -0
- data/rails_generators/templates/spec/controllers/users_controller_spec.rb +579 -0
- data/rails_generators/templates/spec/models/user_mailer_spec.rb +39 -0
- data/rails_generators/templates/spec/models/user_observer_spec.rb +56 -0
- data/rails_generators/templates/spec/models/user_spec.rb +253 -0
- data/rails_generators/templates/spec/support/rules_engine_macros.rb +16 -0
- data/rules_engine_users.gemspec +141 -0
- data/spec/railsenv/app/controllers/application_controller.rb +10 -0
- data/spec/railsenv/config/boot.rb +110 -0
- data/spec/railsenv/config/database.yml +22 -0
- data/spec/railsenv/config/environment.rb +41 -0
- data/spec/railsenv/config/environments/development.rb +17 -0
- data/spec/railsenv/config/environments/production.rb +28 -0
- data/spec/railsenv/config/environments/test.rb +28 -0
- data/spec/railsenv/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/railsenv/config/initializers/inflections.rb +10 -0
- data/spec/railsenv/config/initializers/mime_types.rb +5 -0
- data/spec/railsenv/config/initializers/new_rails_defaults.rb +19 -0
- data/spec/railsenv/config/initializers/session_store.rb +15 -0
- data/spec/railsenv/config/locales/en.yml +5 -0
- data/spec/railsenv/config/routes.rb +43 -0
- data/spec/railsenv/db/test.sqlite3 +1 -0
- data/spec/railsenv/log/debug.log +1 -0
- data/spec/railsenv/log/test.log +1 -0
- data/spec/rcov.opts +3 -0
- data/spec/rules_engine/controller_user_mail_spec.rb +43 -0
- data/spec/rules_engine/controller_users_spec.rb +337 -0
- data/spec/spec.opts +4 -0
- data/spec/spec_helper.rb +30 -0
- data/tasks/rspec.rake +18 -0
- metadata +180 -0
data/.document
ADDED
data/.gitignore
ADDED
data/LICENSE
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
Copyright (c) 2009 Chris Douglas
|
|
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.rdoc
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
= rules_engine_users
|
|
2
|
+
|
|
3
|
+
Description goes here.
|
|
4
|
+
|
|
5
|
+
== Note on Patches/Pull Requests
|
|
6
|
+
|
|
7
|
+
* Fork the project.
|
|
8
|
+
* Make your feature addition or bug fix.
|
|
9
|
+
* Add tests for it. This is important so I don't break it in a
|
|
10
|
+
future version unintentionally.
|
|
11
|
+
* Commit, do not mess with rakefile, version, or history.
|
|
12
|
+
(if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
|
|
13
|
+
* Send me a pull request. Bonus points for topic branches.
|
|
14
|
+
|
|
15
|
+
== Copyright
|
|
16
|
+
|
|
17
|
+
Copyright (c) 2010 Chris Douglas. See LICENSE for details.
|
data/Rakefile
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
require 'rubygems'
|
|
2
|
+
require 'rake'
|
|
3
|
+
|
|
4
|
+
begin
|
|
5
|
+
require 'jeweler'
|
|
6
|
+
Jeweler::Tasks.new do |gem|
|
|
7
|
+
gem.name = "rules_engine_users"
|
|
8
|
+
gem.summary = %Q{Manage users and authentication}
|
|
9
|
+
gem.description = %Q{Manage users and authentication}
|
|
10
|
+
gem.email = "dougo.chris@gmail.com"
|
|
11
|
+
gem.homepage = "http://github.com/dougochris/rules_engine_users"
|
|
12
|
+
gem.authors = ["Chris Douglas"]
|
|
13
|
+
gem.add_development_dependency "rspec", ">= 1.2.9"
|
|
14
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
|
15
|
+
end
|
|
16
|
+
Jeweler::GemcutterTasks.new
|
|
17
|
+
rescue LoadError
|
|
18
|
+
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
Dir["#{File.dirname(__FILE__)}/tasks/*.rake"].sort.each { |ext| load ext }
|
|
22
|
+
|
|
23
|
+
require 'spec/rake/spectask'
|
|
24
|
+
Spec::Rake::SpecTask.new(:spec) do |spec|
|
|
25
|
+
spec.libs << 'lib' << 'spec'
|
|
26
|
+
spec.spec_files = FileList['spec/**/*_spec.rb']
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
Spec::Rake::SpecTask.new(:rcov) do |spec|
|
|
30
|
+
spec.libs << 'lib' << 'spec'
|
|
31
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
|
32
|
+
spec.rcov = true
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
task :spec => :check_dependencies
|
|
36
|
+
|
|
37
|
+
task :default => :spec
|
|
38
|
+
|
|
39
|
+
require 'rake/rdoctask'
|
|
40
|
+
Rake::RDocTask.new do |rdoc|
|
|
41
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
|
42
|
+
|
|
43
|
+
rdoc.rdoc_dir = 'rdoc'
|
|
44
|
+
rdoc.title = "rules_engine_users #{version}"
|
|
45
|
+
rdoc.rdoc_files.include('README*')
|
|
46
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
|
47
|
+
end
|
data/VERSION
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
0.0.1
|
data/init.rb
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + "/lib/rules_engine_users")
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
module RulesEngine
|
|
2
|
+
class ControllerUserMail
|
|
3
|
+
|
|
4
|
+
@@host = "localhost:3000"
|
|
5
|
+
def self.host
|
|
6
|
+
@@host
|
|
7
|
+
end
|
|
8
|
+
def self.host=(name)
|
|
9
|
+
@@host = name
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
@@from = "Do Not Reply <do_not_reply@localhost:3000>"
|
|
13
|
+
def self.from
|
|
14
|
+
@@from
|
|
15
|
+
end
|
|
16
|
+
def self.from=(from)
|
|
17
|
+
@@from = from
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
@@prefix = ""
|
|
21
|
+
def self.prefix
|
|
22
|
+
@@prefix
|
|
23
|
+
end
|
|
24
|
+
def self.prefix=(name)
|
|
25
|
+
@@prefix = name
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
end
|
|
29
|
+
end
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
module RulesEngine
|
|
2
|
+
module ControllerUsers
|
|
3
|
+
######### Requires the following paths
|
|
4
|
+
######### root_path
|
|
5
|
+
|
|
6
|
+
USER_ACCESS_LEVEL = [
|
|
7
|
+
["Administrator", User::ACCESS_LEVEL_ADMIN],
|
|
8
|
+
["Account Disabled", User::ACCESS_LEVEL_DISABLED]
|
|
9
|
+
]
|
|
10
|
+
|
|
11
|
+
# Inclusion hook to make #current_user #logged_in? and #logged_in_as_admin?
|
|
12
|
+
# available as ActionView helper methods.
|
|
13
|
+
def self.included(base)
|
|
14
|
+
base.send :helper_method, :current_user, :logged_in?, :logged_in_as_admin?, :logged_in_disabled?, :user_access_level, :user_access_levels
|
|
15
|
+
base.send :before_filter, :set_timezone
|
|
16
|
+
|
|
17
|
+
base.class_eval do
|
|
18
|
+
extend ClassMethods
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
# Accesses the current user from the session.
|
|
23
|
+
# Future calls avoid the database because nil is not equal to false.
|
|
24
|
+
def current_user
|
|
25
|
+
return nil if @current_user == false
|
|
26
|
+
@current_user || (login_from_session || login_from_basic_auth || login_from_cookie)
|
|
27
|
+
@current_user || nil
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
# Returns true or false if the user is logged in.
|
|
31
|
+
# Preloads @current_user with the user model if they're logged in.
|
|
32
|
+
def logged_in?
|
|
33
|
+
!!current_user
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def logged_in_as_admin?
|
|
37
|
+
logged_in? && current_user.access_level == User::ACCESS_LEVEL_ADMIN
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def logged_in_disabled?
|
|
41
|
+
logged_in? && current_user.access_level == User::ACCESS_LEVEL_DISABLED
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def login_required
|
|
45
|
+
unless logged_in?
|
|
46
|
+
flash[:error]="This page requires you to login"
|
|
47
|
+
access_denied
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def admin_access_required
|
|
52
|
+
login_required
|
|
53
|
+
return unless logged_in?
|
|
54
|
+
unless current_user.access_level == User::ACCESS_LEVEL_ADMIN
|
|
55
|
+
flash[:error]="This page requires administrator access"
|
|
56
|
+
user_access_denied
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
def user_access_level(user)
|
|
61
|
+
match = USER_ACCESS_LEVEL.find {|value| value[1] == user.access_level}
|
|
62
|
+
match.nil? ? "unknown" : match[0]
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
def user_access_levels
|
|
66
|
+
USER_ACCESS_LEVEL.sort {|a, b| a[1] <=> b[1]}
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
def set_timezone
|
|
70
|
+
Time.zone = logged_in? ? current_user.time_zone : "Eastern Time (US & Canada)"
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
module ClassMethods
|
|
74
|
+
def define_access_level name, access_level
|
|
75
|
+
(class << self; self end).instance_eval do
|
|
76
|
+
USER_ACCESS_LEVEL << [name.to_s.titleize, access_level]
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
(class << ActionController::Base; self end).instance_eval do
|
|
80
|
+
define_method "#{name}_access_level" do
|
|
81
|
+
access_level
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
define_method "logged_in_as_#{name}?" do
|
|
86
|
+
logged_in? && current_user.access_level >= access_level
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
define_method "#{name}_access_required" do
|
|
90
|
+
login_required
|
|
91
|
+
return unless logged_in?
|
|
92
|
+
unless current_user.access_level >= access_level
|
|
93
|
+
flash[:error]="This page requires #{name} access"
|
|
94
|
+
user_access_denied
|
|
95
|
+
end
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
self.send :helper_method, "logged_in_as_#{name}"
|
|
99
|
+
end
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
protected
|
|
103
|
+
# Store the given user id in the session.
|
|
104
|
+
def current_user=(new_user)
|
|
105
|
+
|
|
106
|
+
session[:user_id] = new_user ? new_user.id : nil
|
|
107
|
+
@current_user = new_user || false # store false
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
def access_denied
|
|
111
|
+
respond_to do |format|
|
|
112
|
+
format.html do
|
|
113
|
+
session[:return_to] = request.request_uri
|
|
114
|
+
redirect_to user_login_path
|
|
115
|
+
return
|
|
116
|
+
end
|
|
117
|
+
format.js do
|
|
118
|
+
render :update do |page|
|
|
119
|
+
page << "window.location.href = '#{user_login_path}';"
|
|
120
|
+
end
|
|
121
|
+
end
|
|
122
|
+
# format.any do
|
|
123
|
+
# request_http_basic_authentication 'Web Password'
|
|
124
|
+
# end
|
|
125
|
+
# end
|
|
126
|
+
end
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
def user_access_denied
|
|
130
|
+
respond_to do |format|
|
|
131
|
+
format.html do
|
|
132
|
+
redirect_to root_path
|
|
133
|
+
end
|
|
134
|
+
format.js do
|
|
135
|
+
render :update do |page|
|
|
136
|
+
page << "window.location.href = '#{root_path}';"
|
|
137
|
+
end
|
|
138
|
+
end
|
|
139
|
+
# format.any do
|
|
140
|
+
# request_http_basic_authentication 'Web Password'
|
|
141
|
+
# end
|
|
142
|
+
end
|
|
143
|
+
end
|
|
144
|
+
|
|
145
|
+
# Called from #current_user. First attempt to login by the user id stored in the session.
|
|
146
|
+
def login_from_session
|
|
147
|
+
self.current_user = User.find_by_id(session[:user_id]) if session[:user_id]
|
|
148
|
+
end
|
|
149
|
+
|
|
150
|
+
# Called from #current_user. Now, attempt to login by basic authentication information.
|
|
151
|
+
def login_from_basic_auth
|
|
152
|
+
authenticate_with_http_basic do |name, password|
|
|
153
|
+
self.current_user = User.authenticate_by_login(name, password) || User.authenticate_by_email(name, password)
|
|
154
|
+
end
|
|
155
|
+
end
|
|
156
|
+
|
|
157
|
+
# Called from #current_user. Finaly, attempt to login by an expiring token in the cookie.
|
|
158
|
+
def login_from_cookie
|
|
159
|
+
user = cookies[:auth_token] && User.authenticate_by_remember_token(cookies[:auth_token])
|
|
160
|
+
if user
|
|
161
|
+
cookies[:auth_token] = { :value => user.remember_token, :expires => user.remember_token_expires_at }
|
|
162
|
+
self.current_user = user
|
|
163
|
+
end
|
|
164
|
+
end
|
|
165
|
+
end
|
|
166
|
+
end
|
|
167
|
+
|
|
168
|
+
ActionController::Base.class_eval do
|
|
169
|
+
include RulesEngine::ControllerUsers
|
|
170
|
+
end
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
***************************************************************************
|
|
2
|
+
|
|
3
|
+
*** EDIT config/routes.rb
|
|
4
|
+
map.root :controller => 'preview', :action => 'index' # only if map.root not set
|
|
5
|
+
|
|
6
|
+
map.with_options :controller => 'users', :path_prefix => '/user', :name_prefix => 'user_' do |user|
|
|
7
|
+
user.login '/', :action => 'login_form', :conditions => { :method => :get }
|
|
8
|
+
user.login '/', :action => 'login', :conditions => { :method => :post }
|
|
9
|
+
user.logout '/logout', :action => 'logout'
|
|
10
|
+
user.pswd_forgot '/pswd_forgot', :action => 'pswd_forgot_form', :conditions => { :method => :get }
|
|
11
|
+
user.pswd_forgot '/pswd_forgot', :action => 'pswd_forgot', :conditions => { :method => :post }
|
|
12
|
+
user.pswd_change '/pswd_change', :action => 'pswd_change_form', :conditions => { :method => :get }
|
|
13
|
+
user.pswd_change '/pswd_change', :action => 'pswd_change', :conditions => { :method => :post }
|
|
14
|
+
user.details '/user_details', :action => 'user_details', :conditions => { :method => :get }
|
|
15
|
+
user.change '/user_change', :action => 'user_change_form', :conditions => { :method => :get }
|
|
16
|
+
user.change '/user_change', :action => 'user_change', :conditions => { :method => :put }
|
|
17
|
+
user.pswd_reset '/pswd_reset', :action => 'pswd_reset_form', :conditions => { :method => :get }
|
|
18
|
+
user.pswd_reset '/pswd_reset', :action => 'pswd_reset', :conditions => { :method => :post }
|
|
19
|
+
user.welcome '/welcome', :action => 'welcome_form', :conditions => { :method => :get }
|
|
20
|
+
user.welcome '/welcome', :action => 'welcome', :conditions => { :method => :post }
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
map.namespace :admin do |admin|
|
|
24
|
+
admin.resources :users, :controller => 'users'
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
*** EDIT config/environment.rb
|
|
28
|
+
config.gem 'will_paginate'
|
|
29
|
+
config.gem 'dougo_view_helpers'
|
|
30
|
+
config.gem 'dougo_model_helpers'
|
|
31
|
+
config.gem 'dougo_user_helpers'
|
|
32
|
+
|
|
33
|
+
config.active_record.observers = :user_observer
|
|
34
|
+
|
|
35
|
+
ActionController::Base.define_access_level(:more_access, 70)
|
|
36
|
+
ActionController::Base.define_access_level(:less_access, 60)
|
|
37
|
+
|
|
38
|
+
*** EDIT config/environments/producton.rb
|
|
39
|
+
ActionMailer::Base.delivery_method = :smtp
|
|
40
|
+
ActionMailer::Base.smtp_settings = {
|
|
41
|
+
:address => '...',
|
|
42
|
+
:port => 25,
|
|
43
|
+
. . .
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
Dougo::ControllerUserMail.host = 'domain.com'
|
|
47
|
+
Dougo::ControllerUserMail.from = 'domain.com'
|
|
48
|
+
Dougo::ControllerUserMail.prefix = 'My Cool App'
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
*** EDIT config/environments/test.rb
|
|
52
|
+
|
|
53
|
+
config.gem 'cucumber-rails', :lib => false, :version => '>=0.3.0'
|
|
54
|
+
config.gem 'database_cleaner', :lib => false, :version => '>=0.5.0'
|
|
55
|
+
config.gem 'webrat', :lib => false, :version => '>=0.7.0'
|
|
56
|
+
|
|
57
|
+
config.gem "rspec", :version => '>=1.3.0', :lib => false
|
|
58
|
+
config.gem "rspec-rails", :version => '>=1.3.2', :lib => false
|
|
59
|
+
config.gem "faker", :version => '>=0.3.1', :lib => false
|
|
60
|
+
|
|
61
|
+
config.gem "machinist", :version => '>=1.0.6', :lib => false
|
|
62
|
+
config.gem 'rcov', :version => '>=0.9.8', :lib => false
|
|
63
|
+
config.gem 'remarkable_rails', :version => '>=3.1.13', :lib => false
|
|
64
|
+
|
|
65
|
+
require 'machinist/active_record'
|
|
66
|
+
require 'sham'
|
|
67
|
+
require 'faker'
|
|
68
|
+
require 'remarkable_rails'
|
|
69
|
+
|
|
70
|
+
*** EDIT spec/spec_helper.rb
|
|
71
|
+
Spec::Runner.configure do |config|
|
|
72
|
+
...
|
|
73
|
+
|
|
74
|
+
config.before(:each, :behaviour_type => :controller) do
|
|
75
|
+
@controller.instance_eval { flash.stub!(:sweep) }
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
*** RUN rake db:migrate
|
|
79
|
+
|
|
80
|
+
*** EDIT app/views/preview/index.html.erb
|
|
81
|
+
<h1>User Pages</h1>
|
|
82
|
+
<ul>
|
|
83
|
+
<li><a href='/user/'>Login</a></li>
|
|
84
|
+
<li><a href='/user/logout'>Logout</a></li>
|
|
85
|
+
<li><a href='/user/user_details'>Your Details</a></li>
|
|
86
|
+
<li><a href='/user/pswd_forgot'>Password Forgot</a></li>
|
|
87
|
+
<li><a href='/user/pswd_change'>Password Change</a></li>
|
|
88
|
+
<li><a href='/user/pswd_reset'>Password Reset (Check logs for reset token)</a></li>
|
|
89
|
+
<li><a href='/user/welcome'>User Welcome (Check logs for reset token)</a></li>
|
|
90
|
+
<li></li>
|
|
91
|
+
<li><a href='/admin/users'>Admin Users</a></li>
|
|
92
|
+
</ul>
|
|
93
|
+
|
|
94
|
+
restart app and goto http://localhost:3000/preview
|
|
95
|
+
|
|
96
|
+
**************************************************************************
|
|
97
|
+
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
class RulesEngineUsersManifest
|
|
2
|
+
def self.populate_record(m)
|
|
3
|
+
|
|
4
|
+
%W(
|
|
5
|
+
app/controllers
|
|
6
|
+
app/controllers/admin
|
|
7
|
+
app/models
|
|
8
|
+
app/views/admin/users
|
|
9
|
+
app/views/user_mailer
|
|
10
|
+
app/views/users
|
|
11
|
+
db/migrate
|
|
12
|
+
doc
|
|
13
|
+
features/admin/user
|
|
14
|
+
features/admin/user/step_definitions
|
|
15
|
+
features/support
|
|
16
|
+
features/user
|
|
17
|
+
features/user/step_definitions
|
|
18
|
+
spec/controllers
|
|
19
|
+
spec/controllers/admin
|
|
20
|
+
spec/models
|
|
21
|
+
spec/support
|
|
22
|
+
).each do |dirname|
|
|
23
|
+
m.directory dirname
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
%W(
|
|
27
|
+
app/controllers/admin/users_controller.rb
|
|
28
|
+
app/controllers/users_controller.rb
|
|
29
|
+
app/models/user.rb
|
|
30
|
+
app/models/user_mailer.rb
|
|
31
|
+
app/models/user_observer.rb
|
|
32
|
+
app/views/admin/users/_form.html.erb
|
|
33
|
+
app/views/admin/users/edit.html.erb
|
|
34
|
+
app/views/admin/users/index.html.erb
|
|
35
|
+
app/views/admin/users/new.html.erb
|
|
36
|
+
app/views/admin/users/show.html.erb
|
|
37
|
+
app/views/user_mailer/forgot_password.html.erb
|
|
38
|
+
app/views/user_mailer/welcome_message.html.erb
|
|
39
|
+
app/views/users/change_form.html.erb
|
|
40
|
+
app/views/users/details.html.erb
|
|
41
|
+
app/views/users/login_form.html.erb
|
|
42
|
+
app/views/users/pswd_change_form.html.erb
|
|
43
|
+
app/views/users/pswd_forgot_form.html.erb
|
|
44
|
+
app/views/users/pswd_reset_form.html.erb
|
|
45
|
+
app/views/users/welcome_form.html.erb
|
|
46
|
+
db/migrate/20100104014507_create_users.rb
|
|
47
|
+
doc/README.rules_engine_users
|
|
48
|
+
doc/README.rules_engine_users_paths
|
|
49
|
+
features/admin/user/edit.feature
|
|
50
|
+
features/admin/user/index.feature
|
|
51
|
+
features/admin/user/new.feature
|
|
52
|
+
features/admin/user/show.feature
|
|
53
|
+
features/admin/user/step_definitions/edit_steps.rb
|
|
54
|
+
features/admin/user/step_definitions/index_steps.rb
|
|
55
|
+
features/admin/user/step_definitions/show_steps.rb
|
|
56
|
+
features/support/blueprint_users.rb
|
|
57
|
+
features/user/change.feature
|
|
58
|
+
features/user/details.feature
|
|
59
|
+
features/user/login.feature
|
|
60
|
+
features/user/pswd_change.feature
|
|
61
|
+
features/user/pswd_forgot.feature
|
|
62
|
+
features/user/pswd_reset.feature
|
|
63
|
+
features/user/step_definitions/login_steps.rb
|
|
64
|
+
features/user/step_definitions/pswd_reset_steps.rb
|
|
65
|
+
features/user/step_definitions/welcome_steps.rb
|
|
66
|
+
features/user/welcome.feature
|
|
67
|
+
spec/controllers/admin/users_controller_spec.rb
|
|
68
|
+
spec/controllers/users_controller_spec.rb
|
|
69
|
+
spec/models/user_mailer_spec.rb
|
|
70
|
+
spec/models/user_observer_spec.rb
|
|
71
|
+
spec/models/user_spec.rb
|
|
72
|
+
spec/support/rules_engine_macros.rb
|
|
73
|
+
).each do |filename|
|
|
74
|
+
m.file filename, filename
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
end
|
|
79
|
+
end
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
contents :
|
|
2
|
+
- app/views/admin/users
|
|
3
|
+
- app/views/user_mailer
|
|
4
|
+
- app/views/users
|
|
5
|
+
|
|
6
|
+
- features/user
|
|
7
|
+
- features/admin/user
|
|
8
|
+
|
|
9
|
+
files :
|
|
10
|
+
- doc/README.rules_engine_users
|
|
11
|
+
- doc/README.rules_engine_users_paths
|
|
12
|
+
|
|
13
|
+
- app/controllers/users_controller.rb
|
|
14
|
+
|
|
15
|
+
- app/controllers/admin/users_controller.rb
|
|
16
|
+
|
|
17
|
+
- app/models/user.rb
|
|
18
|
+
- app/models/user_mailer.rb
|
|
19
|
+
- app/models/user_observer.rb
|
|
20
|
+
|
|
21
|
+
- db/migrate/20100104014507_create_users.rb
|
|
22
|
+
|
|
23
|
+
- spec/controllers/users_controller_spec.rb
|
|
24
|
+
- spec/controllers/admin/users_controller_spec.rb
|
|
25
|
+
|
|
26
|
+
- spec/models/user_spec.rb
|
|
27
|
+
- spec/models/user_mailer_spec.rb
|
|
28
|
+
- spec/models/user_observer_spec.rb
|
|
29
|
+
|
|
30
|
+
- spec/support/rules_engine_macros.rb
|
|
31
|
+
|
|
32
|
+
- features/support/blueprint_users.rb
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/manifests/rules_engine_users')
|
|
2
|
+
|
|
3
|
+
class RulesEngineUsersGenerator < Rails::Generator::Base
|
|
4
|
+
|
|
5
|
+
def initialize(runtime_args, runtime_options = {})
|
|
6
|
+
super
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def after_generate
|
|
10
|
+
puts ''
|
|
11
|
+
puts '******************************************************'
|
|
12
|
+
puts 'open doc/README.rules_engine_users for more instructions'
|
|
13
|
+
puts ''
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def manifest
|
|
17
|
+
record do |m|
|
|
18
|
+
RulesEngineUsersManifest.populate_record(m)
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
class Admin::UsersController < ApplicationController
|
|
2
|
+
|
|
3
|
+
# before_filter :login_required
|
|
4
|
+
before_filter :admin_access_required
|
|
5
|
+
|
|
6
|
+
before_filter :only => [:show, :edit, :update, :destroy] do |controller|
|
|
7
|
+
controller.re_load_model :user, {:param_id => :id, :redirect_path => :admin_users_path}
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def index
|
|
11
|
+
klass = User
|
|
12
|
+
|
|
13
|
+
if params[:query_type] == 'email'
|
|
14
|
+
klass = klass.by_ge_email(params[:query]) unless params[:query].blank?
|
|
15
|
+
klass = klass.order_email
|
|
16
|
+
elsif params[:query_type] == 'login'
|
|
17
|
+
klass = klass.by_ge_login(params[:query]) unless params[:query].blank?
|
|
18
|
+
klass = klass.order_login
|
|
19
|
+
elsif params[:query_type] == 'full_name'
|
|
20
|
+
klass = klass.by_ge_full_name(params[:query]) unless params[:query].blank?
|
|
21
|
+
klass = klass.order_full_name
|
|
22
|
+
else
|
|
23
|
+
klass = klass.order_full_name
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
@users = klass.paginate(:page => params[:page], :per_page => 20)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def show
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def new
|
|
33
|
+
@user = User.new(:time_zone => 'Eastern Time (US & Canada)', :access_level => User::ACCESS_LEVEL_DISABLED)
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def create
|
|
37
|
+
@user = User.new(params[:user])
|
|
38
|
+
if @user.save
|
|
39
|
+
flash[:success] = "Welcome email sent to new user"
|
|
40
|
+
redirect_to(admin_user_path(@user))
|
|
41
|
+
else
|
|
42
|
+
render :action => "new"
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def edit
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def update
|
|
50
|
+
if @user.update_attributes(params[:user])
|
|
51
|
+
flash[:success] = 'User Updated'
|
|
52
|
+
redirect_to(admin_user_path(@user))
|
|
53
|
+
else
|
|
54
|
+
render :action => "edit"
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def destroy
|
|
59
|
+
@user.destroy
|
|
60
|
+
flash[:success] = 'User Deleted'
|
|
61
|
+
redirect_to(admin_users_path)
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
end
|