incline 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (303) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +13 -0
  3. data/Gemfile +17 -0
  4. data/Gemfile.lock +186 -0
  5. data/MIT-LICENSE +20 -0
  6. data/README.rdoc +208 -0
  7. data/Rakefile +37 -0
  8. data/app/assets/fonts/incline/.keep +0 -0
  9. data/app/assets/images/incline/.keep +0 -0
  10. data/app/assets/images/incline/barcode-B.svg +181 -0
  11. data/app/assets/javascripts/incline/activate_classed_items.js +11 -0
  12. data/app/assets/javascripts/incline/application.js +30 -0
  13. data/app/assets/javascripts/incline/bootstrap-datepicker.js +1800 -0
  14. data/app/assets/javascripts/incline/datatables.js +22193 -0
  15. data/app/assets/javascripts/incline/escapeHtml.js +10 -0
  16. data/app/assets/javascripts/incline/inline_actions.js +479 -0
  17. data/app/assets/javascripts/incline/jquery.doubleScroll.js +112 -0
  18. data/app/assets/javascripts/incline/jquery.number.js +764 -0
  19. data/app/assets/javascripts/incline/regexMask.js +27 -0
  20. data/app/assets/javascripts/incline/select2/i18n/en.js +3 -0
  21. data/app/assets/javascripts/incline/select2/select2.full.js +6436 -0
  22. data/app/assets/stylesheets/incline/application.css +18 -0
  23. data/app/assets/stylesheets/incline/bootstrap-theme.min.css +5 -0
  24. data/app/assets/stylesheets/incline/custom.scss +279 -0
  25. data/app/assets/stylesheets/incline/datatables.css +494 -0
  26. data/app/assets/stylesheets/incline/datepicker3.css +790 -0
  27. data/app/assets/stylesheets/incline/select2.css +484 -0
  28. data/app/controllers/incline/access_groups_controller.rb +127 -0
  29. data/app/controllers/incline/access_test_controller.rb +30 -0
  30. data/app/controllers/incline/account_activations_controller.rb +28 -0
  31. data/app/controllers/incline/application_controller.rb +11 -0
  32. data/app/controllers/incline/contact_controller.rb +34 -0
  33. data/app/controllers/incline/password_resets_controller.rb +113 -0
  34. data/app/controllers/incline/security_controller.rb +100 -0
  35. data/app/controllers/incline/sessions_controller.rb +50 -0
  36. data/app/controllers/incline/users_controller.rb +304 -0
  37. data/app/controllers/incline/welcome_controller.rb +19 -0
  38. data/app/helpers/incline/.keep +0 -0
  39. data/app/mailers/incline/application_mailer_base.rb +11 -0
  40. data/app/mailers/incline/contact_form.rb +19 -0
  41. data/app/mailers/incline/user_mailer.rb +45 -0
  42. data/app/models/incline/access_group.rb +121 -0
  43. data/app/models/incline/access_group_group_member.rb +12 -0
  44. data/app/models/incline/access_group_user_member.rb +10 -0
  45. data/app/models/incline/action_group.rb +12 -0
  46. data/app/models/incline/action_security.rb +222 -0
  47. data/app/models/incline/contact_message.rb +37 -0
  48. data/app/models/incline/disable_info.rb +20 -0
  49. data/app/models/incline/password_reset.rb +14 -0
  50. data/app/models/incline/password_reset_request.rb +14 -0
  51. data/app/models/incline/user.rb +437 -0
  52. data/app/models/incline/user_login_history.rb +30 -0
  53. data/app/views/incline/access_groups/_details.json.jbuilder +10 -0
  54. data/app/views/incline/access_groups/_form.html.erb +19 -0
  55. data/app/views/incline/access_groups/_list.html.erb +60 -0
  56. data/app/views/incline/access_groups/_messages.json.jbuilder +6 -0
  57. data/app/views/incline/access_groups/edit.html.erb +2 -0
  58. data/app/views/incline/access_groups/index.html.erb +6 -0
  59. data/app/views/incline/access_groups/index.json.jbuilder +16 -0
  60. data/app/views/incline/access_groups/new.html.erb +2 -0
  61. data/app/views/incline/access_groups/show.html.erb +9 -0
  62. data/app/views/incline/access_groups/show.json.jbuilder +11 -0
  63. data/app/views/incline/contact/new.html.erb +22 -0
  64. data/app/views/incline/contact_form/contact.html.erb +16 -0
  65. data/app/views/incline/contact_form/contact.text.erb +13 -0
  66. data/app/views/incline/password_resets/edit.html.erb +16 -0
  67. data/app/views/incline/password_resets/new.html.erb +12 -0
  68. data/app/views/incline/security/_details.json.jbuilder +7 -0
  69. data/app/views/incline/security/_form.html.erb +20 -0
  70. data/app/views/incline/security/_list.html.erb +89 -0
  71. data/app/views/incline/security/_messages.json.jbuilder +6 -0
  72. data/app/views/incline/security/edit.html.erb +2 -0
  73. data/app/views/incline/security/index.html.erb +6 -0
  74. data/app/views/incline/security/index.json.jbuilder +16 -0
  75. data/app/views/incline/security/show.html.erb +31 -0
  76. data/app/views/incline/security/show.json.jbuilder +11 -0
  77. data/app/views/incline/sessions/new.html.erb +26 -0
  78. data/app/views/incline/user_mailer/account_activation.html.erb +7 -0
  79. data/app/views/incline/user_mailer/account_activation.text.erb +6 -0
  80. data/app/views/incline/user_mailer/invalid_password_reset.html.erb +3 -0
  81. data/app/views/incline/user_mailer/invalid_password_reset.text.erb +5 -0
  82. data/app/views/incline/user_mailer/password_reset.html.erb +8 -0
  83. data/app/views/incline/user_mailer/password_reset.text.erb +7 -0
  84. data/app/views/incline/users/_details.json.jbuilder +32 -0
  85. data/app/views/incline/users/_form.html.erb +21 -0
  86. data/app/views/incline/users/_list.html.erb +102 -0
  87. data/app/views/incline/users/_messages.json.jbuilder +6 -0
  88. data/app/views/incline/users/disable_confirm.html.erb +19 -0
  89. data/app/views/incline/users/edit.html.erb +5 -0
  90. data/app/views/incline/users/index.html.erb +6 -0
  91. data/app/views/incline/users/index.json.jbuilder +16 -0
  92. data/app/views/incline/users/new.html.erb +5 -0
  93. data/app/views/incline/users/show.html.erb +12 -0
  94. data/app/views/incline/users/show.json.jbuilder +11 -0
  95. data/app/views/incline/welcome/home.html.erb +5 -0
  96. data/app/views/layouts/application.html.erb +1 -0
  97. data/app/views/layouts/incline/_account_menu.html.erb +18 -0
  98. data/app/views/layouts/incline/_app_menu_anon.html.erb +1 -0
  99. data/app/views/layouts/incline/_app_menu_authenticated.html.erb +1 -0
  100. data/app/views/layouts/incline/_footer.html.erb +13 -0
  101. data/app/views/layouts/incline/_header.html.erb +21 -0
  102. data/app/views/layouts/incline/_html_mailer.html.erb +5 -0
  103. data/app/views/layouts/incline/_incline_app.html.erb +25 -0
  104. data/app/views/layouts/incline/_messages.html.erb +3 -0
  105. data/app/views/layouts/incline/_shim.html.erb +3 -0
  106. data/app/views/layouts/incline/_text_mailer.text.erb +1 -0
  107. data/app/views/layouts/incline/application.html.erb +1 -0
  108. data/app/views/layouts/mailer.html.erb +2 -0
  109. data/app/views/layouts/mailer.text.erb +2 -0
  110. data/bin/rails +12 -0
  111. data/bin/test_scaffold.sh +10 -0
  112. data/config/routes.rb +61 -0
  113. data/db/migrate/20170511230126_create_incline_users.rb +26 -0
  114. data/db/migrate/20170515003052_create_incline_access_groups.rb +10 -0
  115. data/db/migrate/20170515003221_create_incline_user_login_histories.rb +12 -0
  116. data/db/migrate/20170515150908_create_incline_access_group_user_members.rb +11 -0
  117. data/db/migrate/20170515151058_create_incline_access_group_group_members.rb +11 -0
  118. data/db/migrate/20170517193432_add_comments_to_incline_user.rb +5 -0
  119. data/db/migrate/20170622132700_create_incline_action_securities.rb +16 -0
  120. data/db/migrate/20170622172712_create_incline_action_groups.rb +11 -0
  121. data/db/migrate/20170622195742_add_non_standard_to_action_security.rb +5 -0
  122. data/db/migrate/20170622230422_add_visible_to_action_security.rb +5 -0
  123. data/db/seeds.rb +81 -0
  124. data/exe/new_incline_app +42 -0
  125. data/lib/generators/incline/install_generator.rb +259 -0
  126. data/lib/generators/incline/templates/_app_menu_anon.html.erb +1 -0
  127. data/lib/generators/incline/templates/_app_menu_authenticated.html.erb +1 -0
  128. data/lib/generators/incline/templates/incline_application.css +17 -0
  129. data/lib/generators/incline/templates/incline_application.html.erb +1 -0
  130. data/lib/generators/incline/templates/incline_application.js +12 -0
  131. data/lib/generators/incline/templates/incline_database.yml +25 -0
  132. data/lib/generators/incline/templates/incline_email.yml +20 -0
  133. data/lib/generators/incline/templates/incline_mailer.html.erb +2 -0
  134. data/lib/generators/incline/templates/incline_mailer.text.erb +2 -0
  135. data/lib/generators/incline/templates/incline_users.yml +64 -0
  136. data/lib/generators/incline/templates/incline_version.rb +3 -0
  137. data/lib/incline/auth_engine_base.rb +52 -0
  138. data/lib/incline/data_tables_request.rb +336 -0
  139. data/lib/incline/date_time_formats.rb +6 -0
  140. data/lib/incline/engine.rb +212 -0
  141. data/lib/incline/errors.rb +15 -0
  142. data/lib/incline/extensions/action_controller_base.rb +526 -0
  143. data/lib/incline/extensions/action_mailer_base.rb +66 -0
  144. data/lib/incline/extensions/action_view_base.rb +489 -0
  145. data/lib/incline/extensions/active_record_base.rb +308 -0
  146. data/lib/incline/extensions/application.rb +137 -0
  147. data/lib/incline/extensions/application_configuration.rb +50 -0
  148. data/lib/incline/extensions/connection_adapter.rb +55 -0
  149. data/lib/incline/extensions/date_time_value.rb +123 -0
  150. data/lib/incline/extensions/date_value.rb +77 -0
  151. data/lib/incline/extensions/decimal_value.rb +55 -0
  152. data/lib/incline/extensions/erb_scaffold_generator.rb +31 -0
  153. data/lib/incline/extensions/float_value.rb +59 -0
  154. data/lib/incline/extensions/form_builder.rb +617 -0
  155. data/lib/incline/extensions/integer_value.rb +54 -0
  156. data/lib/incline/extensions/jbuilder_generator.rb +38 -0
  157. data/lib/incline/extensions/jbuilder_template.rb +39 -0
  158. data/lib/incline/extensions/main_app.rb +40 -0
  159. data/lib/incline/extensions/numeric.rb +63 -0
  160. data/lib/incline/extensions/object.rb +31 -0
  161. data/lib/incline/extensions/resource_route_generator.rb +53 -0
  162. data/lib/incline/extensions/session.rb +113 -0
  163. data/lib/incline/extensions/string.rb +50 -0
  164. data/lib/incline/extensions/test_case.rb +764 -0
  165. data/lib/incline/extensions/time_zone_converter.rb +40 -0
  166. data/lib/incline/global_status.rb +236 -0
  167. data/lib/incline/helpers/route_hash_formatter.rb +46 -0
  168. data/lib/incline/json_log_formatter.rb +96 -0
  169. data/lib/incline/json_logger.rb +17 -0
  170. data/lib/incline/log.rb +153 -0
  171. data/lib/incline/number_formats.rb +17 -0
  172. data/lib/incline/recaptcha.rb +346 -0
  173. data/lib/incline/user_manager.rb +212 -0
  174. data/lib/incline/validators/email_validator.rb +45 -0
  175. data/lib/incline/validators/ip_address_validator.rb +32 -0
  176. data/lib/incline/validators/recaptcha_validator.rb +37 -0
  177. data/lib/incline/validators/safe_name_validator.rb +31 -0
  178. data/lib/incline/version.rb +3 -0
  179. data/lib/incline/work_path.rb +75 -0
  180. data/lib/incline.rb +197 -0
  181. data/lib/tasks/incline_tasks.rake +4 -0
  182. data/lib/templates/erb/scaffold/_form.html.erb +43 -0
  183. data/lib/templates/erb/scaffold/_list.html.erb +81 -0
  184. data/lib/templates/erb/scaffold/edit.html.erb +1 -0
  185. data/lib/templates/erb/scaffold/index.html.erb +6 -0
  186. data/lib/templates/erb/scaffold/new.html.erb +1 -0
  187. data/lib/templates/erb/scaffold/show.html.erb +34 -0
  188. data/lib/templates/jbuilder/scaffold/_details.json.jbuilder +20 -0
  189. data/lib/templates/jbuilder/scaffold/index.json.jbuilder +16 -0
  190. data/lib/templates/jbuilder/scaffold/show.json.jbuilder +16 -0
  191. data/lib/templates/rails/scaffold_controller/controller.rb +128 -0
  192. data/test/controllers/incline/access_groups_controller_test.rb +65 -0
  193. data/test/controllers/incline/access_test_controller_test.rb +53 -0
  194. data/test/controllers/incline/contact_controller_test.rb +32 -0
  195. data/test/controllers/incline/security_controller_test.rb +39 -0
  196. data/test/controllers/incline/welcome_controller_test.rb +16 -0
  197. data/test/dummy/README.rdoc +28 -0
  198. data/test/dummy/Rakefile +6 -0
  199. data/test/dummy/app/assets/images/.keep +0 -0
  200. data/test/dummy/app/assets/javascripts/application.js +12 -0
  201. data/test/dummy/app/assets/stylesheets/application.css +17 -0
  202. data/test/dummy/app/controllers/application_controller.rb +5 -0
  203. data/test/dummy/app/controllers/concerns/.keep +0 -0
  204. data/test/dummy/app/helpers/application_helper.rb +2 -0
  205. data/test/dummy/app/mailers/.keep +0 -0
  206. data/test/dummy/app/models/.keep +0 -0
  207. data/test/dummy/app/models/concerns/.keep +0 -0
  208. data/test/dummy/app/views/layouts/application.html.erb +1 -0
  209. data/test/dummy/app/views/layouts/incline/_app_menu_anon.html.erb +1 -0
  210. data/test/dummy/app/views/layouts/incline/_app_menu_authenticated.html.erb +1 -0
  211. data/test/dummy/app/views/layouts/mailer.html.erb +2 -0
  212. data/test/dummy/app/views/layouts/mailer.text.erb +2 -0
  213. data/test/dummy/bin/bundle +3 -0
  214. data/test/dummy/bin/rails +4 -0
  215. data/test/dummy/bin/rake +4 -0
  216. data/test/dummy/bin/setup +29 -0
  217. data/test/dummy/config/application.rb +38 -0
  218. data/test/dummy/config/boot.rb +5 -0
  219. data/test/dummy/config/database.yml +34 -0
  220. data/test/dummy/config/email.yml +24 -0
  221. data/test/dummy/config/environment.rb +5 -0
  222. data/test/dummy/config/environments/development.rb +45 -0
  223. data/test/dummy/config/environments/production.rb +85 -0
  224. data/test/dummy/config/environments/test.rb +44 -0
  225. data/test/dummy/config/initializers/assets.rb +11 -0
  226. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  227. data/test/dummy/config/initializers/cookies_serializer.rb +3 -0
  228. data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  229. data/test/dummy/config/initializers/inflections.rb +16 -0
  230. data/test/dummy/config/initializers/mime_types.rb +4 -0
  231. data/test/dummy/config/initializers/session_store.rb +3 -0
  232. data/test/dummy/config/initializers/to_time_preserves_timezone.rb +10 -0
  233. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  234. data/test/dummy/config/locales/en.yml +23 -0
  235. data/test/dummy/config/routes.rb +6 -0
  236. data/test/dummy/config.ru +4 -0
  237. data/test/dummy/db/schema.rb +108 -0
  238. data/test/dummy/lib/assets/.keep +0 -0
  239. data/test/dummy/log/.keep +0 -0
  240. data/test/dummy/public/404.html +67 -0
  241. data/test/dummy/public/422.html +67 -0
  242. data/test/dummy/public/500.html +66 -0
  243. data/test/dummy/public/favicon.ico +0 -0
  244. data/test/extensions/action_controller_base_extensions_test.rb +21 -0
  245. data/test/extensions/action_mailer_base_extensions_test.rb +20 -0
  246. data/test/extensions/action_view_base_extensions_test.rb +267 -0
  247. data/test/extensions/active_record_extensions_test.rb +173 -0
  248. data/test/extensions/application_configuration_extensions_test.rb +46 -0
  249. data/test/extensions/application_extensions_test.rb +23 -0
  250. data/test/extensions/connection_adapter_extensions_test.rb +54 -0
  251. data/test/extensions/date_time_value_extensions_test.rb +104 -0
  252. data/test/extensions/date_value_extensions_test.rb +102 -0
  253. data/test/extensions/decimal_value_extensions_test.rb +85 -0
  254. data/test/extensions/erb_scaffold_generator_extensions_test.rb +17 -0
  255. data/test/extensions/float_value_extensions_test.rb +78 -0
  256. data/test/extensions/form_builder_extensions_test.rb +28 -0
  257. data/test/extensions/integer_value_extensions_test.rb +78 -0
  258. data/test/extensions/jbuilder_generator_extensions_test.rb +21 -0
  259. data/test/extensions/jbuilder_template_extensions_test.rb +47 -0
  260. data/test/extensions/main_app_extensions_test.rb +55 -0
  261. data/test/extensions/numeric_extensions_test.rb +76 -0
  262. data/test/extensions/object_extensions_test.rb +104 -0
  263. data/test/extensions/session_extensions_test.rb +69 -0
  264. data/test/extensions/string_extensions_test.rb +32 -0
  265. data/test/extensions/test_case_extensions_test.rb +538 -0
  266. data/test/extensions/time_zone_converter_extensions_test.rb +10 -0
  267. data/test/fixtures/incline/access_group_group_members.yml +1 -0
  268. data/test/fixtures/incline/access_group_user_members.yml +1 -0
  269. data/test/fixtures/incline/access_groups.yml +13 -0
  270. data/test/fixtures/incline/action_groups.yml +6 -0
  271. data/test/fixtures/incline/action_securities.yml +18 -0
  272. data/test/fixtures/incline/user_login_histories.yml +1 -0
  273. data/test/fixtures/incline/users.yml +64 -0
  274. data/test/incline_test.rb +63 -0
  275. data/test/integration/incline/users_edit_test.rb +180 -0
  276. data/test/integration/incline/users_login_test.rb +105 -0
  277. data/test/integration/incline/users_signup_test.rb +147 -0
  278. data/test/integration/navigation_test.rb +11 -0
  279. data/test/lib/data_tables_request_test.rb +245 -0
  280. data/test/lib/date_time_formats_test.rb +111 -0
  281. data/test/lib/global_status_test.rb +89 -0
  282. data/test/lib/json_log_formatter_test.rb +43 -0
  283. data/test/lib/log_test.rb +36 -0
  284. data/test/lib/recaptcha_test.rb +75 -0
  285. data/test/lib/user_manager_test.rb +47 -0
  286. data/test/lib/work_path_test.rb +18 -0
  287. data/test/models/incline/access_group_group_member_test.rb +30 -0
  288. data/test/models/incline/access_group_test.rb +60 -0
  289. data/test/models/incline/access_group_user_member_test.rb +29 -0
  290. data/test/models/incline/action_group_test.rb +27 -0
  291. data/test/models/incline/action_security_test.rb +176 -0
  292. data/test/models/incline/contact_message_test.rb +66 -0
  293. data/test/models/incline/disable_info_test.rb +29 -0
  294. data/test/models/incline/password_reset_request_test.rb +35 -0
  295. data/test/models/incline/password_reset_test.rb +51 -0
  296. data/test/models/incline/user_login_history_test.rb +31 -0
  297. data/test/models/incline/user_test.rb +91 -0
  298. data/test/test_helper.rb +42 -0
  299. data/test/validators/email_validator_test.rb +102 -0
  300. data/test/validators/ip_address_validator_test.rb +107 -0
  301. data/test/validators/recaptcha_validator_test.rb +57 -0
  302. data/test/validators/safe_name_validator_test.rb +101 -0
  303. metadata +584 -0
