adva 0.1.4 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (251) hide show
  1. checksums.yaml +4 -4
  2. data/adva.gemspec +3 -0
  3. data/app/assets/config/manifest.js +6 -0
  4. data/app/assets/javascripts/adva_cms/ckeditor.js.erb +12 -0
  5. data/app/assets/javascripts/adva_cms/concat_main_menus.js +13 -0
  6. data/app/assets/javascripts/adva_cms/jquery.table_tree.js +704 -0
  7. data/app/assets/javascripts/adva_cms.js +7 -0
  8. data/app/assets/javascripts/ckeditor/config.js.erb +94 -0
  9. data/app/assets/stylesheets/adva_cms/admin/common.scss +15 -1
  10. data/app/assets/stylesheets/adva_cms/admin/projection.scss +2 -5
  11. data/app/assets/stylesheets/adva_cms/admin/sidebar.scss +30 -9
  12. data/app/assets/stylesheets/adva_cms/admin.scss +1 -1
  13. data/app/controllers/admin/base_controller.rb +10 -24
  14. data/app/controllers/admin/page/articles_controller.rb +8 -27
  15. data/app/controllers/admin/page/categories_controller.rb +6 -9
  16. data/app/controllers/admin/page/links_controller.rb +6 -9
  17. data/app/controllers/admin/sections_controller.rb +7 -9
  18. data/app/controllers/admin/sites_controller.rb +9 -12
  19. data/app/controllers/admin/users_controller.rb +6 -9
  20. data/app/controllers/articles_controller.rb +30 -52
  21. data/app/controllers/base_controller.rb +8 -8
  22. data/app/controllers/password_controller.rb +3 -5
  23. data/app/controllers/session_controller.rb +3 -5
  24. data/app/helpers/activities_helper.rb +9 -20
  25. data/app/helpers/admin/base_helper.rb +4 -22
  26. data/app/helpers/base_helper.rb +1 -1
  27. data/app/helpers/content_helper.rb +7 -5
  28. data/app/helpers/resource_helper.rb +4 -5
  29. data/app/helpers/users_helper.rb +1 -1
  30. data/app/models/activity.rb +3 -0
  31. data/app/models/article.rb +0 -11
  32. data/app/models/category.rb +3 -3
  33. data/app/models/content.rb +10 -39
  34. data/app/models/link.rb +0 -1
  35. data/app/models/password_mailer.rb +6 -9
  36. data/app/models/section.rb +6 -7
  37. data/app/models/site.rb +0 -2
  38. data/app/models/user.rb +1 -2
  39. data/app/views/activity_notifier/new_content_notification.html.erb +5 -5
  40. data/app/views/admin/activities/_activities.html.erb +4 -4
  41. data/app/views/admin/activities/_comment.html.erb +21 -21
  42. data/app/views/admin/activities/_content.html.erb +4 -3
  43. data/app/views/admin/activities/_topic.html.erb +5 -5
  44. data/app/views/admin/install/confirmation.html.erb +3 -3
  45. data/app/views/admin/install/index.html.erb +14 -14
  46. data/app/views/admin/page/articles/_form.html.erb +28 -25
  47. data/app/views/admin/page/articles/_options.html.erb +3 -4
  48. data/app/views/admin/page/articles/edit.html.erb +3 -3
  49. data/app/views/admin/page/articles/new.html.erb +4 -4
  50. data/app/views/admin/page/categories/edit.html.erb +9 -9
  51. data/app/views/admin/page/categories/index.html.erb +16 -16
  52. data/app/views/admin/page/categories/new.html.erb +5 -3
  53. data/app/views/admin/page/contents/index.html.erb +3 -18
  54. data/app/views/admin/page/links/_form.html.erb +17 -17
  55. data/app/views/admin/page/links/_options.html.erb +16 -19
  56. data/app/views/admin/page/links/edit.html.erb +3 -3
  57. data/app/views/admin/page/links/new.html.erb +3 -3
  58. data/app/views/admin/sections/_form.html.haml +5 -5
  59. data/app/views/admin/sections/edit.html.haml +2 -2
  60. data/app/views/admin/sections/index.html.erb +18 -18
  61. data/app/views/admin/sections/new.html.erb +15 -13
  62. data/app/views/admin/sections/settings/_page.html.haml +4 -6
  63. data/app/views/admin/shared/_header.html.erb +5 -4
  64. data/app/views/admin/shared/_section_tree.html.erb +2 -2
  65. data/app/views/admin/sites/_email_notifications.html.erb +6 -7
  66. data/app/views/admin/sites/_form.html.erb +7 -7
  67. data/app/views/admin/sites/_recent_users.html.erb +4 -2
  68. data/app/views/admin/sites/_unapproved_comments.html.erb +1 -1
  69. data/app/views/admin/sites/index.html.erb +1 -1
  70. data/app/views/admin/sites/new.html.erb +2 -2
  71. data/app/views/admin/sites/show.html.erb +7 -8
  72. data/app/views/admin/users/edit.html.erb +1 -1
  73. data/app/views/admin/users/index.html.erb +10 -10
  74. data/app/views/admin/users/new.html.erb +1 -1
  75. data/app/views/admin/users/show.html.erb +7 -7
  76. data/app/views/layouts/admin.html.haml +3 -5
  77. data/app/views/layouts/login.html.erb +1 -1
  78. data/app/views/password/edit.html.erb +12 -5
  79. data/app/views/password/new.html.erb +7 -7
  80. data/app/views/password_mailer/reset_password_email.html.erb +21 -1
  81. data/app/views/password_mailer/updated_password_email.html.erb +3 -1
  82. data/app/views/session/new.html.erb +9 -9
  83. data/app/views/shared/_flash.html.erb +2 -2
  84. data/app/views/shared/_sidebar.html.erb +2 -2
  85. data/config/initializers/ckeditor.rb +61 -0
  86. data/config/initializers/time_format.rb +2 -0
  87. data/lib/adva/authenticate_user.rb +193 -0
  88. data/lib/{active_record → adva}/belongs_to_author.rb +4 -4
  89. data/lib/adva/event.rb +34 -0
  90. data/lib/adva/extensible_forms.rb +285 -0
  91. data/lib/{has_options.rb → adva/has_options.rb} +5 -7
  92. data/lib/adva/has_permalink.rb +36 -0
  93. data/lib/adva/version.rb +1 -1
  94. data/lib/adva.rb +10 -36
  95. data/lib/rails_ext/action_controller/event_helper.rb +1 -1
  96. data/lib/rails_ext.rb +0 -9
  97. data/vendor/gems/cacheable_flash/.gitignore +8 -0
  98. data/vendor/gems/cacheable_flash/Gemfile +8 -0
  99. data/vendor/gems/cacheable_flash/README.md +35 -0
  100. data/vendor/gems/cacheable_flash/Rakefile +4 -0
  101. data/vendor/gems/cacheable_flash/bin/console +15 -0
  102. data/vendor/gems/cacheable_flash/bin/setup +8 -0
  103. data/vendor/gems/cacheable_flash/cacheable_flash.gemspec +38 -0
  104. data/vendor/gems/cacheable_flash/lib/cacheable_flash/controller.rb +29 -0
  105. data/vendor/gems/cacheable_flash/lib/cacheable_flash/javascript.js +19 -0
  106. data/vendor/gems/cacheable_flash/lib/cacheable_flash/middleware.rb +30 -0
  107. data/vendor/gems/cacheable_flash/lib/cacheable_flash/version.rb +5 -0
  108. data/vendor/gems/cacheable_flash/lib/cacheable_flash.rb +12 -0
  109. data/vendor/gems/simple_taggable/lib/tag_list.rb +1 -1
  110. data/vendor/gems/tags/lib/menu.rb +1 -1
  111. data/vendor/gems/tags/lib/tags/tag.rb +1 -1
  112. metadata +71 -144
  113. data/app/assets/javascripts/adva_cms/admin/jquery.admin.js +0 -23
  114. data/app/assets/javascripts/adva_cms/admin/jquery.article.js +0 -22
  115. data/app/assets/javascripts/adva_cms/admin/jquery.cached_pages.js +0 -14
  116. data/app/assets/javascripts/adva_cms/admin/jquery.table_tree.js +0 -7
  117. data/app/assets/javascripts/adva_cms/application.js +0 -13
  118. data/app/assets/javascripts/adva_cms/base.js +0 -4
  119. data/app/assets/javascripts/adva_cms/cookie.js +0 -49
  120. data/app/assets/javascripts/adva_cms/jquery/jquery-lowpro.js +0 -224
  121. data/app/assets/javascripts/adva_cms/jquery/jquery.qtip.js +0 -2085
  122. data/app/assets/javascripts/adva_cms/jquery/jquery.table_tree.js +0 -307
  123. data/app/assets/javascripts/adva_cms/jquery/jquery.tablednd_0_5.js +0 -386
  124. data/app/assets/javascripts/adva_cms/jquery.common.js +0 -41
  125. data/app/assets/javascripts/adva_cms/jquery.dates.js +0 -51
  126. data/app/assets/javascripts/adva_cms/jquery.flash.js +0 -59
  127. data/app/assets/javascripts/adva_cms/jquery.roles.js +0 -25
  128. data/app/assets/javascripts/adva_cms/json.js +0 -139
  129. data/app/controllers/admin/base_account_controller.rb +0 -13
  130. data/app/controllers/admin/install_controller.rb +0 -61
  131. data/app/controllers/admin/plugins_controller.rb +0 -38
  132. data/app/helpers/meta_tags_helper.rb +0 -30
  133. data/app/models/account.rb +0 -7
  134. data/app/models/event.rb +0 -34
  135. data/app/views/admin/articles/_meta_tags.html.erb +0 -7
  136. data/app/views/admin/cached_pages/_filter.html.erb +0 -8
  137. data/app/views/admin/cached_pages/destroy.js.erb +0 -18
  138. data/app/views/admin/cached_pages/index.html.erb +0 -26
  139. data/app/views/admin/plugins/_form.html.erb +0 -11
  140. data/app/views/admin/plugins/index.html.erb +0 -16
  141. data/app/views/admin/plugins/show.html.erb +0 -43
  142. data/app/views/admin/shared/_language_select.html.erb +0 -6
  143. data/app/views/admin/shared/_section_summary.html.erb +0 -23
  144. data/app/views/admin/sites/_meta_tags.html.erb +0 -15
  145. data/app/views/layouts/default.html.erb +0 -38
  146. data/app/views/layouts/simple.html.erb +0 -22
  147. data/app/views/shared/_footer.html.erb +0 -4
  148. data/app/views/shared/messages/insufficient_permissions.html.erb +0 -4
  149. data/config/initializers/article.rb +0 -8
  150. data/config/initializers/has_options.rb +0 -2
  151. data/config/initializers/has_permalink.rb +0 -2
  152. data/config/initializers/site.rb +0 -8
  153. data/config/locales/en.yml +0 -1319
  154. data/lib/action_controller/authenticate_anonymous.rb +0 -69
  155. data/lib/action_controller/authenticate_user.rb +0 -203
  156. data/lib/core_ext.rb +0 -7
  157. data/lib/extensible_forms.rb +0 -284
  158. data/lib/has_permalink.rb +0 -33
  159. data/lib/login/helper_integration.rb +0 -11
  160. data/lib/login/mail_config.rb +0 -39
  161. data/lib/rails_ext/action_controller/cacheable_flash.rb +0 -30
  162. data/lib/rails_ext/action_controller/content_for_assignments.rb +0 -106
  163. data/lib/rails_ext/action_controller/page_caching.rb +0 -23
  164. data/lib/rails_ext/action_controller/responds_to_parent.rb +0 -46
  165. data/lib/rails_ext/active_record/exists.rb +0 -5
  166. data/lib/rails_ext/active_record/sti_instantiation.rb +0 -35
  167. data/lib/rails_ext/active_record/sticky_changes.rb +0 -30
  168. data/lib/rails_ext/railties/plugin.rb +0 -58
  169. data/lib/rails_ext/railties/plugin_configuration.rb +0 -72
  170. data/lib/registry.rb +0 -49
  171. data/lib/tasks/translation.rake +0 -69
  172. data/lib/time_hacks.rb +0 -57
  173. data/lib/webrat_patch.rb +0 -11
  174. data/test/meta_tags_test.rb +0 -42
  175. data/vendor/gems/has_counter/.gitignore +0 -17
  176. data/vendor/gems/has_counter/Gemfile +0 -4
  177. data/vendor/gems/has_counter/LICENSE +0 -22
  178. data/vendor/gems/has_counter/MIT-LICENSE +0 -20
  179. data/vendor/gems/has_counter/README.markdown +0 -64
  180. data/vendor/gems/has_counter/README.md +0 -29
  181. data/vendor/gems/has_counter/Rakefile +0 -2
  182. data/vendor/gems/has_counter/db/migrate/20080601194338_create_counters_table.rb.rb +0 -13
  183. data/vendor/gems/has_counter/has_counter.gemspec +0 -17
  184. data/vendor/gems/has_counter/lib/active_record/has_counter.rb +0 -67
  185. data/vendor/gems/has_counter/lib/counter.rb +0 -23
  186. data/vendor/gems/has_counter/lib/has_counter/version.rb +0 -3
  187. data/vendor/gems/has_counter/lib/has_counter.rb +0 -4
  188. data/vendor/gems/has_counter/spec/has_counter.sqlite3.db +0 -0
  189. data/vendor/gems/has_counter/spec/has_counter_spec.rb +0 -55
  190. data/vendor/gems/has_counter/spec/spec_helper.rb +0 -117
  191. data/vendor/gems/has_filter/.gitignore +0 -17
  192. data/vendor/gems/has_filter/Gemfile +0 -4
  193. data/vendor/gems/has_filter/LICENSE +0 -22
  194. data/vendor/gems/has_filter/README.md +0 -29
  195. data/vendor/gems/has_filter/Rakefile +0 -2
  196. data/vendor/gems/has_filter/app/assets/images/has_filter/filter_add.png +0 -0
  197. data/vendor/gems/has_filter/app/assets/images/has_filter/filter_button_left.png +0 -0
  198. data/vendor/gems/has_filter/app/assets/images/has_filter/filter_button_right.png +0 -0
  199. data/vendor/gems/has_filter/app/assets/images/has_filter/filter_remove.png +0 -0
  200. data/vendor/gems/has_filter/app/assets/javascripts/has_filter/filter.js +0 -35
  201. data/vendor/gems/has_filter/app/assets/javascripts/has_filter/jquery.filter.js +0 -23
  202. data/vendor/gems/has_filter/app/assets/stylesheets/has_filter/alternate/filter.scss +0 -102
  203. data/vendor/gems/has_filter/app/assets/stylesheets/has_filter/filter.scss +0 -100
  204. data/vendor/gems/has_filter/app/helpers/filter_helper.rb +0 -3
  205. data/vendor/gems/has_filter/has_filter.gemspec +0 -17
  206. data/vendor/gems/has_filter/init.rb +0 -3
  207. data/vendor/gems/has_filter/lib/has_filter/active_record/act_macro.rb +0 -102
  208. data/vendor/gems/has_filter/lib/has_filter/filter/base.rb +0 -67
  209. data/vendor/gems/has_filter/lib/has_filter/filter/categorized.rb +0 -24
  210. data/vendor/gems/has_filter/lib/has_filter/filter/chain.rb +0 -45
  211. data/vendor/gems/has_filter/lib/has_filter/filter/set.rb +0 -80
  212. data/vendor/gems/has_filter/lib/has_filter/filter/state.rb +0 -25
  213. data/vendor/gems/has_filter/lib/has_filter/filter/tagged.rb +0 -22
  214. data/vendor/gems/has_filter/lib/has_filter/filter/text.rb +0 -55
  215. data/vendor/gems/has_filter/lib/has_filter/filter.rb +0 -17
  216. data/vendor/gems/has_filter/lib/has_filter/version.rb +0 -3
  217. data/vendor/gems/has_filter/lib/has_filter.rb +0 -22
  218. data/vendor/gems/has_filter/test/db/setup.rb +0 -45
  219. data/vendor/gems/has_filter/test/db/test.sqlite3.db +0 -0
  220. data/vendor/gems/has_filter/test/fixtures.rb +0 -15
  221. data/vendor/gems/has_filter/test/has_filter/filter_chain_test.rb +0 -41
  222. data/vendor/gems/has_filter/test/has_filter/filter_scopes_test.rb +0 -102
  223. data/vendor/gems/has_filter/test/has_filter/filter_tags_test.rb +0 -113
  224. data/vendor/gems/has_filter/test/has_filter/integration.rb +0 -15
  225. data/vendor/gems/has_filter/test/has_filter/scopes_test.rb +0 -48
  226. data/vendor/gems/has_filter/test/log/test.log +0 -34346
  227. data/vendor/gems/has_filter/test/models.rb +0 -23
  228. data/vendor/gems/has_filter/test/templates/has_filter/test/index.html.erb +0 -5
  229. data/vendor/gems/has_filter/test/test_helper.rb +0 -66
  230. data/vendor/gems/xss_terminate/.gitignore +0 -17
  231. data/vendor/gems/xss_terminate/Gemfile +0 -4
  232. data/vendor/gems/xss_terminate/LICENSE +0 -22
  233. data/vendor/gems/xss_terminate/MIT-LICENSE +0 -20
  234. data/vendor/gems/xss_terminate/README +0 -94
  235. data/vendor/gems/xss_terminate/README.md +0 -29
  236. data/vendor/gems/xss_terminate/Rakefile +0 -23
  237. data/vendor/gems/xss_terminate/lib/html5lib_sanitize.rb +0 -2453
  238. data/vendor/gems/xss_terminate/lib/rails_sanitize.rb +0 -8
  239. data/vendor/gems/xss_terminate/lib/xss_terminate/version.rb +0 -3
  240. data/vendor/gems/xss_terminate/lib/xss_terminate.rb +0 -141
  241. data/vendor/gems/xss_terminate/tasks/xss_terminate_tasks.rake +0 -7
  242. data/vendor/gems/xss_terminate/test/models/comment.rb +0 -5
  243. data/vendor/gems/xss_terminate/test/models/entry.rb +0 -7
  244. data/vendor/gems/xss_terminate/test/models/message.rb +0 -3
  245. data/vendor/gems/xss_terminate/test/models/person.rb +0 -5
  246. data/vendor/gems/xss_terminate/test/models/review.rb +0 -5
  247. data/vendor/gems/xss_terminate/test/schema.rb +0 -34
  248. data/vendor/gems/xss_terminate/test/setup_test.rb +0 -16
  249. data/vendor/gems/xss_terminate/test/xss_terminate_test.rb +0 -50
  250. data/vendor/gems/xss_terminate/xss_terminate.gemspec +0 -17
  251. /data/lib/tasks/{adva_cms.rake → adva.rake} +0 -0
