parlement 0.14 → 0.17

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 (205) hide show
  1. data/CHANGES +41 -1
  2. data/MEMORY +66 -5
  3. data/README +10 -5
  4. data/Rakefile +15 -23
  5. data/app/controllers/account_controller.rb +48 -43
  6. data/app/controllers/{application.rb → application_controller.rb} +15 -12
  7. data/app/controllers/elt_controller.rb +77 -32
  8. data/app/controllers/subscriber_controller.rb +11 -10
  9. data/app/helpers/application_helper.rb +14 -1
  10. data/app/helpers/elt_helper.rb +9 -7
  11. data/app/models/elt.rb +25 -24
  12. data/app/models/mail.rb +44 -47
  13. data/app/models/person_notify.rb +2 -2
  14. data/app/models/user.rb +128 -2
  15. data/app/models/user_notify.rb +15 -15
  16. data/app/views/account/_login.rhtml +39 -39
  17. data/app/views/account/_show.rhtml +22 -30
  18. data/app/views/account/signup.rhtml +2 -2
  19. data/app/views/elt/_choice.rhtml +6 -6
  20. data/app/views/elt/_elt.rhtml +27 -32
  21. data/app/views/elt/choices.rhtml +16 -18
  22. data/app/views/elt/list/_byDate.rhtml +14 -14
  23. data/app/views/elt/list/_byVote.rhtml +15 -15
  24. data/app/views/elt/list/_children.rhtml +48 -40
  25. data/app/views/elt/list/_subscribers.rhtml +1 -1
  26. data/app/views/elt/new.rhtml +22 -21
  27. data/app/views/elt/rss.rxml +4 -11
  28. data/app/views/elt/show.rhtml +65 -61
  29. data/app/views/elt/vote_rss.rxml +4 -11
  30. data/app/views/layouts/top.rhtml +39 -50
  31. data/app/views/person/_listElts.rhtml +1 -1
  32. data/app/views/person/show.rhtml +1 -1
  33. data/{vendor/plugins/login_engine/app → app}/views/user_notify/change_password.rhtml +0 -0
  34. data/{vendor/plugins/login_engine/app → app}/views/user_notify/delete.rhtml +0 -0
  35. data/{vendor/plugins/login_engine/app → app}/views/user_notify/forgot_password.rhtml +0 -0
  36. data/{vendor/plugins/login_engine/app → app}/views/user_notify/pending_delete.rhtml +0 -0
  37. data/{vendor/plugins/login_engine/app → app}/views/user_notify/signup.rhtml +0 -0
  38. data/config/boot.rb +97 -32
  39. data/config/environment.rb +37 -35
  40. data/config/environments/development.rb +2 -3
  41. data/config/environments/production.rb +3 -0
  42. data/config/initializers/string_ruby_1.8.rb +10 -0
  43. data/config/routes.rb +17 -22
  44. data/db/schema.rb +102 -74
  45. data/lib/tasks/rspec.rake +167 -0
  46. data/public/404.html +25 -7
  47. data/public/500.html +26 -7
  48. data/public/dispatch.cgi +0 -0
  49. data/public/dispatch.fcgi +0 -0
  50. data/public/dispatch.rb +0 -0
  51. data/public/images/live_tree_branch_collapsed_icon.gif +0 -0
  52. data/public/images/live_tree_branch_expanded_icon.gif +0 -0
  53. data/public/images/live_tree_leaf_icon.gif +0 -0
  54. data/public/javascripts/application.js +258 -0
  55. data/public/javascripts/controls.js +544 -414
  56. data/public/javascripts/dragdrop.js +229 -198
  57. data/public/javascripts/effects.js +499 -459
  58. data/public/javascripts/prototype.js +2926 -1121
  59. data/public/javascripts/shadedborder.js +68 -50
  60. data/public/stylesheets/default.css +34 -34
  61. data/public/stylesheets/live_tree.css +0 -0
  62. data/public/stylesheets/scaffold.css +6 -6
  63. data/script/about +0 -0
  64. data/script/autospec +6 -0
  65. data/script/benchmarker +0 -0
  66. data/script/breakpointer +0 -0
  67. data/script/console +0 -0
  68. data/script/dbconsole +3 -0
  69. data/script/destroy +0 -0
  70. data/script/generate +0 -0
  71. data/script/plugin +0 -0
  72. data/script/profiler +0 -0
  73. data/script/runner +0 -0
  74. data/script/server +0 -0
  75. data/script/spec +10 -0
  76. data/script/spec_server +9 -0
  77. data/test/unit/attachment_test.rb +4 -4
  78. data/test/unit/choice_test.rb +1 -1
  79. data/test/unit/elt_test.rb +9 -9
  80. data/test/unit/mail_notify_test.rb +2 -2
  81. data/test/unit/mail_test.rb +18 -11
  82. data/test/unit/person_notify_test.rb +1 -1
  83. data/test/unit/person_test.rb +1 -1
  84. data/test/unit/subscriber_test.rb +1 -1
  85. data/test/unit/user_test.rb +81 -0
  86. data/test/unit/visit_test.rb +6 -6
  87. data/vendor/plugins/activerecord_foreign_key_extensions/init.rb +2 -0
  88. data/vendor/plugins/activerecord_foreign_key_extensions/lib/active_record_extensions.rb +182 -0
  89. data/vendor/plugins/activerecord_text_id_extensions/init.rb +2 -0
  90. data/vendor/plugins/activerecord_text_id_extensions/lib/active_record_extensions.rb +24 -0
  91. data/vendor/plugins/acts_as_nested_set/README +15 -0
  92. data/vendor/plugins/acts_as_nested_set/init.rb +1 -0
  93. data/vendor/plugins/acts_as_nested_set/lib/active_record/acts/nested_set.rb +210 -0
  94. data/vendor/plugins/acts_as_nested_set/test/nested_set_test.rb +269 -0
  95. data/vendor/plugins/acts_as_tree/README +26 -0
  96. data/vendor/plugins/acts_as_tree/Rakefile +22 -0
  97. data/vendor/plugins/acts_as_tree/init.rb +1 -0
  98. data/vendor/plugins/acts_as_tree/lib/active_record/acts/tree.rb +96 -0
  99. data/vendor/plugins/{output_compression/CHANGELOG → acts_as_tree/test/abstract_unit.rb} +0 -0
  100. data/vendor/plugins/acts_as_tree/test/acts_as_tree_test.rb +219 -0
  101. data/vendor/plugins/acts_as_tree/test/database.yml +0 -0
  102. data/vendor/plugins/acts_as_tree/test/fixtures/mixin.rb +0 -0
  103. data/vendor/plugins/acts_as_tree/test/fixtures/mixins.yml +0 -0
  104. data/vendor/plugins/acts_as_tree/test/schema.rb +0 -0
  105. data/vendor/plugins/classic_pagination/CHANGELOG +152 -0
  106. data/vendor/plugins/classic_pagination/README +18 -0
  107. data/vendor/plugins/{output_compression/rakefile → classic_pagination/Rakefile} +22 -22
  108. data/vendor/plugins/classic_pagination/init.rb +33 -0
  109. data/vendor/plugins/classic_pagination/install.rb +1 -0
  110. data/vendor/plugins/classic_pagination/lib/pagination.rb +405 -0
  111. data/vendor/plugins/classic_pagination/lib/pagination_helper.rb +135 -0
  112. data/vendor/plugins/classic_pagination/test/fixtures/companies.yml +24 -0
  113. data/vendor/plugins/classic_pagination/test/fixtures/company.rb +9 -0
  114. data/vendor/plugins/classic_pagination/test/fixtures/developer.rb +7 -0
  115. data/vendor/plugins/classic_pagination/test/fixtures/developers.yml +21 -0
  116. data/vendor/plugins/classic_pagination/test/fixtures/developers_projects.yml +13 -0
  117. data/vendor/plugins/classic_pagination/test/fixtures/project.rb +3 -0
  118. data/vendor/plugins/classic_pagination/test/fixtures/projects.yml +7 -0
  119. data/vendor/plugins/classic_pagination/test/fixtures/replies.yml +13 -0
  120. data/vendor/plugins/classic_pagination/test/fixtures/reply.rb +5 -0
  121. data/vendor/plugins/classic_pagination/test/fixtures/schema.sql +42 -0
  122. data/vendor/plugins/classic_pagination/test/fixtures/topic.rb +3 -0
  123. data/vendor/plugins/classic_pagination/test/fixtures/topics.yml +22 -0
  124. data/vendor/plugins/classic_pagination/test/helper.rb +117 -0
  125. data/vendor/plugins/classic_pagination/test/pagination_helper_test.rb +38 -0
  126. data/vendor/plugins/classic_pagination/test/pagination_test.rb +177 -0
  127. data/vendor/plugins/file_column/lib/file_column.rb +1 -1
  128. data/vendor/plugins/file_column/test/file_column_test.rb +0 -0
  129. metadata +151 -197
  130. data/app/helpers/live_tree.rb +0 -238
  131. data/app/views/elt/_form.rhtml +0 -31
  132. data/app/views/elt/show_tree.rhtml +0 -8
  133. data/config/environments/user_environment.rb +0 -1
  134. data/db/ROOT/Titemagli.txt +0 -3
  135. data/db/ROOT/titemagli.txt +0 -9
  136. data/public/javascripts/behaviour.js +0 -254
  137. data/public/javascripts/ie7-load.htc +0 -1
  138. data/public/javascripts/ie7.js +0 -6
  139. data/public/javascripts/live_tree.js +0 -749
  140. data/public/javascripts/mybehaviour.js +0 -225
  141. data/public/javascripts/scriptaculous.js +0 -47
  142. data/public/javascripts/slider.js +0 -283
  143. data/public/stylesheets/blue.css +0 -471
  144. data/vendor/plugins/engines/CHANGELOG +0 -241
  145. data/vendor/plugins/engines/MIT-LICENSE +0 -21
  146. data/vendor/plugins/engines/README +0 -64
  147. data/vendor/plugins/engines/Rakefile +0 -32
  148. data/vendor/plugins/engines/UPGRADING +0 -93
  149. data/vendor/plugins/engines/about.yml +0 -7
  150. data/vendor/plugins/engines/generators/plugin_migration/USAGE +0 -45
  151. data/vendor/plugins/engines/generators/plugin_migration/plugin_migration_generator.rb +0 -79
  152. data/vendor/plugins/engines/generators/plugin_migration/templates/plugin_migration.erb +0 -13
  153. data/vendor/plugins/engines/init.rb +0 -40
  154. data/vendor/plugins/engines/install.rb +0 -32
  155. data/vendor/plugins/engines/lib/engines.rb +0 -323
  156. data/vendor/plugins/engines/lib/engines/deprecated_config_support.rb +0 -135
  157. data/vendor/plugins/engines/lib/engines/plugin.rb +0 -214
  158. data/vendor/plugins/engines/lib/engines/plugin_list.rb +0 -31
  159. data/vendor/plugins/engines/lib/engines/plugin_migrator.rb +0 -60
  160. data/vendor/plugins/engines/lib/engines/rails_extensions.rb +0 -6
  161. data/vendor/plugins/engines/lib/engines/rails_extensions/active_record.rb +0 -19
  162. data/vendor/plugins/engines/lib/engines/rails_extensions/dependencies.rb +0 -143
  163. data/vendor/plugins/engines/lib/engines/rails_extensions/migrations.rb +0 -155
  164. data/vendor/plugins/engines/lib/engines/rails_extensions/public_asset_helpers.rb +0 -116
  165. data/vendor/plugins/engines/lib/engines/rails_extensions/rails.rb +0 -20
  166. data/vendor/plugins/engines/lib/engines/rails_extensions/rails_initializer.rb +0 -86
  167. data/vendor/plugins/engines/lib/engines/rails_extensions/routing.rb +0 -77
  168. data/vendor/plugins/engines/lib/engines/rails_extensions/templates.rb +0 -140
  169. data/vendor/plugins/engines/lib/engines/testing.rb +0 -87
  170. data/vendor/plugins/engines/tasks/engines.rake +0 -149
  171. data/vendor/plugins/login_engine/CHANGELOG +0 -22
  172. data/vendor/plugins/login_engine/README +0 -344
  173. data/vendor/plugins/login_engine/app/controllers/user_controller.rb +0 -262
  174. data/vendor/plugins/login_engine/app/helpers/user_helper.rb +0 -88
  175. data/vendor/plugins/login_engine/app/models/user.rb +0 -7
  176. data/vendor/plugins/login_engine/app/models/user_notify.rb +0 -75
  177. data/vendor/plugins/login_engine/app/views/user/_edit.rhtml +0 -11
  178. data/vendor/plugins/login_engine/app/views/user/_password.rhtml +0 -9
  179. data/vendor/plugins/login_engine/app/views/user/change_password.rhtml +0 -17
  180. data/vendor/plugins/login_engine/app/views/user/edit.rhtml +0 -23
  181. data/vendor/plugins/login_engine/app/views/user/forgot_password.rhtml +0 -18
  182. data/vendor/plugins/login_engine/app/views/user/home.rhtml +0 -7
  183. data/vendor/plugins/login_engine/app/views/user/login.rhtml +0 -17
  184. data/vendor/plugins/login_engine/app/views/user/logout.rhtml +0 -8
  185. data/vendor/plugins/login_engine/app/views/user/signup.rhtml +0 -17
  186. data/vendor/plugins/login_engine/db/migrate/001_initial_schema.rb +0 -25
  187. data/vendor/plugins/login_engine/init_engine.rb +0 -11
  188. data/vendor/plugins/login_engine/install.rb +0 -4
  189. data/vendor/plugins/login_engine/lib/login_engine.rb +0 -62
  190. data/vendor/plugins/login_engine/lib/login_engine/authenticated_system.rb +0 -113
  191. data/vendor/plugins/login_engine/lib/login_engine/authenticated_user.rb +0 -155
  192. data/vendor/plugins/login_engine/public/stylesheets/login_engine.css +0 -81
  193. data/vendor/plugins/login_engine/test/fixtures/users.yml +0 -41
  194. data/vendor/plugins/login_engine/test/functional/user_controller_test.rb +0 -536
  195. data/vendor/plugins/login_engine/test/mocks/mail.rb +0 -14
  196. data/vendor/plugins/login_engine/test/mocks/time.rb +0 -19
  197. data/vendor/plugins/login_engine/test/test_helper.rb +0 -11
  198. data/vendor/plugins/login_engine/test/unit/user_test.rb +0 -114
  199. data/vendor/plugins/output_compression/MIT-LICENSE +0 -20
  200. data/vendor/plugins/output_compression/README +0 -4
  201. data/vendor/plugins/output_compression/init.rb +0 -1
  202. data/vendor/plugins/output_compression/lib/output_compression.rb +0 -84
  203. data/vendor/plugins/output_compression/test/output_test.rb +0 -11
  204. data/vendor/plugins/output_compression/test/test_controller.rb +0 -3
  205. data/vendor/plugins/output_compression/test/test_helper.rb +0 -14