@@ -0,0 +1,34 @@
1
+ module Incline
2
+ class ContactController < ApplicationController
3
+
4
+ allow_anon true
5
+
6
+ ##
7
+ # GET /incline/contact
8
+ def new
9
+ @msg = Incline::ContactMessage.new
10
+ end
11
+
12
+ ##
13
+ # POST /incline/contact
14
+ def create
15
+ @msg = get_message
16
+ if @msg.valid?
17
+ @msg.remote_ip = request.remote_ip
18
+ @msg.send_message
19
+ flash[:success] = 'Your message has been sent.'
20
+ redirect_to root_url
21
+ else
22
+ render 'new'
23
+ end
24
+ end
25
+
26
+ private
27
+
28
+ def get_message
29
+ p = params.require(:contact_message).permit(:your_name, :your_email, :related_to, :subject, :body, :recaptcha)
30
+ Incline::ContactMessage.new(p)
31
+ end
32
+
33
+ end
34
+ end
@@ -0,0 +1,113 @@
1
+ module Incline
2
+ class PasswordResetsController < ApplicationController
3
+ before_action :set_reset_request, only: [ :new, :create ]
4
+ before_action :set_user, only: [:edit, :update]
5
+ before_action :valid_user, only: [ :edit, :update ]
6
+ before_action :set_reset, only: [ :edit, :update ]
7
+ before_action :check_expiration, only: [ :edit, :update ]
8
+
9
+ # The user should NOT be logged in.
10
+ require_anon true
11
+
12
+
13
+ ##
14
+ # GET /incline/password_resets/new
15
+ def new
16
+
17
+ end
18
+
19
+ ##
20
+ # POST /incline/password_resets
21
+ def create
22
+ unless @reset_request.valid?
23
+ render 'new' and return
24
+ end
25
+
26
+ @user = User.find_by(email: @reset_request.email)
27
+ if @user && @user.enabled? && @user.activated?
28
+ @user.create_reset_digest
29
+ @user.send_password_reset_email request.remote_ip
30
+ elsif @user
31
+ if !@user.enabled?
32
+ User.send_disabled_reset_email(email, request.remote_ip)
33
+ elsif !@user.active?
34
+ User.send_inactive_reset_email(email, request.remote_ip)
35
+ else
36
+ User.send_missing_reset_email(email, request.remote_ip)
37
+ end
38
+ else
39
+ User.send_missing_reset_email(email, request.remote_ip)
40
+ end
41
+
42
+ flash[:info] = 'An email with password reset information has been sent to you.'
43
+ redirect_to root_url
44
+ end
45
+
46
+ ##
47
+ # GET /incline/password_resets/reset-token?email=user@example.com
48
+ def edit
49
+
50
+ end
51
+
52
+ ##
53
+ # POST /incline/password_resets/reset-token
54
+ def update
55
+ unless @reset.valid?
56
+ render 'edit' and return
57
+ end
58
+
59
+ if @user.update_attributes(password: @reset.password, password_confirmation: @reset.password)
60
+ log_in @user
61
+ flash[:success] = 'Password has been reset.'
62
+ redirect_to @user
63
+ else
64
+ @user.errors[:base] << 'Failed to reset password.'
65
+ render 'edit'
66
+ end
67
+ end
68
+
69
+ private
70
+
71
+ def set_reset_request
72
+ @reset_request = Incline::PasswordResetRequest.new(reset_request_params)
73
+ end
74
+
75
+ def set_reset
76
+ @reset = Incline::PasswordReset.new(reset_params)
77
+ end
78
+
79
+ def set_user
80
+ @user = User.find_by(email: params[:email])
81
+ end
82
+
83
+ def reset_request_params
84
+ if params[:password_reset_request]
85
+ params.require(:password_reset_request).permit(:email, :recaptcha)
86
+ else
87
+ {}
88
+ end
89
+ end
90
+
91
+ def reset_params
92
+ if params[:password_reset]
93
+ merge(params.require(:password_reset).permit(:password, :password_confirmation, :recaptcha))
94
+ else
95
+ {}
96
+ end
97
+ end
98
+
99
+ def valid_user
100
+ unless @user && @user.enabled? && @user.activated? && @user.authenticated?(:reset, params[:id])
101
+ redirect_to root_url
102
+ end
103
+ end
104
+
105
+ def check_expiration
106
+ if @user.password_reset_expired?
107
+ flash[:danger] = 'Password reset request has expired.'
108
+ redirect_to new_password_reset_url
109
+ end
110
+ end
111
+
112
+ end
113
+ end
@@ -0,0 +1,100 @@
1
+ module Incline
2
+ class SecurityController < ApplicationController
3
+
4
+ before_action :set_dt_request, only: [ :index, :locate ]
5
+ before_action :set_security, only: [ :show, :edit, :update ]
6
+
7
+ require_admin true
8
+
9
+ layout :layout_to_use
10
+
11
+ ##
12
+ # GET /incline/security
13
+ def index
14
+ @lists = {}
15
+ unless @dt_request.provided?
16
+ Incline::ActionSecurity.valid_items # ensure only valid items are in the database.
17
+
18
+ # build lists for the dropdown filters.
19
+ @lists[:controller_name] = Incline::ActionSecurity.visible.pluck(:controller_name).uniq.sort
20
+ @lists[:action_name] = Incline::ActionSecurity.visible.pluck(:action_name).uniq.sort
21
+ @lists[:short_permitted] = Incline::ActionSecurity::SHORT_PERMITTED_FILTERS
22
+ end
23
+ end
24
+
25
+ ##
26
+ # GET /incline/security/1
27
+ def show
28
+ end
29
+
30
+ ##
31
+ # GET /incline/security/1/edit
32
+ def edit
33
+ end
34
+
35
+ ##
36
+ # PATCH/PUT /incline/security/1
37
+ def update
38
+ if @security.update(security_params)
39
+ handle_update_success notice: 'Action security was successfully updated.'
40
+ else
41
+ handle_update_failure :edit
42
+ end
43
+ end
44
+
45
+ # POST /incline/security/1/locate
46
+ def locate
47
+ render json: { record: @dt_request.record_location }
48
+ end
49
+
50
+ # GET/POST /incline/security/api?action=...
51
+ def api
52
+ process_api_action
53
+ end
54
+
55
+ private
56
+
57
+ def layout_to_use
58
+ inline_request? ? false : nil
59
+ end
60
+
61
+ def handle_update_failure(action)
62
+ if json_request?
63
+ # add a model-level error and render the json response.
64
+ @access_group.errors.add(:base, 'failed to save')
65
+ render 'show', formats: [ :json ]
66
+ else
67
+ # render the appropriate action.
68
+ render action
69
+ end
70
+ end
71
+
72
+ def handle_update_success(*messages)
73
+ # reload the cache from the database.
74
+ Incline::ActionSecurity.valid_items true, false
75
+
76
+ if inline_request?
77
+ # inline and json requests expect json on success.
78
+ render 'show', formats: [ :json ]
79
+ else
80
+ # otherwise, we redirect.
81
+ redirect_to index_security_url, *messages
82
+ end
83
+ end
84
+
85
+ def set_dt_request
86
+ @dt_request = Incline::DataTablesRequest.new(params.merge(force_regex: true)) do
87
+ Incline::ActionSecurity.visible
88
+ end
89
+ end
90
+
91
+ def set_security
92
+ @security = Incline::ActionSecurity.find(params[:id])
93
+ end
94
+
95
+ def security_params
96
+ params.require(:action_security).permit(group_ids: [])
97
+ end
98
+
99
+ end
100
+ end
@@ -0,0 +1,50 @@
1
+ module Incline
2
+ ##
3
+ # A simple controller providing the login and logout methods for the application.
4
+ class SessionsController < ApplicationController
5
+
6
+ # must be anon to login.
7
+ require_anon :new, :create
8
+
9
+ # don't raise an error if anon tries to logout.
10
+ allow_anon true
11
+
12
+ ##
13
+ # GET /incline/login
14
+ def new
15
+ end
16
+
17
+ ##
18
+ # POST /incline/login
19
+ def create
20
+ if (@user = Incline::UserManager.authenticate(params[:session][:email], params[:session][:password], request.remote_ip))
21
+ if @user.activated?
22
+ # log the user in.
23
+ log_in @user
24
+ params[:session][:remember_me] == '1' ? remember(@user) : forget(@user)
25
+
26
+ # show alerts on login.
27
+ session[:show_alerts] = true
28
+
29
+ redirect_back_or @user
30
+ else
31
+ flash[:safe_warning] = 'Your account has not yet been activated.<br/>Check your email for the activation link.'
32
+ redirect_to root_url
33
+ end
34
+ else
35
+ # deny login.
36
+ flash.now[:danger] = 'Invalid email or password.'
37
+ render 'new'
38
+ end
39
+ end
40
+
41
+ ##
42
+ # DELETE /incline/logout
43
+ def destroy
44
+ log_out if logged_in?
45
+ redirect_to root_url
46
+ end
47
+
48
+ end
49
+
50
+ end
@@ -0,0 +1,304 @@
1
+ # require_dependency "incline/application_controller"
2
+
3
+ module Incline
4
+ class UsersController < ApplicationController
5
+
6
+ before_action :set_user, except: [ :index, :new, :create, :api ]
7
+ before_action :set_dt_request, only: [ :index, :locate ]
8
+ before_action :set_disable_info, only: [ :disable_confirm, :disable ]
9
+ before_action :not_current, only: [ :destroy, :disable, :disable_confirm, :enable, :promote, :demote ]
10
+
11
+ layout :use_layout, except: [ :index ]
12
+
13
+ # Only anonymous users can signup.
14
+ require_anon :new, :create
15
+
16
+ # Only admins can delete/disable/enable users, or list all users, or show/edit/update other users.
17
+ require_admin :index, :show, :edit, :update, :destroy, :disable, :disable_confirm, :enable, :promote, :demote, :locate
18
+
19
+ ##
20
+ # GET /incline/users
21
+ def index
22
+
23
+ end
24
+
25
+ ##
26
+ # GET /incline/signup
27
+ def new
28
+ @user = Incline::User.new
29
+ end
30
+
31
+ ##
32
+ # POST /incline/signup
33
+ def create
34
+ @user = Incline::User.new(user_params :before_create)
35
+
36
+ if system_admin? # skip recaptcha check if an admin is currently logged in.
37
+ @user.recaptcha = :verified
38
+ end
39
+
40
+ if @user.valid?
41
+ if @user.save
42
+ @user.send_activation_email request.remote_ip
43
+ if system_admin?
44
+ flash[:info] = "The user #{@user} has been created, but will need to activate their account before use."
45
+ additional_params = user_params :after_create
46
+ if additional_params.any?
47
+ unless @user.update_attributes(additional_params)
48
+ flash[:warning] = 'Failed to apply additional attributes to new user account.'
49
+ end
50
+ end
51
+ if inline_request?
52
+ render 'show', formats: [ :json ]
53
+ else
54
+ redirect_to users_url
55
+ end
56
+ return
57
+ else
58
+ flash[:safe_info] = 'Your account has been created, but needs to be activated before you can use it.<br>Please check your email to activate your account.'
59
+ if inline_request?
60
+ render 'show', formats: [ :json ]
61
+ else
62
+ redirect_to root_url
63
+ end
64
+ return
65
+ end
66
+ else
67
+ @user.errors[:base] << 'Failed to create user account.'
68
+ end
69
+ end
70
+ render 'new'
71
+ end
72
+
73
+ ##
74
+ # GET /incline/users/1
75
+ def show
76
+ render 'show'
77
+ end
78
+
79
+ ##
80
+ # GET /incline/users/1/edit
81
+ def edit
82
+ render 'edit'
83
+ end
84
+
85
+ ##
86
+ # PUT /incline/users/1
87
+ def update
88
+ if @user.update_attributes(user_params)
89
+ if current_user?(@user)
90
+ flash[:success] = 'Your profile has been updated.'
91
+ if inline_request?
92
+ render 'show', formats: [ :json ]
93
+ else
94
+ redirect_to @user
95
+ end
96
+ return
97
+ else
98
+ flash[:success] = "The user #{@user} has been updated."
99
+ if inline_request?
100
+ render 'show', formats: [ :json ]
101
+ else
102
+ redirect_to users_path
103
+ end
104
+ return
105
+ end
106
+ end
107
+ render 'edit'
108
+ end
109
+
110
+ ##
111
+ # DELETE /incline/users/1
112
+ def destroy
113
+ if @user.enabled?
114
+ flash[:danger] = 'Cannot delete an enabled user.'
115
+ elsif @user.disabled_at.blank? || @user.disabled_at > 15.days.ago
116
+ flash[:danger] = 'Cannot delete a user within 15 days of being disabled.'
117
+ else
118
+ @user.destroy
119
+ flash[:success] = "User #{@user} has been deleted."
120
+ end
121
+ if inline_request?
122
+ render 'show', formats: [ :json ]
123
+ else
124
+ redirect_to users_path
125
+ end
126
+ end
127
+
128
+ ##
129
+ # GET /incline/users/1/disable
130
+ def disable_confirm
131
+ unless @disable_info.user.enabled?
132
+ flash[:warning] = "User #{@disable_info.user} is already disabled."
133
+ unless inline_request?
134
+ redirect_to users_path
135
+ end
136
+ end
137
+ end
138
+
139
+ ##
140
+ # PUT /incline/users/1/disable
141
+ def disable
142
+ if @disable_info.valid?
143
+ if @disable_info.user.disable(current_user, @disable_info.reason)
144
+ flash[:success] = "User #{@disable_info.user} has been disabled."
145
+ if inline_request?
146
+ render 'show', formats: [ :json ]
147
+ else
148
+ redirect_to users_path
149
+ end
150
+ return
151
+ else
152
+ @disable_info.errors.add(:user, 'was unable to be updated')
153
+ end
154
+ end
155
+ render 'disable_confirm'
156
+ end
157
+
158
+ ##
159
+ # PUT /incline/users/1/enable
160
+ def enable
161
+ if @user.enabled?
162
+ flash[:warning] = "User #{@user} is already enabled."
163
+ unless inline_request?
164
+ redirect_to users_path and return
165
+ end
166
+ else
167
+ if @user.enable
168
+ flash[:success] = "User #{@user} has been enabled."
169
+ else
170
+ flash[:danger] = "Failed to enable user #{@user}."
171
+ end
172
+ end
173
+ if inline_request?
174
+ render 'show', formats: [ :json ]
175
+ else
176
+ redirect_to users_path
177
+ end
178
+ end
179
+
180
+ ##
181
+ # PUT /incline/users/1/promote
182
+ def promote
183
+ # add the administrator flag to the selected user.
184
+ if @user.system_admin?
185
+ flash[:warning] = "User #{@user} is already an administrator."
186
+ unless inline_request?
187
+ redirect_to users_path and return
188
+ end
189
+ else
190
+ if @user.update(system_admin: true)
191
+ flash[:success] = "User #{@user} has been promoted to administrator."
192
+ else
193
+ flash[:danger] = "Failed to promote user #{@user}."
194
+ end
195
+ end
196
+
197
+ if inline_request?
198
+ render 'show', formats: [ :json ]
199
+ else
200
+ redirect_to users_path
201
+ end
202
+ end
203
+
204
+ ##
205
+ # PUT /incline/users/1/demote
206
+ def demote
207
+ # remove the administrator flag from the selected user.
208
+ if @user.system_admin?
209
+ if @user.update(system_admin: false)
210
+ flash[:success] = "User #{@user} has been demoted from administrator."
211
+ else
212
+ flash[:danger] = "Failed to demote user #{@user}."
213
+ end
214
+ else
215
+ flash[:warning] = "User #{@user} is not an administrator."
216
+ unless inline_request?
217
+ redirect_to users_path and return
218
+ end
219
+ end
220
+
221
+ if inline_request?
222
+ render 'show', formats: [ :json ]
223
+ else
224
+ redirect_to users_path
225
+ end
226
+
227
+ end
228
+
229
+ # POST /incline/users/1/locate
230
+ def locate
231
+ render json: { record: @dt_request.record_location }
232
+ end
233
+
234
+ # GET/POST /incline/users/api?action=...
235
+ def api
236
+ process_api_action
237
+ end
238
+
239
+ private
240
+
241
+ def set_dt_request
242
+ @dt_request = Incline::DataTablesRequest.new(params) do
243
+ (current_user.system_admin? ? Incline::User.known : Incline::User.known.enabled)
244
+ end
245
+ end
246
+
247
+ def use_layout
248
+ inline_request? ? false : nil
249
+ end
250
+
251
+ def valid_user?
252
+ # This method allows us to override the "require_admin" and "require_anon" settings for these actions.
253
+
254
+ action = params[:action].to_sym
255
+
256
+ # The current user can show or edit their own details without any further validation.
257
+ return true if [ :show, :edit, :update ].include?(action) && logged_in? && current_user?(set_user)
258
+
259
+ # A system administrator can create new users.
260
+ return true if [ :new, :create ].include?(action) && logged_in? && system_admin?
261
+
262
+ super
263
+ end
264
+
265
+ def set_user
266
+ @user ||=
267
+ if system_admin?
268
+ Incline::User.find(params[:id])
269
+ else
270
+ Incline::User.enabled.find(params[:id])
271
+ end ||
272
+ Incline::User.new(name: 'Invalid User', email: 'invalid-user')
273
+ end
274
+
275
+ def set_disable_info
276
+ @disable_info = Incline::DisableInfo.new(disable_info_params)
277
+ @disable_info.user = @user
278
+ end
279
+
280
+ def user_params(mode = :all)
281
+ ok = (mode == :all || mode == :before_create) ? [ :name, :email, :password, :password_confirmation, :recaptcha ] : [ ]
282
+
283
+ # admins can add groups to other users.
284
+ ok += [ { group_ids: [] } ] if (mode == :all || mode == :after_create) && logged_in? && system_admin? && !current_user?(set_user)
285
+
286
+ params.require(:user).permit(ok)
287
+ end
288
+
289
+ def disable_info_params
290
+ params[:disable_info] ?
291
+ params.require(:disable_info).permit(:reason) :
292
+ { }
293
+ end
294
+
295
+ def not_current
296
+ if current_user?(@user)
297
+ flash[:warning] = 'You cannot perform this operation on yourself.'
298
+ redirect_to users_path
299
+ end
300
+ end
301
+
302
+
303
+ end
304
+ end
@@ -0,0 +1,19 @@
1
+ require_dependency "incline/application_controller"
2
+
3
+ module Incline
4
+ ##
5
+ # An innocuous controller that simply hosts the home page of the application.
6
+ class WelcomeController < ApplicationController
7
+
8
+ allow_anon true
9
+
10
+ ##
11
+ # Get /incline
12
+ #
13
+ # Use +root "incline/welcome#home"+ in your +routes.rb+ file to use this, or define your own
14
+ # home page as desired.
15
+ def home
16
+
17
+ end
18
+ end
19
+ end
File without changes
@@ -0,0 +1,11 @@
1
+ module Incline
2
+ ##
3
+ # This class defines the default behavior for mailers in this application.
4
+ #
5
+ class ApplicationMailerBase < ActionMailer::Base
6
+
7
+
8
+ layout 'mailer'
9
+
10
+ end
11
+ end
@@ -0,0 +1,19 @@
1
+
2
+ module Incline
3
+ ##
4
+ # This mailer is used for the generic contact form.
5
+ class ContactForm < ::Incline::ApplicationMailerBase
6
+
7
+ ##
8
+ # Sends the message from the contact form.
9
+ def contact(msg)
10
+ @data = {
11
+ msg: msg,
12
+ client_ip: msg.remote_ip,
13
+ gems: Incline::gem_list
14
+ }
15
+ mail subject: msg.full_subject, reply_to: msg.your_email
16
+ end
17
+ end
18
+
19
+ end
@@ -0,0 +1,45 @@
1
+
2
+ module Incline
3
+
4
+ ##
5
+ # This mailer is used for the account activation, password reset, and invalid password reset messages.
6
+ #
7
+ class UserMailer < ::Incline::ApplicationMailerBase
8
+
9
+ ##
10
+ # Sends the activation email to a new user.
11
+ def account_activation(data = {})
12
+ @data = {
13
+ user: nil,
14
+ client_ip: '0.0.0.0'
15
+ }.merge(data || {})
16
+ raise unless data[:user]
17
+ mail to: data[:user].email, subject: 'Account activation'
18
+ end
19
+
20
+ ##
21
+ # Sends the password reset email to an existing user.
22
+ def password_reset(data = {})
23
+ @data = {
24
+ user: nil,
25
+ client_ip: '0.0.0.0'
26
+ }.merge(data || {})
27
+ raise unless data[:user]
28
+ mail to: data[:user].email, subject: 'Password reset request'
29
+ end
30
+
31
+ ##
32
+ # Sends an invalid password reset attempt message to a user whether they exist or not.
33
+ def invalid_password_reset(data = {})
34
+ @data = {
35
+ email: nil,
36
+ message: 'This email address is not associated with an existing account.',
37
+ client_ip: '0.0.0.0'
38
+ }.merge(data || {})
39
+ raise unless data[:email]
40
+ mail to: data[:email], subject: 'Password reset request'
41
+ end
42
+
43
+ end
44
+
45
+ end