@@ -1,69 +0,0 @@
1
- # Auto-registers and re-authenticates anonymous users based on a single token
2
- # that's stored in the session. This is for anonymous posting of blog comments,
3
- # editing wikipages etc. and allows to do such things as:
4
- #
5
- # * store user information in the user table (which keeps the model and db
6
- # structure clean) and
7
- # * allow users to (e.g.) edit their comment based on this anonymous login.
8
-
9
- module ActionController
10
- module AuthenticateAnonymous
11
- def self.included(base)
12
- base.extend ClassMethods
13
- end
14
-
15
- module ClassMethods
16
- def authenticates_anonymous_user
17
- return if authenticates_anonymous_user?
18
- include InstanceMethods
19
- prepend Module.new {
20
- def current_user
21
- @current_user ||= (super || login_or_register_anonymous)
22
- end
23
-
24
- def authenticated?
25
- !!current_user and !current_user.anonymous?
26
- end
27
- }
28
- end
29
-
30
- def authenticates_anonymous_user?
31
- included_modules.include? InstanceMethods
32
- end
33
- end
34
-
35
- module InstanceMethods
36
- def login_or_register_anonymous
37
- anonymous = try_login_anonymous || User.anonymous
38
- anonymous = register_or_update_anonymous anonymous if params[:user]
39
- login_anonymous! anonymous if anonymous
40
- anonymous
41
- end
42
-
43
- def try_login_anonymous
44
- # try to authenticate if token is present
45
- validate_token User, session[:anonymous_token] if session[:anonymous_token]
46
- end
47
-
48
- def register_or_update_anonymous(anonymous)
49
- # if :name and :email params are passed either register a new Anonymous or update the existing one
50
- anonymous.update params[:user].merge(request_info)
51
- anonymous
52
- end
53
-
54
- def login_anonymous!(anonymous)
55
- # set a new session token and expiration
56
- token = anonymous.assign_token('anonymous', 3.hour.from_now)
57
- anonymous.save
58
- session[:anonymous_token] = "#{anonymous.id};#{token}"
59
- cookies[:aid] = anonymous.id.to_s unless anonymous.new_record?
60
- end
61
-
62
- def request_info
63
- { :ip => request.env["REMOTE_ADDR"],
64
- :agent => request.env["HTTP_USER_AGENT"],
65
- :referer => request.env["HTTP_REFERER"] }
66
- end
67
- end
68
- end
69
- end
@@ -1,203 +0,0 @@
1
- module ActionController
2
-
3
- # Module automatically mixed into the all controllers making the
4
- # application of authentication easy. See
5
- # Login::ControllerIntegration::ClassMethods for how to apply
6
- # authentication.
7
- module AuthenticateUser
8
- def self.included(target)
9
- target.extend(ClassMethods)
10
- target.send(:include, InstanceMethods)
11
- target.helper_method(:logged_in?, :authenticated?)
12
- end
13
-
14
- # Methods available as macro-style methods on any controller
15
- module ClassMethods
16
-
17
- # Sets up the controller so that authentication is required. If
18
- # the user is not authenticated then they will be redirected to
19
- # the login screen.
20
- #
21
- # The page requested will be saved so that once the login has
22
- # occured they will be sent back to the page they first
23
- # requested. If no page was requested (they went to the login
24
- # page directly) then they will be directed to profiles/home
25
- # after login which is a placeholder for the app to override.
26
- #
27
- # Options given are passed directly to the before_action method
28
- # so feel free to provide :only and :except options.
29
- def authentication_required
30
- before_action :require_authentication
31
- end
32
-
33
- # Will remove authentication from certain actions. Options given
34
- # are passed directly to skip_before_action so feel free to use
35
- # :only and :except options.
36
- #
37
- # This method is useful in cases where you have locked down the
38
- # entire application by putting authentication_required in your
39
- # ApplicationController but then want to open an action back up
40
- # in a specific controller.
41
- def no_authentication_required
42
- skip_before_action :require_authentication
43
- end
44
- end
45
-
46
- # Methods callable from within actions
47
- module InstanceMethods
48
- def authenticate_user(credentials)
49
- User.authenticate(credentials).tap do |user|
50
- if user
51
- # prevent session hijacking - unnecessary according to http://dev.rubyonrails.org/ticket/10108
52
- # reset_session_except :return_location
53
- session[:uid] = user.id
54
- set_user_cookie!(user)
55
- end
56
- end
57
- end
58
-
59
- # Will retrieve the current_user. Will not force a login but
60
- # simply load the current user if a person is logged in. If
61
- # you need the user object loaded with extra options (such as
62
- # eager loading) then create a private method called
63
- # "user_find_options" on your controller that returns a hash
64
- # of the find options you want.
65
- #
66
- # This method will also inform the models of the current user
67
- # if the current user is logged in and the "User" class responds
68
- # to the class method current_user=. This is a nice way to
69
- # communciate the current user down to the model level for
70
- # model-level security. This means you will want to call this
71
- # method at least once before using the model-level security.
72
- # Usually you will call it in a before filter. This method is
73
- # called automatically when authentication_required is applied to
74
- # an action.
75
- def current_user
76
- @current_user ||= begin
77
- # Check for session[:uid] here? That would mean that for token auth the
78
- # user always needs to be logged out (e.g. in UserController#create).
79
- # Looks a bit more robust this way:
80
- try_login
81
- if session && session[:uid]
82
- user = find_current_user
83
- set_user_cookie!(user)
84
- user
85
- else
86
- User.anonymous
87
- end
88
- end
89
- end
90
-
91
- def authenticated?
92
- !current_user.anonymous?
93
- end
94
- alias :logged_in? :authenticated?
95
-
96
- # killed this because it's just the wrong way to do it
97
- #
98
- # # Will store the current params so that we can return here on
99
- # # successful login. If you want to redirect to the login yourself
100
- # # (perhaps you are applying your own security instead of just
101
- # # determining if the user is logged in) then you will want to
102
- # # call this before issuing your redirect to the login screen.
103
- # def store_return_location
104
- # session[:return_location] = params
105
- # end
106
-
107
- private
108
-
109
- # Will actually test to see if the user is authorized
110
- def require_authentication
111
- # No matter what the app does a user can always login, forgot
112
- # password and register. The controllers provided by this
113
- # plugin alreaddy have these controllers/actions on an
114
- # exception list but this prevents a mistake an overridden
115
- # controller from preventing the normal login behavior.
116
- %w(session password user).each do |c|
117
- %w(new create).each do |a|
118
- return if (controller_name == c) && (action_name == a)
119
- end
120
- end
121
-
122
- # If we cannot get the current user store the requested page
123
- # and send them to the login page.
124
- if current_user.anonymous?
125
- redirect_to login_url(:return_to => request.url) and false
126
- end
127
- end
128
-
129
- def logout
130
- reset_session
131
- forget_me!
132
- end
133
-
134
- def forget_me!
135
- cookies[:remember_me] = nil
136
- cookies[:uid] = nil
137
- cookies[:uname] = nil
138
- end
139
-
140
- def remember_me!
141
- token = current_user.assign_token!('remember me')
142
- cookies[:remember_me] = { :value => "#{current_user.id};#{token}", :expires => 10.years.from_now }
143
- end
144
-
145
- def set_user_cookie!(user = current_user)
146
- unless user.anonymous?
147
- cookies[:uid] = user.id.to_s
148
- cookies[:uname] = user.name
149
- end
150
- end
151
-
152
- # There are a few ways that a user can login without going through
153
- # a login screen. These methods all rely on authenticating with
154
- # the information given in the request. If any of these methods
155
- # are successful then session[:uid] will be set with the current
156
- # user id and current_user will return the current user
157
- def try_login
158
- if user = http_auth_login || validation_login || remember_me_login
159
- session[:uid] = user.id
160
- end
161
- end
162
-
163
- # Will attempt to authenticate with HTTP Auth. HTTP Auth will not
164
- # be required. We are just checking if it is provided mainly for
165
- # RESTful requests.
166
- def http_auth_login
167
- # FIXME: Implement
168
- end
169
-
170
- # Will use the URL param :token to see if we can do a token
171
- # authentication.
172
- def validation_login
173
- validate_token User, params[:token]
174
- end
175
-
176
- # Will check for a :remember_me cookie for a token that will
177
- # authenticate the user.
178
- def remember_me_login
179
- validate_token User, cookies[:remember_me]
180
- end
181
-
182
- # The tokens are stored in various places as id;token. This method
183
- # will split that out and validate it. If everything is successful
184
- # then the user object is returned. Otherwise nil is returned.
185
- # The full token should be passed in.
186
- def validate_token(klass, token, options = {})
187
- return nil if token.blank?
188
- return nil unless token =~ /\;/
189
-
190
- uid, token = token.split ';'
191
- if object = klass.find_by_id(uid)
192
- return object if object.authenticate(token)
193
- end
194
- nil
195
- end
196
-
197
- def find_current_user
198
- User.find_by_id(session[:uid])
199
- end
200
-
201
- end
202
- end
203
- end
data/lib/core_ext.rb DELETED
@@ -1,7 +0,0 @@
1
- class Object
2
- def in?(*array)
3
- array = array.first if array.first.is_a?(Array)
4
- array.include?(self)
5
- end
6
- end
7
-
@@ -1,284 +0,0 @@
1
- require 'action_view'
2
- require 'action_view/helpers'
3
- require 'action_view/helpers/form_helper'
4
-
5
- module ActionView
6
- module Helpers
7
- module FormHelper
8
- prepend Module.new {
9
- def fields_for(*args, &block)
10
- name = singular_class_name(name) unless name.class.in?(String, Symbol)
11
-
12
- options = args.last.is_a?(Hash) ? args.last : {}
13
- options[:builder] ||= pick_form_builder(name)
14
-
15
- super(name, *args, &block)
16
- end
17
- }
18
-
19
- def field_set(object_name, name, content = nil, options = {}, &block)
20
- options.delete(:object)
21
- options[:name] ||= name
22
- options[:id] ||= name
23
- content ||= self.capture(&block) if block_given?
24
- content_tag("fieldset", raw(content), options).html_safe
25
- end
26
-
27
- protected
28
- def singular_class_name(name)
29
- ActiveModel::Naming.singular(name)
30
- end
31
-
32
- def pick_form_builder(name)
33
- name = "#{name.to_s.classify}FormBuilder"
34
- name.constantize
35
- rescue NameError
36
- Object.const_set(name, Class.new(ActionView::Base.default_form_builder)) rescue ActionView::Base.default_form_builder
37
- end
38
- end
39
- end
40
- end
41
-
42
- class ExtensibleFormBuilder < ActionView::Helpers::FormBuilder
43
- class_attribute :callbacks
44
- self.callbacks = { :before => {}, :after => {} }
45
-
46
- class_attribute :tabs
47
- self.tabs = []
48
-
49
- class_attribute :options
50
- self.options = { :labels => false, :wrap => false, :default_class_names => {} }
51
-
52
- class << self
53
- [:labels, :wrap].each do |option|
54
- define_method(:"#{option}=") { |value| self.options[option] = value }
55
- end
56
-
57
- def default_class_names(type = nil)
58
- if type
59
- self.options[:default_class_names][type] ||= []
60
- else
61
- self.options[:default_class_names]
62
- end
63
- end
64
-
65
- def before(object_name, method, string = nil, &block)
66
- add_callback(:before, object_name, method, string || block)
67
- end
68
-
69
- def after(object_name, method, string = nil, &block)
70
- add_callback(:after, object_name, method, string || block)
71
- end
72
-
73
- def tab(name, options = {}, &block)
74
- self.tabs.reject! { |n, b| name == n }
75
- self.tabs += [[name, block]]
76
- end
77
-
78
- protected
79
-
80
- def add_callback(stage, object_name, method, callback)
81
- method = method.to_sym
82
- callbacks[stage][object_name] ||= { }
83
- callbacks[stage][object_name][method] ||= []
84
- callbacks[stage][object_name][method] << callback
85
- end
86
- end
87
-
88
- helpers = field_helpers + %w(select date_select datetime_select time_select time_zone_select collection_select) -
89
- %w(hidden_field label fields_for apply_form_for_options!)
90
-
91
- helpers.each do |method_name|
92
- class_eval <<-src, __FILE__, __LINE__
93
- def #{method_name}(*args, &block)
94
- type = #{method_name.to_sym.inspect}
95
-
96
- options = args.extract_options!
97
- options = add_default_class_names(options, type)
98
- # options = add_tabindex(options, type)
99
-
100
- label, wrap, hint = options.delete(:label), options.delete(:wrap), options.delete(:hint)
101
- name = args.first
102
-
103
- with_callbacks(name) do
104
- tag = super(*(args << options), &block)
105
- # remember_tabindex(tag, options)
106
- tag = hint(tag, hint) if hint
107
- tag = labelize(type, tag, name, label) if label || self.options[:labels]
108
- tag = wrap(tag) if wrap || self.options[:wrap]
109
- tag
110
- end
111
- end
112
- src
113
- end
114
-
115
- def field_set(*args, &block)
116
- options = args.extract_options!
117
- options = add_default_class_names(options, :field_set)
118
-
119
- name = args.first
120
- name ||= :default_fields
121
-
122
- @template.concat with_callbacks(name) {
123
- legend = options.delete(:legend) || ''
124
- legend = @template.content_tag('legend', legend) unless legend.blank?
125
- @template.field_set(@object_name, name, nil, objectify_options(options)) do
126
- legend.to_s + (block ? block.call.to_s : '')
127
- end
128
- }
129
- end
130
-
131
- def tabs
132
- yield if block_given?
133
- assign_ivars!
134
- @template.content_tag(:div, :class => 'tabs') {
135
- @template.content_tag(:ul) {
136
- self.class.tabs.map { |name, block|
137
- klass = self.class.tabs.first.first == name ? 'active' : nil
138
- @template.content_tag 'li', @template.link_to(I18n.t(name, :scope => :'adva.titles'), "##{name}"), :class => klass
139
- }.join.html_safe
140
- } +
141
- self.class.tabs.map { |name, block|
142
- klass = self.class.tabs.first.first == name ? 'tab active' : 'tab'
143
- @template.content_tag 'div', block.call(self), :id => "tab_#{name}", :class => klass
144
- }.join.html_safe
145
- }.html_safe
146
- end
147
-
148
- def tab(name, &block)
149
- with_callbacks(:"tab_#{name}") {
150
- self.class.tab(name, &block)
151
- }
152
- end
153
-
154
- def buttons(name = :submit_buttons, &block)
155
- @template.concat with_callbacks(name) {
156
- @template.capture { @template.buttons(&block) }
157
- }
158
- end
159
-
160
- def render(*args)
161
- @template.send(:render, *args)
162
- end
163
-
164
- protected
165
-
166
- def labelize(type, tag, method, label = nil)
167
- label = case label
168
- when String then label
169
- when Symbol then I18n.t(label)
170
- when TrueClass then
171
- scope = [:activerecord, :attributes] + object.class.to_s.underscore.split('/')
172
- string = I18n.t(method, :scope => scope)
173
- string.is_a?(String) ? string : method.to_s.titleize
174
- else nil
175
- end
176
-
177
- case type
178
- when :check_box, :radio_button
179
- tag + self.label(method, label, :class => 'inline light', :for => extract_id(tag), :id => "#{extract_id(tag)}_label")
180
- else
181
- self.label(method, label) + tag
182
- end
183
- end
184
-
185
- def wrap(tag)
186
- @template.content_tag(:p, tag)
187
- end
188
-
189
- def hint(tag, hint)
190
- hint = I18n.t(hint) if hint.is_a?(Symbol)
191
- tag + @template.content_tag(:span, hint, :class => 'hint', :for => extract_id(tag))
192
- end
193
-
194
- def add_default_class_names(options, type)
195
- options[:class] = (Array(options[:class]) + self.class.default_class_names(type)).join(' ')
196
- options.delete(:class) if options[:class].blank?
197
- options
198
- end
199
-
200
- def tabindex_increment!
201
- @tabindex_count ||= 0
202
- @tabindex_count += 1
203
- end
204
-
205
- def set_tabindex_position(index = nil, position = nil)
206
- position = case position
207
- when :after then tabindexes[index] + 1
208
- when :before then tabindexes[index] - 1
209
- when :same then tabindexes[index]
210
- else tabindex_increment!
211
- end
212
- position
213
- end
214
-
215
- def add_tabindex(options, type)
216
- index = options[:tabindex]
217
-
218
- if index.is_a?(Hash)
219
- key = index.keys.first
220
- options[:tabindex] = set_tabindex_position(index[key], key)
221
- elsif index.is_a?(Symbol)
222
- options[:tabindex] = set_tabindex_position(index, :same)
223
- elsif index.blank?
224
- options[:tabindex] = set_tabindex_position
225
- end
226
-
227
- options
228
- end
229
-
230
- def tabindexes
231
- @tabindexes ||= {}
232
- end
233
-
234
- def remember_tabindex(tag, options)
235
- id = extract_id(tag)
236
- tabindexes[:"#{id}"] = options[:tabindex] unless id.blank?
237
- end
238
-
239
- def with_callbacks(method, &block)
240
- result = ''
241
- result += run_callbacks(:before, method) if method
242
- result += yield.to_s
243
- result += run_callbacks(:after, method) if method
244
- result.html_safe
245
- end
246
-
247
- def run_callbacks(stage, method)
248
- if callbacks = callbacks_for(stage, method.to_sym)
249
- callbacks.inject('') do |result, callback|
250
- result + case callback
251
- when Proc
252
- assign_ivars!
253
- instance_eval(&callback)
254
- else
255
- callback
256
- end.to_s
257
- end
258
- end || ''
259
- end
260
-
261
- def callbacks_for(stage, method)
262
- object_name = @object_name.try(:to_sym)
263
- self.callbacks[stage][object_name] and
264
- self.callbacks[stage][object_name][method.to_sym]
265
- end
266
-
267
- def assign_ivars!
268
- unless @ivars_assigned
269
- @template.assigns.each { |key, value| instance_variable_set("@#{key}", value) }
270
- vars = @template.controller.instance_variable_names
271
- vars.each { |name| instance_variable_set(name, @template.controller.instance_variable_get(name)) }
272
- @ivars_assigned = true
273
- end
274
- end
275
-
276
- # yep, we gotta do this crap because there doesn't seem to be a sane way
277
- # to hook into actionview's form_helper methods
278
- def extract_id(tag)
279
- tag =~ /id="([^"]+)"/
280
- $1
281
- end
282
- end
283
-
284
- ActionView::Base.default_form_builder = ExtensibleFormBuilder
data/lib/has_permalink.rb DELETED
@@ -1,33 +0,0 @@
1
- require "friendly_id"
2
-
3
- module HasPermalink
4
- def self.included(base)
5
- base.extend ClassMethods
6
- end
7
-
8
- module ClassMethods
9
- def has_permalink column, options={}
10
- extend FriendlyId
11
-
12
- friendly_id column do |config|
13
- config.use :slugged, :finders
14
- if options[:scope]
15
- config.use :scoped
16
- config.scope = options[:scope]
17
- end
18
- config.slug_column = options[:url_attribute]
19
- end
20
-
21
- self.class_eval do
22
- def should_generate_new_friendly_id?
23
- permalink.blank?
24
- end
25
- end
26
-
27
- define_method :"#{options[:url_attribute]}=" do |value|
28
- value = value.parameterize if value
29
- super value
30
- end
31
- end
32
- end
33
- end
@@ -1,11 +0,0 @@
1
- module Login
2
- # Automatically mixed into all views for utility functions.
3
- module HelperIntegration
4
-
5
- # Returns the current user at the view level. Everything said
6
- # about the current_user method in the
7
- # Login::ControllerIntegration::InstanceMethods module
8
- # applies to this method as well.
9
- def current_user; controller.current_user end
10
- end
11
- end
@@ -1,39 +0,0 @@
1
- module Login
2
-
3
- # The purpose of this module is to provide an application some control
4
- # over how the messages are sent without having to overwrite blocks
5
- # of code. We do this through simple constants. The two constants
6
- # currently are:
7
- #
8
- # SUBJECT_PREFIX::
9
- # Text that is before every message subject. By default this is not
10
- # used. You may want to put something like the website here.
11
- # NOTIFICATIONS_FROM::
12
- # Who the message appears to be coming from. By default this is
13
- # postmaster@yourdomain.com
14
- #
15
- # If you want to access these same values in your own mailers just
16
- # mix them into your mailers and the methods will be available.
17
- module MailConfig
18
- protected
19
-
20
- # Will return subject prefix
21
- def subject_prefix
22
- return "[#{SUBJECT_PREFIX}] " if Object.const_defined?('SUBJECT_PREFIX')
23
- ''
24
- end
25
-
26
- # Email message appear to come from. The constant takes priority
27
- # but if no constant is defined then the email is extracted from
28
- # the given param which can be any link that you want the email
29
- # to appear to come from.
30
- def system_email(extract_from)
31
- return NOTIFICATIONS_FROM if Object.const_defined?('NOTIFICATIONS_FROM')
32
- if host = URI.parse(extract_from).host
33
- host = host.split '.'
34
- host.shift if host.first =~ /www/i
35
- "postmaster@#{host * '.'}"
36
- end
37
- end
38
- end
39
- end
@@ -1,30 +0,0 @@
1
- # http://github.com/pivotal/cacheable-flash
2
-
3
- require "json"
4
-
5
- module CacheableFlash
6
- def self.included(base)
7
- base.prepend_around_action :write_flash_to_cookie
8
- end
9
-
10
- def write_flash_to_cookie
11
- yield self
12
-
13
- cookie_flash = begin
14
- JSON.parse(cookies["flash"] || "{}")
15
- rescue JSON::ParserError
16
- {}
17
- end
18
-
19
- flash.each do |key, value|
20
- if cookie_flash[key.to_s].blank?
21
- cookie_flash[key.to_s] = value
22
- else
23
- cookie_flash[key.to_s] << "<br/>#{value}" # TODO should be an array
24
- end
25
- end
26
-
27
- cookies['flash'] = cookie_flash.to_json
28
- flash.clear
29
- end
30
- end