@@ -1,22 +0,0 @@
1
- = v1.0.2
2
- * Added version
3
- * Removed errant requires no longer needed (murray.steele@gmail.com, Ticket #156, Ticket #157, Ticket #158)
4
- # Removed documentation/rake tasks that refer the schema.rb (Ticket #155)
5
- # Verified cannot be assigned via URL parameters. If more security is required, users should override the signup action itself (Ticket #169)
6
- # Minor view/flash message cleanup
7
- # Authentication by token now respects primary key prefixes (Ticket #140)
8
-
9
- = v1.0.1
10
- * Added CHANGELOG
11
- * Changed wording for when password forgotten to 'reset', rather than 'retrieve'. (snowblink@gmail.com)
12
- * Fixed new location of engines testing extensions. (lazyatom@gmail.com)
13
- * Removed schema.db from Login Engine; migrations should be used instead. (snowblink@gmail.com)
14
- * Updated User Controller tests to parse the user_id and email out of the URL in the email body. (snowblink@gmail.com)
15
- * Ticket #89 (lazyatom@gmail.com) User creation halts the after_save callback chain.
16
- * Ticket #97 (dcorbin@machturtle.com) The forgotten_password view generates invalid HTML
17
- * Ticket #112 (segabor@gmail.com) Authentication system will break even on successful login
18
- * Added simple email validation to the User model. (snowblink@gmail.com)
19
- This should also take care of the unit test failures detailed in Ticket #114 (morris@wolfman.com)
20
- * Ticket #118 (augustz@augustz.com) SVN source for login_engine not found
21
- * Ticket #119 (Goynang) Unit tests for engines fail after default install
22
- * Ticket #126 (lazyatom@gmail.com) Add install.rb to login engine
@@ -1,344 +0,0 @@
1
- = Before we start
2
-
3
- This is a Rails Engine version of the Salted Login Generator, a most excellent login system which is sufficient for most simple cases. For the most part, this code has not been altered from its generator form, with the following notable exceptions
4
-
5
- * Localization has been removed.
6
- * The 'welcome' page has been changed to the 'home' page
7
- * A few new functions have been thrown in
8
- * It's... uh.... a Rails Engine now ;-)
9
-
10
- However, what I'm trying to say is that 99.9999% of the credit for this should go to Joe Hosteny, Tobias Luetke (xal) and the folks that worked on the original Salted Login generator code. I've just wrapped it into something runnable with the Rails Engine system.
11
-
12
- Please also bear in mind that this is a work in progress, and things like testing are wildly up in the air... but they will fall into place very soon. And now, on with the show.
13
-
14
-
15
- = Installation
16
-
17
- Installing the Login Engine is fairly simple.
18
-
19
- Your options are:
20
- 1. Install as a rails plugin:
21
- $ script/plugin install login_engine
22
- 2. Use svn:externals
23
- $ svn propedit svn:externals vendor/plugins
24
-
25
- You can choose to use the latest stable release:
26
- login_engine http://svn.rails-engines.org/plugins/login_engine
27
-
28
- Or a tagged release (recommended for releases of your code):
29
- login_engine http://svn.rails-engines.org/logine_engine/tags/<TAGGED_RELEASE>
30
-
31
- There are a few configuration steps that you'll need to take to get everything running smoothly. Listed below are the changes to your application you will need to make.
32
-
33
- === Setup your Rails application
34
-
35
- Edit your <tt>database.yml</tt>, most importantly! You might also want to move <tt>public/index.html</tt> out of the way, and set up some default routes in <tt>config/routes.rb</tt>.
36
-
37
- === Add configuration and start engine
38
-
39
- Add the following to the bottom of environment.rb:
40
-
41
- module LoginEngine
42
- config :salt, "your-salt-here"
43
- end
44
-
45
- Engines.start :login
46
-
47
- You'll probably want to change the Salt value to something unique. You can also override any of the configuration values defined at the top of lib/user_system.rb in a similar way. Note that you don't need to start the engine with <tt>Engines.start :login_engine</tt> - instead, <tt>:login</tt> (or any name) is sufficient if the engine is a directory named <some-name>_engine.
48
-
49
-
50
- === Add the filters
51
-
52
- Next, edit your <tt>app/controllers/application.rb</tt> file. The beginning of your <tt>ApplicationController</tt> should look something like this:
53
-
54
- require 'login_engine'
55
-
56
- class ApplicationController < ActionController::Base
57
- include LoginEngine
58
- helper :user
59
- model :user
60
-
61
- before_filter :login_required
62
-
63
- If you don't want ALL actions to require a login, you need to read further below to learn how to restrict only certain actions.
64
-
65
- Add the following to your ApplicationHelper:
66
-
67
- module ApplicationHelper
68
- include LoginEngine
69
- end
70
-
71
- This ensures that the methods to work with users in your views are available
72
-
73
- === Set up ActionMailer
74
-
75
- If you want to disable email functions within the Login Engine, simple set the :use_email_notification config flag to false in your environment.rb file:
76
-
77
- module LoginEngine
78
-
79
- # ... other options...
80
- config :use_email_notification, false
81
-
82
- end
83
-
84
- You should note that retrieving forgotten passwords automatically isn't possible when the email functions are disabled. Instead, the user is presented with a message instructing them to contact the system administrator
85
-
86
- If you wish you use email notifications and account creation verification, you must properly configure ActionMailer for your mail settings. For example, you could add the following in config/environments/development.rb (for a .Mac account, and with your own username and password, obviously):
87
-
88
- ActionMailer::Base.server_settings = {
89
- :address => "smtp.mac.com",
90
- :port => 25,
91
- :domain => "smtp.mac.com",
92
- :user_name => "<your user name here>",
93
- :password => "<your password here>",
94
- :authentication => :login
95
- }
96
-
97
- You'll need to configure it properly so that email can be sent. One of the easiest ways to test your configuration is to temporarily reraise exceptions from the signup method (so that you get the actual mailer exception string). In the rescue statement, put a single "raise" statement in. Once you've debugged any setting problems, remove that statement to get the proper flash error handling back.
98
-
99
-
100
- === Create the DB schema
101
-
102
- After you have done the modifications the the ApplicationController and its helper, you can import the user model into the database. Migration information in login_engine/db/migrate/.
103
-
104
- You *MUST* check that these files aren't going to interfere with anything in your application.
105
-
106
- You can change the table name used by adding
107
-
108
- module LoginEngine
109
-
110
- # ... other options...
111
- config :user_table, "your_table_name"
112
-
113
- end
114
-
115
- ...to the LoginEngine configuration in <tt>environment.rb</tt>. Then run from the root of your project:
116
-
117
- rake db:migrate:engines ENGINE=login
118
-
119
- to import the schema into your database.
120
-
121
-
122
- == Include stylesheets
123
-
124
- If you want the default stylesheet, add the following line to your layout:
125
-
126
- <%= engine_stylesheet 'login_engine' %>
127
-
128
- ... somewhere in the <head> section of your HTML layout file.
129
-
130
- == Integrate flash messages into your layout
131
-
132
- LoginEngine does not display any flash messages in the views it contains, and thus you must display them yourself. This allows you to integrate any flash messages into your existing layout. LoginEngine adheres to the emerging flash usage standard, namely:
133
-
134
- * :warning - warning (failure) messages
135
- * :notice - success messages
136
- * :message - neutral (reminder, informational) messages
137
-
138
- This gives you the flexibility to theme the different message classes separately. In your layout you should check for and display flash[:warning], flash[:notice] and flash[:message]. For example:
139
-
140
- <% for name in [:notice, :warning, :message] %>
141
- <% if flash[name] %>
142
- <%= "<div id=\"#{name}\">#{flash[name]}</div>" %>
143
- <% end %>
144
- <% end %>
145
-
146
- Alternately, you could look at using the flash helper plugin (available from https://opensvn.csie.org/traccgi/flash_helper_plugin/trac.cgi/), which supports the same naming convention.
147
-
148
-
149
- = How to use the Login Engine
150
-
151
- Now you can go around and happily add "before_filter :login_required" to the controllers which you would like to protect.
152
-
153
- After integrating the login system with your rails application navigate to your new controller's signup method. There you can create a new account. After you are done you should have a look at your DB. Your freshly created user will be there but the password will be a sha1 hashed 40 digit mess. I find this should be the minimum of security which every page offering login & password should give its customers. Now you can move to one of those controllers which you protected with the before_filter :login_required snippet. You will automatically be re-directed to your freshly created login controller and you are asked for a password. After entering valid account data you will be taken back to the controller which you requested earlier. Simple huh?
154
-
155
- === Protection using <tt>before_filter</tt>
156
-
157
- Adding the line <tt>before_filter :login_required</tt> to your <tt>app/controllers/application.rb</tt> file will protect *all* of your applications methods, in every controller. If you only want to control access to specific controllers, remove this line from <tt>application.rb</tt> and add it to the controllers that you want to secure.
158
-
159
- Within individual controllers you can restrict which methods the filter runs on in the usual way:
160
-
161
- before_filter :login_required, :only => [:myaccount, :changepassword]
162
- before_filter :login_required, :except => [:index]
163
-
164
- === Protection using <tt>protect?()</tt>
165
-
166
- Alternatively, you can leave the <tt>before_filter</tt> in the global <tt>application.rb</tt> file, and control which actions are restricted in individual controllers by defining a <tt>protect?()</tt> method in that controller.
167
-
168
- For instance, in the <tt>UserController</tt> we want to allow everyone access to the 'login', 'signup' and 'forgot_password' methods (otherwise noone would be able to access our site!). So a <tt>protect?()</tt> method is defined in <tt>user_controller.rb</tt> as follows:
169
-
170
- def protect?(action)
171
- if ['login', 'signup', 'forgot_password'].include?(action)
172
- return false
173
- else
174
- return true
175
- end
176
- end
177
-
178
- Of course, you can override this Engine behaviour in your application - see below.
179
-
180
- == Configuration
181
-
182
- The following configuration variables are set in lib/login_engine.rb. If you wish to override them, you should set them BEFORE calling Engines.start (it is possible to set them after, but it's simpler to just do it before. Please refer to the Engine documentation for the #config method for more information).
183
-
184
- For example, the following might appear at the bottom of /config/environment.rb:
185
-
186
- module LoginEngine
187
- config :salt, 'my salt'
188
- config :app_name, 'My Great App'
189
- config :app_url, 'http://www.wow-great-domain.com'
190
- end
191
-
192
- Engines.start
193
-
194
- === Configuration Options
195
-
196
- +email_from+:: The email from which registration/administration emails will appear to
197
- come from. Defaults to 'webmaster@your.company'.
198
- +admin_email+:: The email address users are prompted to contact if passwords cannot
199
- be emailed. Defaults to 'webmaster@your.company'.
200
- +app_url+:: The URL of the site sent to users for signup/forgotten passwords, etc.
201
- Defaults to 'http://localhost:3000/'.
202
- +app_name+:: The application title used in emails. Defaults to 'TestApp'.
203
- +mail_charset+:: The charset used in emails. Defaults to 'utf-8'.
204
- +security_token_life_hours+:: The life span of security tokens, in hours. If a security
205
- token is older than this when it is used to try and authenticate
206
- a user, it will be discarded. In other words, the amount of time
207
- new users have between signing up and clicking the link they
208
- are sent. Defaults to 24 hours.
209
- +two_column_input+:: If true, forms created with the UserHelper#form_input method will
210
- use a two-column table. Defaults to true.
211
- +changeable_fields+:: An array of fields within the user model which the user
212
- is allowed to edit. The Salted Hash Login generator documentation
213
- states that you should NOT include the email field in this
214
- array, although I am not sure why. Defaults to +[ 'firstname', 'lastname' ]+.
215
- +delayed_delete+:: Set to true to allow delayed deletes (i.e., delete of record
216
- doesn't happen immediately after user selects delete account,
217
- but rather after some expiration of time to allow this action
218
- to be reverted). Defaults to false.
219
- +delayed_delete_days+:: The time delay used for the 'delayed_delete' feature. Defaults to
220
- 7 days.
221
- +user_table+:: The table to store User objects in. Defaults to "users" (or "user" if
222
- ActiveRecord pluralization is disabled).
223
- +use_email_notification+:: If false, no emails will be sent to the user. As a consequence,
224
- users who signup are immediately verified, and they cannot request
225
- forgotten passwords. Defaults to true.
226
- +confirm_account+:: An overriding flag to control whether or not user accounts must be
227
- verified by email. This overrides the +user_email_notification+ flag.
228
- Defaults to true.
229
-
230
- == Overriding controllers and views
231
-
232
- The standard home page is almost certainly not what you want to present to your users. Because this login system is a Rails Engine, overriding the default behaviour couldn't be simpler. To change the RHTML template shown for the <tt>home</tt> action, simple create a new file in <tt>RAILS_ROOT/app/views/user/home.rhtml</tt> (you'll probably need to create the directory <tt>user</tt> at the same time). This new view file will be used instead of the one provided in the Login Engine. Easy!
233
-
234
-
235
- == Tips & Tricks
236
-
237
- How do I...
238
-
239
- ... access the user who is currently logged in
240
-
241
- A: You can get the user object from the session using session[:user]
242
- Example:
243
- Welcome <%= session[:user].name %>
244
-
245
- You can also use the 'current_user' method provided by UserHelper:
246
- Example:
247
- Welcome <%= current_user.name %>
248
-
249
-
250
- ... restrict access to only a few methods?
251
-
252
- A: Use before_filters build in scoping.
253
- Example:
254
- before_filter :login_required, :only => [:myaccount, :changepassword]
255
- before_filter :login_required, :except => [:index]
256
-
257
- ... check if a user is logged-in in my views?
258
-
259
- A: session[:user] will tell you. Here is an example helper which you can use to make this more pretty:
260
- Example:
261
- def user?
262
- !session[:user].nil?
263
- end
264
-
265
- ... return a user to the page they came from before logging in?
266
-
267
- A: The user will be send back to the last url which called the method "store_location"
268
- Example:
269
- User was at /articles/show/1, wants to log in.
270
- in articles_controller.rb, add store_location to the show function and
271
- send the user to the login form.
272
- After he logs in he will be send back to /articles/show/1
273
-
274
- You can find more help at http://wiki.rubyonrails.com/rails/show/SaltedLoginGenerator
275
-
276
- == Troubleshooting
277
-
278
- One of the more common problems people have seen is that after verifying an account by following the emailed URL, they are unable to login via the normal login method since the verified field is not properly set in the user model's row in the DB.
279
-
280
- The most common cause of this problem is that the DB and session get out of sync. In particular, it always happens for me after recreating the DB if I have run the server previously. To fix the problem, remove the /tmp/ruby* session files (from wherever they are for your installation) while the server is stopped, and then restart. This usually is the cause of the problem.
281
-
282
- = Notes
283
-
284
- === Database Schemas & Testing
285
-
286
- Currently, since not all databases appear to support structure cloning, the tests will load the entire schema into your test database, potentially blowing away any other test structures you might have. If this presents an issue for your application, comment out the line in test/test_helper.rb
287
-
288
-
289
- = Database Schema Details
290
-
291
- You need a database table corresponding to the User model. This is provided as a Rails Schema file, but the schema is presented below for information. Note the table type for MySQL. Whatever DB you use, it must support transactions. If it does not, the functional tests will not work properly, nor will the application in the face of failures during certain DB creates and updates.
292
-
293
- mysql syntax:
294
- CREATE TABLE users (
295
- id INTEGER UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
296
- login VARCHAR(80) NOT NULL,
297
- salted_password VARCHAR(40) NOT NULL,
298
- email VARCHAR(60) NOT NULL,
299
- firstname VARCHAR(40),
300
- lastname VARCHAR(40),
301
- salt CHAR(40) NOT NULL,
302
- verified INT default 0,
303
- role VARCHAR(40) default NULL,
304
- security_token CHAR(40) default NULL,
305
- token_expiry DATETIME default NULL,
306
- deleted INT default 0,
307
- delete_after DATETIME default NULL
308
- ) TYPE=InnoDB DEFAULT CHARSET=utf8;
309
-
310
- postgres:
311
- CREATE TABLE "users" (
312
- id SERIAL PRIMARY KEY
313
- login VARCHAR(80) NOT NULL,
314
- salted_password VARCHAR(40) NOT NULL,
315
- email VARCHAR(60) NOT NULL,
316
- firstname VARCHAR(40),
317
- lastname VARCHAR(40),
318
- salt CHAR(40) NOT NULL,
319
- verified INT default 0,
320
- role VARCHAR(40) default NULL,
321
- security_token CHAR(40) default NULL,
322
- token_expiry TIMESTAMP default NULL,
323
- deleted INT default 0,
324
- delete_after TIMESTAMP default NULL
325
- ) WITH OIDS;
326
-
327
- sqlite:
328
- CREATE TABLE 'users' (
329
- id INTEGER PRIMARY KEY,
330
- login VARCHAR(80) NOT NULL,
331
- salted_password VARCHAR(40) NOT NULL,
332
- email VARCHAR(60) NOT NULL,
333
- firstname VARCHAR(40),
334
- lastname VARCHAR(40),
335
- salt CHAR(40) NOT NULL,
336
- verified INT default 0,
337
- role VARCHAR(40) default NULL,
338
- security_token CHAR(40) default NULL,
339
- token_expiry DATETIME default NULL,
340
- deleted INT default 0,
341
- delete_after DATETIME default NULL
342
- );
343
-
344
- Of course your user model can have any amount of extra fields. This is just a starting point.
@@ -1,262 +0,0 @@
1
- class UserController < ApplicationController
2
- # echarp
3
- #model :user
4
-
5
- # Override this function in your own application to define a custom home action.
6
- def home
7
- if user?
8
- @fullname = "#{current_user.firstname} #{current_user.lastname}"
9
- else
10
- @fullname = "Not logged in..."
11
- end # this is a bit of a hack since the home action is used to verify user
12
- # keys, where noone is logged in. We should probably create a unique
13
- # 'validate_key' action instead.
14
- end
15
-
16
- # The action used to log a user in. If the user was redirected to the login page
17
- # by the login_required method, they should be sent back to the page they were
18
- # trying to access. If not, they will be sent to "/user/home".
19
- def login
20
- return if generate_blank
21
- @user = User.new(params[:user])
22
- if session[:user] = User.authenticate(params[:user][:login], params[:user][:password])
23
- session[:user].logged_in_at = Time.now
24
- session[:user].save
25
- flash[:notice] = 'Login successful'
26
- redirect_to_stored_or_default :action => 'home'
27
- else
28
- @login = params[:user][:login]
29
- flash.now[:warning] = 'Login unsuccessful'
30
- end
31
- end
32
-
33
- # Register as a new user. Upon successful registration, the user will be sent to
34
- # "/user/login" to enter their details.
35
- def signup
36
- return if generate_blank
37
- params[:user].delete('form')
38
- params[:user].delete('verified') # you CANNOT pass this as part of the request
39
- @user = User.new(params[:user])
40
- begin
41
- User.transaction(@user) do
42
- @user.new_password = true
43
- unless LoginEngine.config(:use_email_notification) and LoginEngine.config(:confirm_account)
44
- @user.verified = 1
45
- end
46
- if @user.save
47
- key = @user.generate_security_token
48
- url = url_for(:action => 'home', :user_id => @user.id, :key => key)
49
- flash[:notice] = 'Signup successful!'
50
- if LoginEngine.config(:use_email_notification) and LoginEngine.config(:confirm_account)
51
- UserNotify.deliver_signup(@user, params[:user][:password], url)
52
- flash[:notice] << ' Please check your registered email account to verify your account registration and continue with the login.'
53
- else
54
- flash[:notice] << ' Please log in.'
55
- end
56
- redirect_to :action => 'login'
57
- end
58
- end
59
- rescue Exception => e
60
- flash.now[:notice] = nil
61
- flash.now[:warning] = 'Error creating account: confirmation email not sent'
62
- logger.error "Unable to send confirmation E-Mail:"
63
- logger.error e
64
- end
65
- end
66
-
67
- def logout
68
- session[:user] = nil
69
- redirect_to :action => 'login'
70
- end
71
-
72
- def change_password
73
- return if generate_filled_in
74
- if do_change_password_for(@user)
75
- # since sometimes we're changing the password from within another action/template...
76
- #redirect_to :action => params[:back_to] if params[:back_to]
77
- redirect_back_or_default :action => 'change_password'
78
- end
79
- end
80
-
81
- protected
82
- def do_change_password_for(user)
83
- begin
84
- User.transaction(user) do
85
- user.change_password(params[:user][:password], params[:user][:password_confirmation])
86
- if user.save
87
- if LoginEngine.config(:use_email_notification)
88
- UserNotify.deliver_change_password(user, params[:user][:password])
89
- flash[:notice] = "Updated password emailed to #{@user.email}"
90
- else
91
- flash[:notice] = "Password updated."
92
- end
93
- return true
94
- else
95
- flash[:warning] = 'There was a problem saving the password. Please retry.'
96
- return false
97
- end
98
- end
99
- rescue
100
- flash[:warning] = 'Password could not be changed at this time. Please retry.'
101
- end
102
- end
103
-
104
- public
105
-
106
-
107
- def forgot_password
108
- # Always redirect if logged in
109
- if user?
110
- flash[:message] = 'You are currently logged in. You may change your password now.'
111
- redirect_to :action => 'change_password'
112
- return
113
- end
114
-
115
- # Email disabled... we are unable to provide the password
116
- if !LoginEngine.config(:use_email_notification)
117
- flash[:message] = "Please contact the system admin at #{LoginEngine.config(:admin_email)} to reset your password."
118
- redirect_back_or_default :action => 'login'
119
- return
120
- end
121
-
122
- # Render on :get and render
123
- return if generate_blank
124
-
125
- # Handle the :post
126
- if params[:user][:email].empty?
127
- flash.now[:warning] = 'Please enter a valid email address.'
128
- elsif (user = User.find_by_email(params[:user][:email])).nil?
129
- flash.now[:warning] = "We could not find a user with the email address #{params[:user][:email]}"
130
- else
131
- begin
132
- User.transaction(user) do
133
- key = user.generate_security_token
134
- url = url_for(:action => 'change_password', :user_id => user.id, :key => key)
135
- UserNotify.deliver_forgot_password(user, url)
136
- flash[:notice] = "Instructions on resetting your password have been emailed to #{params[:user][:email]}"
137
- end
138
- unless user?
139
- redirect_to :action => 'login'
140
- return
141
- end
142
- redirect_back_or_default :action => 'home'
143
- rescue
144
- flash.now[:warning] = "Your password could not be emailed to #{params[:user][:email]}"
145
- end
146
- end
147
- end
148
-
149
- def edit
150
- return if generate_filled_in
151
- do_edit_user(@user)
152
- end
153
-
154
- protected
155
- def do_edit_user(user)
156
- begin
157
- User.transaction(user) do
158
- user.attributes = params[:user].delete_if { |k,v| not LoginEngine.config(:changeable_fields).include?(k) }
159
- if user.save
160
- flash[:notice] = "User details updated"
161
- else
162
- flash[:warning] = "Details could not be updated! Please retry."
163
- end
164
- end
165
- rescue
166
- flash.now[:warning] = "Error updating user details. Please try again later."
167
- end
168
- end
169
-
170
- public
171
-
172
- def delete
173
- get_user_to_act_on
174
- if do_delete_user(@user)
175
- logout
176
- else
177
- redirect_back_or_default :action => 'home'
178
- end
179
- end
180
-
181
- protected
182
- def do_delete_user(user)
183
- begin
184
- if LoginEngine.config(:delayed_delete)
185
- User.transaction(user) do
186
- key = user.set_delete_after
187
- if LoginEngine.config(:use_email_notification)
188
- url = url_for(:action => 'restore_deleted', :user_id => user.id, :key => key)
189
- UserNotify.deliver_pending_delete(user, url)
190
- end
191
- end
192
- else
193
- destroy(@user)
194
- end
195
- return true
196
- rescue
197
- if LoginEngine.config(:use_email_notification)
198
- flash.now[:warning] = 'The delete instructions were not sent. Please try again later.'
199
- else
200
- flash.now[:notice] = 'The account has been scheduled for deletion. It will be removed in #{LoginEngine.config(:delayed_delete_days)} days.'
201
- end
202
- return false
203
- end
204
- end
205
-
206
- public
207
-
208
- def restore_deleted
209
- get_user_to_act_on
210
- @user.deleted = 0
211
- if not @user.save
212
- flash.now[:warning] = "The account for #{@user['login']} was not restored. Please try the link again."
213
- redirect_to :action => 'login'
214
- else
215
- redirect_to :action => 'home'
216
- end
217
- end
218
-
219
- protected
220
-
221
- def destroy(user)
222
- UserNotify.deliver_delete(user) if LoginEngine.config(:use_email_notification)
223
- flash[:notice] = "The account for #{user['login']} was successfully deleted."
224
- user.destroy()
225
- end
226
-
227
- def protect?(action)
228
- if ['login', 'signup', 'forgot_password'].include?(action)
229
- return false
230
- else
231
- return true
232
- end
233
- end
234
-
235
- # Generate a template user for certain actions on get
236
- def generate_blank
237
- case request.method
238
- when :get
239
- @user = User.new
240
- render
241
- return true
242
- end
243
- return false
244
- end
245
-
246
- # Generate a template user for certain actions on get
247
- def generate_filled_in
248
- get_user_to_act_on
249
- case request.method
250
- when :get
251
- render
252
- return true
253
- end
254
- return false
255
- end
256
-
257
- # returns the user object this method should act upon; only really
258
- # exists for other engines operating on top of this one to redefine...
259
- def get_user_to_act_on
260
- @user = session[:user]
261
- end
262
- end