curupira 0.1.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of curupira might be problematic. Click here for more details.

Files changed (181) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +19 -0
  3. data/.rspec +2 -0
  4. data/.travis.yml +19 -0
  5. data/Gemfile +17 -0
  6. data/Gemfile.lock +202 -0
  7. data/README.md +72 -0
  8. data/Rakefile +31 -0
  9. data/app/controllers/curupira/authorized_controller.rb +9 -0
  10. data/app/controllers/curupira/groups_controller.rb +43 -0
  11. data/app/controllers/curupira/passwords_controller.rb +46 -0
  12. data/app/controllers/curupira/roles_controller.rb +43 -0
  13. data/app/controllers/curupira/sessions_controller.rb +30 -0
  14. data/app/controllers/curupira/users_controller.rb +47 -0
  15. data/app/helpers/curupira/authorize_helper.rb +21 -0
  16. data/app/helpers/curupira/relationship_select_options_helper.rb +17 -0
  17. data/app/mailers/curupira/reset_password_mailer.rb +13 -0
  18. data/app/views/curupira/groups/_form.html.erb +28 -0
  19. data/app/views/curupira/groups/_role_group_fields.html.erb +9 -0
  20. data/app/views/curupira/groups/edit.html.erb +3 -0
  21. data/app/views/curupira/groups/index.html.erb +24 -0
  22. data/app/views/curupira/groups/new.html.erb +3 -0
  23. data/app/views/curupira/groups/show.html.erb +32 -0
  24. data/app/views/curupira/passwords/edit.html.erb +14 -0
  25. data/app/views/curupira/passwords/new.html.erb +14 -0
  26. data/app/views/curupira/reset_password_mailer/instructions.html.erb +19 -0
  27. data/app/views/curupira/reset_password_mailer/reseted.html.erb +7 -0
  28. data/app/views/curupira/roles/_authorization_fields.html.erb +10 -0
  29. data/app/views/curupira/roles/_form.html.erb +23 -0
  30. data/app/views/curupira/roles/edit.html.erb +3 -0
  31. data/app/views/curupira/roles/index.html.erb +24 -0
  32. data/app/views/curupira/roles/new.html.erb +3 -0
  33. data/app/views/curupira/roles/show.html.erb +37 -0
  34. data/app/views/curupira/sessions/new.html.erb +17 -0
  35. data/app/views/curupira/shared/_model_links.html.erb +7 -0
  36. data/app/views/curupira/shared/_session_links.html.erb +7 -0
  37. data/app/views/curupira/users/_form.html.erb +43 -0
  38. data/app/views/curupira/users/_group_user_fields.html.erb +20 -0
  39. data/app/views/curupira/users/_role_group_user_fields.html.erb +10 -0
  40. data/app/views/curupira/users/edit.html.erb +3 -0
  41. data/app/views/curupira/users/index.html.erb +28 -0
  42. data/app/views/curupira/users/new.html.erb +3 -0
  43. data/app/views/curupira/users/show.html.erb +28 -0
  44. data/curupira.gemspec +28 -0
  45. data/lib/curupira.rb +16 -0
  46. data/lib/curupira/authorizer.rb +43 -0
  47. data/lib/curupira/rails.rb +30 -0
  48. data/lib/curupira/rails/routes.rb +15 -0
  49. data/lib/curupira/version.rb +3 -0
  50. data/lib/generators/curupira/controllers/controllers_generator.rb +27 -0
  51. data/lib/generators/curupira/install/install_generator.rb +80 -0
  52. data/lib/generators/curupira/install/model_generators_helper.rb +266 -0
  53. data/lib/generators/curupira/routes/routes_generator.rb +21 -0
  54. data/lib/generators/curupira/routes/templates/routes.rb +1 -0
  55. data/lib/generators/curupira/templates/db/migrate/add_curupira_to_users.rb +20 -0
  56. data/lib/generators/curupira/templates/db/migrate/create_action_labels.rb +12 -0
  57. data/lib/generators/curupira/templates/db/migrate/create_authorizations.rb +12 -0
  58. data/lib/generators/curupira/templates/db/migrate/create_features.rb +11 -0
  59. data/lib/generators/curupira/templates/db/migrate/create_group_users.rb +13 -0
  60. data/lib/generators/curupira/templates/db/migrate/create_groups.rb +10 -0
  61. data/lib/generators/curupira/templates/db/migrate/create_role_group_users.rb +12 -0
  62. data/lib/generators/curupira/templates/db/migrate/create_role_groups.rb +13 -0
  63. data/lib/generators/curupira/templates/db/migrate/create_roles.rb +8 -0
  64. data/lib/generators/curupira/templates/db/migrate/sorcery_core.rb +27 -0
  65. data/lib/generators/curupira/templates/models/action_label.rb +2 -0
  66. data/lib/generators/curupira/templates/models/authorization.rb +2 -0
  67. data/lib/generators/curupira/templates/models/feature.rb +2 -0
  68. data/lib/generators/curupira/templates/models/feature_service.rb +4 -0
  69. data/lib/generators/curupira/templates/models/group.rb +2 -0
  70. data/lib/generators/curupira/templates/models/group_user.rb +2 -0
  71. data/lib/generators/curupira/templates/models/role.rb +2 -0
  72. data/lib/generators/curupira/templates/models/role_group.rb +2 -0
  73. data/lib/generators/curupira/templates/models/role_group_user.rb +2 -0
  74. data/lib/generators/curupira/templates/models/service.rb +2 -0
  75. data/lib/generators/curupira/templates/models/user.rb +2 -0
  76. data/lib/generators/curupira/templates/sorcery.rb +462 -0
  77. data/lib/generators/curupira/views/views_generator.rb +27 -0
  78. data/lib/tasks/curupira_tasks.rake +4 -0
  79. data/spec/app_templates/app/models/action_label.rb +2 -0
  80. data/spec/app_templates/app/models/authorization.rb +2 -0
  81. data/spec/app_templates/app/models/feature.rb +2 -0
  82. data/spec/app_templates/app/models/feature_service.rb +2 -0
  83. data/spec/app_templates/app/models/group.rb +4 -0
  84. data/spec/app_templates/app/models/group_user.rb +2 -0
  85. data/spec/app_templates/app/models/role.rb +2 -0
  86. data/spec/app_templates/app/models/role_group.rb +2 -0
  87. data/spec/app_templates/app/models/role_group_user.rb +2 -0
  88. data/spec/app_templates/app/models/service.rb +2 -0
  89. data/spec/app_templates/app/models/user.rb +2 -0
  90. data/spec/app_templates/config/routes.rb +3 -0
  91. data/spec/controllers/controller_spec.rb +40 -0
  92. data/spec/controllers/groups_controller_spec.rb +162 -0
  93. data/spec/controllers/passwords_controller_spec.rb +171 -0
  94. data/spec/controllers/roles_controller_spec.rb +168 -0
  95. data/spec/controllers/sessions_controller_spec.rb +112 -0
  96. data/spec/controllers/users_controller_spec.rb +182 -0
  97. data/spec/curupira/authorization_spec.rb +67 -0
  98. data/spec/dummy/README.rdoc +28 -0
  99. data/spec/dummy/Rakefile +6 -0
  100. data/spec/dummy/app/assets/images/.keep +0 -0
  101. data/spec/dummy/app/assets/javascripts/application.js +15 -0
  102. data/spec/dummy/app/assets/stylesheets/application.css +15 -0
  103. data/spec/dummy/app/controllers/application_controller.rb +5 -0
  104. data/spec/dummy/app/controllers/concerns/.keep +0 -0
  105. data/spec/dummy/app/controllers/home_controller.rb +4 -0
  106. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  107. data/spec/dummy/app/mailers/.keep +0 -0
  108. data/spec/dummy/app/models/.keep +0 -0
  109. data/spec/dummy/app/models/action_label.rb +3 -0
  110. data/spec/dummy/app/models/authorization.rb +4 -0
  111. data/spec/dummy/app/models/feature.rb +3 -0
  112. data/spec/dummy/app/models/group.rb +9 -0
  113. data/spec/dummy/app/models/group_user.rb +7 -0
  114. data/spec/dummy/app/models/role.rb +10 -0
  115. data/spec/dummy/app/models/role_group.rb +4 -0
  116. data/spec/dummy/app/models/role_group_user.rb +4 -0
  117. data/spec/dummy/app/models/user.rb +10 -0
  118. data/spec/dummy/app/views/home/index.html.erb +5 -0
  119. data/spec/dummy/app/views/home/test.html.erb +1 -0
  120. data/spec/dummy/app/views/layouts/application.html.erb +19 -0
  121. data/spec/dummy/bin/bundle +3 -0
  122. data/spec/dummy/bin/rails +4 -0
  123. data/spec/dummy/bin/rake +4 -0
  124. data/spec/dummy/bin/setup +29 -0
  125. data/spec/dummy/config.ru +4 -0
  126. data/spec/dummy/config/application.rb +25 -0
  127. data/spec/dummy/config/boot.rb +5 -0
  128. data/spec/dummy/config/database.yml +25 -0
  129. data/spec/dummy/config/environment.rb +5 -0
  130. data/spec/dummy/config/environments/development.rb +46 -0
  131. data/spec/dummy/config/environments/production.rb +79 -0
  132. data/spec/dummy/config/environments/test.rb +44 -0
  133. data/spec/dummy/config/initializers/assets.rb +11 -0
  134. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  135. data/spec/dummy/config/initializers/cookies_serializer.rb +3 -0
  136. data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  137. data/spec/dummy/config/initializers/inflections.rb +16 -0
  138. data/spec/dummy/config/initializers/mime_types.rb +4 -0
  139. data/spec/dummy/config/initializers/session_store.rb +3 -0
  140. data/spec/dummy/config/initializers/sorcery.rb +462 -0
  141. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  142. data/spec/dummy/config/locales/en.yml +23 -0
  143. data/spec/dummy/config/routes.rb +6 -0
  144. data/spec/dummy/config/secrets.yml +22 -0
  145. data/spec/dummy/db/migrate/20150305011941_create_role_group_users.rb +12 -0
  146. data/spec/dummy/db/migrate/20150305011942_create_authorizations.rb +12 -0
  147. data/spec/dummy/db/migrate/20150305011944_create_groups.rb +10 -0
  148. data/spec/dummy/db/migrate/20150305011945_create_roles.rb +8 -0
  149. data/spec/dummy/db/migrate/20150305011946_sorcery_core.rb +27 -0
  150. data/spec/dummy/db/migrate/20150305011947_create_group_users.rb +13 -0
  151. data/spec/dummy/db/migrate/20150305011948_create_role_groups.rb +13 -0
  152. data/spec/dummy/db/migrate/20150312181229_create_action_labels.rb +12 -0
  153. data/spec/dummy/db/migrate/20150312181747_create_features.rb +11 -0
  154. data/spec/dummy/db/schema.rb +112 -0
  155. data/spec/dummy/db/seeds.rb +137 -0
  156. data/spec/dummy/lib/assets/.keep +0 -0
  157. data/spec/dummy/log/.keep +0 -0
  158. data/spec/dummy/public/404.html +67 -0
  159. data/spec/dummy/public/422.html +67 -0
  160. data/spec/dummy/public/500.html +66 -0
  161. data/spec/dummy/public/favicon.ico +0 -0
  162. data/spec/features/link_authorize_spec.rb +25 -0
  163. data/spec/features/list_users_spec.rb +38 -0
  164. data/spec/features/log_in_spec.rb +15 -0
  165. data/spec/generators/curupira/install/action_label_spec.rb +53 -0
  166. data/spec/generators/curupira/install/authorization_generator_spec.rb +51 -0
  167. data/spec/generators/curupira/install/feature_generator_spec.rb +52 -0
  168. data/spec/generators/curupira/install/group_user_generator_spec.rb +51 -0
  169. data/spec/generators/curupira/install/install_generators_spec.rb +159 -0
  170. data/spec/generators/curupira/install/role_generator_spec.rb +38 -0
  171. data/spec/generators/curupira/install/role_group_generator_spec.rb +51 -0
  172. data/spec/generators/curupira/install/role_group_user_generator_spec.rb +52 -0
  173. data/spec/helpers/relationship_select_options_helper_spec.rb +18 -0
  174. data/spec/rails_helper.rb +55 -0
  175. data/spec/spec_helper.rb +87 -0
  176. data/spec/support/factories.rb +64 -0
  177. data/spec/support/generator_spec_helpers.rb +42 -0
  178. data/spec/support/helpers_spec.rb +23 -0
  179. data/spec/support/shared_examples/role_generator_shared_example_spec.rb +13 -0
  180. data/spec/support/sorcery.rb +4 -0
  181. metadata +539 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d98c87ceff0b90c91a113a0b4f9e76b9a653dd5a
4
+ data.tar.gz: ac0828d2f4c76b0ff16736c039238001c308d64f
5
+ SHA512:
6
+ metadata.gz: 10d5bca583f38e6f517c988c25ac5f6874762d735e00a005511d6a49669f27c13da0b52c1fe768d0dd455c26dc9386f3085d6b1ac213c31714382191431cc2ec
7
+ data.tar.gz: f0c0d4a748ddeefe1d535a26567b695cfb807df29bdec30cc4b63fbf0666a2eb8e8ddc75dd191fb5a31b7d54dc79326142a8361551f9b55eeaa3380082fc0bdc
data/.gitignore ADDED
@@ -0,0 +1,19 @@
1
+ .bundle/
2
+ log/*.log
3
+ pkg/
4
+ spec/dummy/db/*.sqlite3
5
+ spec/dummy/db/*.sqlite3-journal
6
+ spec/dummy/log/*.log
7
+ spec/dummy/tmp/
8
+ spec/dummy/.sass-cache
9
+ spec/dummy/spec/
10
+ spec/tmp/*
11
+ test/dummy/db/*.sqlite3
12
+ test/dummy/db/*.sqlite3-journal
13
+ test/dummy/log/*.log
14
+ test/dummy/tmp/
15
+ test/dummy/.sass-cache
16
+ test/tmp/*
17
+ .rvmrc
18
+ .ruby-version
19
+ .ruby-gemset
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,19 @@
1
+ language: ruby
2
+
3
+ rvm:
4
+ - 2.2
5
+
6
+ script: "bundle exec rake spec"
7
+
8
+ addons:
9
+ code_climate:
10
+ repo_token: c683c82066fc6a0297ffa32a791058ebfa2bf120fae7924192e885e9d8887d54
11
+
12
+ notifications:
13
+ email:
14
+ recipients:
15
+ - paulo.moura@prodigasistemas.com.br
16
+ - felipe.iketani@prodigasistemas.com.br
17
+ - rcasseb@prodigasistemas.com.br
18
+ - luizsanches@prodigasistemas.com.br
19
+ on_success: never
data/Gemfile ADDED
@@ -0,0 +1,17 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ group :development, :test do
6
+ gem 'byebug'
7
+ gem 'pry-rails'
8
+ end
9
+
10
+ group :test do
11
+ gem 'ammeter'
12
+ gem 'codeclimate-test-reporter', require: nil
13
+ end
14
+
15
+ platforms :ruby do
16
+ gem 'sqlite3'
17
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,202 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ curupira (0.1.0)
5
+ cocoon
6
+ jquery-rails
7
+ rails (~> 4.2.0)
8
+ sorcery
9
+
10
+ GEM
11
+ remote: https://rubygems.org/
12
+ specs:
13
+ actionmailer (4.2.0)
14
+ actionpack (= 4.2.0)
15
+ actionview (= 4.2.0)
16
+ activejob (= 4.2.0)
17
+ mail (~> 2.5, >= 2.5.4)
18
+ rails-dom-testing (~> 1.0, >= 1.0.5)
19
+ actionpack (4.2.0)
20
+ actionview (= 4.2.0)
21
+ activesupport (= 4.2.0)
22
+ rack (~> 1.6.0)
23
+ rack-test (~> 0.6.2)
24
+ rails-dom-testing (~> 1.0, >= 1.0.5)
25
+ rails-html-sanitizer (~> 1.0, >= 1.0.1)
26
+ actionview (4.2.0)
27
+ activesupport (= 4.2.0)
28
+ builder (~> 3.1)
29
+ erubis (~> 2.7.0)
30
+ rails-dom-testing (~> 1.0, >= 1.0.5)
31
+ rails-html-sanitizer (~> 1.0, >= 1.0.1)
32
+ activejob (4.2.0)
33
+ activesupport (= 4.2.0)
34
+ globalid (>= 0.3.0)
35
+ activemodel (4.2.0)
36
+ activesupport (= 4.2.0)
37
+ builder (~> 3.1)
38
+ activerecord (4.2.0)
39
+ activemodel (= 4.2.0)
40
+ activesupport (= 4.2.0)
41
+ arel (~> 6.0)
42
+ activesupport (4.2.0)
43
+ i18n (~> 0.7)
44
+ json (~> 1.7, >= 1.7.7)
45
+ minitest (~> 5.1)
46
+ thread_safe (~> 0.3, >= 0.3.4)
47
+ tzinfo (~> 1.1)
48
+ ammeter (1.1.2)
49
+ activesupport (>= 3.0)
50
+ railties (>= 3.0)
51
+ rspec-rails (>= 2.2)
52
+ arel (6.0.0)
53
+ bcrypt (3.1.10)
54
+ builder (3.2.2)
55
+ byebug (3.5.1)
56
+ columnize (~> 0.8)
57
+ debugger-linecache (~> 1.2)
58
+ slop (~> 3.6)
59
+ capybara (2.4.4)
60
+ mime-types (>= 1.16)
61
+ nokogiri (>= 1.3.3)
62
+ rack (>= 1.0.0)
63
+ rack-test (>= 0.5.4)
64
+ xpath (~> 2.0)
65
+ cocoon (1.2.6)
66
+ codeclimate-test-reporter (0.4.7)
67
+ simplecov (>= 0.7.1, < 1.0.0)
68
+ coderay (1.1.0)
69
+ columnize (0.9.0)
70
+ debugger-linecache (1.2.0)
71
+ diff-lcs (1.2.5)
72
+ docile (1.1.5)
73
+ erubis (2.7.0)
74
+ factory_girl (4.5.0)
75
+ activesupport (>= 3.0.0)
76
+ factory_girl_rails (4.5.0)
77
+ factory_girl (~> 4.5.0)
78
+ railties (>= 3.0.0)
79
+ faraday (0.9.1)
80
+ multipart-post (>= 1.2, < 3)
81
+ globalid (0.3.3)
82
+ activesupport (>= 4.1.0)
83
+ hike (1.2.3)
84
+ i18n (0.7.0)
85
+ jquery-rails (4.0.3)
86
+ rails-dom-testing (~> 1.0)
87
+ railties (>= 4.2.0)
88
+ thor (>= 0.14, < 2.0)
89
+ json (1.8.2)
90
+ jwt (1.4.1)
91
+ loofah (2.0.1)
92
+ nokogiri (>= 1.5.9)
93
+ mail (2.6.3)
94
+ mime-types (>= 1.16, < 3)
95
+ method_source (0.8.2)
96
+ mime-types (2.4.3)
97
+ mini_portile (0.6.2)
98
+ minitest (5.5.1)
99
+ multi_json (1.10.1)
100
+ multi_xml (0.5.5)
101
+ multipart-post (2.0.0)
102
+ nokogiri (1.6.6.2)
103
+ mini_portile (~> 0.6.0)
104
+ oauth (0.4.7)
105
+ oauth2 (1.0.0)
106
+ faraday (>= 0.8, < 0.10)
107
+ jwt (~> 1.0)
108
+ multi_json (~> 1.3)
109
+ multi_xml (~> 0.5)
110
+ rack (~> 1.2)
111
+ pry (0.10.1)
112
+ coderay (~> 1.1.0)
113
+ method_source (~> 0.8.1)
114
+ slop (~> 3.4)
115
+ pry-rails (0.3.3)
116
+ pry (>= 0.9.10)
117
+ rack (1.6.0)
118
+ rack-test (0.6.3)
119
+ rack (>= 1.0)
120
+ rails (4.2.0)
121
+ actionmailer (= 4.2.0)
122
+ actionpack (= 4.2.0)
123
+ actionview (= 4.2.0)
124
+ activejob (= 4.2.0)
125
+ activemodel (= 4.2.0)
126
+ activerecord (= 4.2.0)
127
+ activesupport (= 4.2.0)
128
+ bundler (>= 1.3.0, < 2.0)
129
+ railties (= 4.2.0)
130
+ sprockets-rails
131
+ rails-deprecated_sanitizer (1.0.3)
132
+ activesupport (>= 4.2.0.alpha)
133
+ rails-dom-testing (1.0.5)
134
+ activesupport (>= 4.2.0.beta, < 5.0)
135
+ nokogiri (~> 1.6.0)
136
+ rails-deprecated_sanitizer (>= 1.0.1)
137
+ rails-html-sanitizer (1.0.1)
138
+ loofah (~> 2.0)
139
+ railties (4.2.0)
140
+ actionpack (= 4.2.0)
141
+ activesupport (= 4.2.0)
142
+ rake (>= 0.8.7)
143
+ thor (>= 0.18.1, < 2.0)
144
+ rake (10.4.2)
145
+ rspec-core (3.2.1)
146
+ rspec-support (~> 3.2.0)
147
+ rspec-expectations (3.2.0)
148
+ diff-lcs (>= 1.2.0, < 2.0)
149
+ rspec-support (~> 3.2.0)
150
+ rspec-mocks (3.2.1)
151
+ diff-lcs (>= 1.2.0, < 2.0)
152
+ rspec-support (~> 3.2.0)
153
+ rspec-rails (3.2.1)
154
+ actionpack (>= 3.0, < 4.3)
155
+ activesupport (>= 3.0, < 4.3)
156
+ railties (>= 3.0, < 4.3)
157
+ rspec-core (~> 3.2.0)
158
+ rspec-expectations (~> 3.2.0)
159
+ rspec-mocks (~> 3.2.0)
160
+ rspec-support (~> 3.2.0)
161
+ rspec-support (3.2.2)
162
+ simplecov (0.9.2)
163
+ docile (~> 1.1.0)
164
+ multi_json (~> 1.0)
165
+ simplecov-html (~> 0.9.0)
166
+ simplecov-html (0.9.0)
167
+ slop (3.6.0)
168
+ sorcery (0.9.0)
169
+ bcrypt (~> 3.1)
170
+ oauth (~> 0.4, >= 0.4.4)
171
+ oauth2 (>= 0.8.0)
172
+ sprockets (2.12.3)
173
+ hike (~> 1.2)
174
+ multi_json (~> 1.0)
175
+ rack (~> 1.0)
176
+ tilt (~> 1.1, != 1.3.0)
177
+ sprockets-rails (2.2.4)
178
+ actionpack (>= 3.0)
179
+ activesupport (>= 3.0)
180
+ sprockets (>= 2.8, < 4.0)
181
+ sqlite3 (1.3.10)
182
+ thor (0.19.1)
183
+ thread_safe (0.3.4)
184
+ tilt (1.4.1)
185
+ tzinfo (1.2.2)
186
+ thread_safe (~> 0.1)
187
+ xpath (2.0.0)
188
+ nokogiri (~> 1.3)
189
+
190
+ PLATFORMS
191
+ ruby
192
+
193
+ DEPENDENCIES
194
+ ammeter
195
+ byebug
196
+ capybara
197
+ codeclimate-test-reporter
198
+ curupira!
199
+ factory_girl_rails
200
+ pry-rails
201
+ rspec-rails
202
+ sqlite3
data/README.md ADDED
@@ -0,0 +1,72 @@
1
+ # curupira
2
+ Easy way to authentication and authorization for ActiveRecord based on Sorcery. Curupira will help you quickly develop an application that uses authentication and authorization rules with database.
3
+
4
+ By [Pródiga Sistemas](http://www.prodigasistemas.com.br/).
5
+
6
+ [![Build Status](https://travis-ci.org/prodigasistemas/curupira.svg?branch=master)](https://travis-ci.org/prodigasistemas/curupira)
7
+ [![Code Climate](https://codeclimate.com/github/prodigasistemas/curupira/badges/gpa.svg)](https://codeclimate.com/github/prodigasistemas/curupira)
8
+ [![Test Coverage](https://codeclimate.com/github/prodigasistemas/curupira/badges/coverage.svg)](https://codeclimate.com/github/prodigasistemas/curupira)
9
+
10
+ ## Getting started
11
+
12
+ Curupira works with rails 4.0 or onwards. Add curupira to your Gemfile:
13
+
14
+ ```ruby
15
+ gem 'curupira'
16
+ ```
17
+
18
+ And run:
19
+
20
+ ```console
21
+ bundle install
22
+ ```
23
+
24
+ ## Rails Configuration
25
+
26
+ ```console
27
+ rails generate curupira:install
28
+ ```
29
+
30
+ The generator will install an initializer which describes ALL of Sorcery's configuration options, models and migrations for authentication and authorization solution.
31
+
32
+ ## Controller filters and helpers
33
+
34
+ Curupira will provide some helpers to use inside controllers and views. To setup controller with user authentication, just this add before_action:
35
+
36
+ ```ruby
37
+ before_action :require_login
38
+ ```
39
+
40
+ Curupira will provide all features and [Sorcery api](https://github.com/NoamB/sorcery).
41
+
42
+ To authorization, add filter authorize on ApplicationController.
43
+
44
+ ```ruby
45
+ before_action :authorize
46
+ ```
47
+
48
+ ## Configuring views
49
+
50
+ Curupira will generate views to add users, roles, groups and features in database. You can customize it.
51
+
52
+ ```console
53
+ rails generate curupira:views
54
+ ```
55
+
56
+ For dafault, the curupira views use coccon for nested forms.
57
+
58
+ ## Configuring controllers
59
+
60
+ If the customization at the views level is not enough, you can customize each controller:
61
+
62
+ ```console
63
+ rails generate curupira:controllers
64
+ ```
65
+
66
+ * Add to your application.js
67
+ //= require jquery
68
+ //= require cocoon
69
+
70
+ ## License
71
+
72
+ Curupira is released under the [MIT License](http://www.opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,31 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ APP_RAKEFILE = File.expand_path("../spec/dummy/Rakefile", __FILE__)
8
+ load 'rails/tasks/engine.rake'
9
+
10
+
11
+ Bundler::GemHelper.install_tasks
12
+
13
+
14
+ Dir[File.join(File.dirname(__FILE__), 'tasks/**/*.rake')].each {|f| load f }
15
+
16
+ require 'rspec/core'
17
+ require 'rspec/core/rake_task'
18
+
19
+ desc "Run all specs in spec directory (excluding plugin specs)"
20
+ RSpec::Core::RakeTask.new(:spec => 'app:db:test:prepare')
21
+
22
+ require 'rake/testtask'
23
+
24
+ Rake::TestTask.new(:test) do |t|
25
+ t.libs << 'lib'
26
+ t.libs << 'test'
27
+ t.pattern = 'test/**/*_test.rb'
28
+ t.verbose = false
29
+ end
30
+
31
+ task :default => :spec
@@ -0,0 +1,9 @@
1
+ class Curupira::AuthorizedController < ApplicationController
2
+ before_filter :require_login
3
+
4
+ private
5
+
6
+ def not_authenticated
7
+ redirect_to new_session_path, alert: "Por favor, se autentique primeiro"
8
+ end
9
+ end
@@ -0,0 +1,43 @@
1
+ class Curupira::GroupsController < Curupira::AuthorizedController
2
+ def index
3
+ @groups = Group.all
4
+ end
5
+
6
+ def show
7
+ @group = Group.find(params[:id])
8
+ end
9
+
10
+ def new
11
+ @group = Group.new
12
+ end
13
+
14
+ def edit
15
+ @group = Group.find(params[:id])
16
+ end
17
+
18
+ def create
19
+ @group = Group.new(group_params)
20
+
21
+ if @group.save
22
+ redirect_to @group, notice: "Grupo criado com sucesso"
23
+ else
24
+ render :new
25
+ end
26
+ end
27
+
28
+ def update
29
+ @group = Group.find(params[:id])
30
+
31
+ if @group.update group_params
32
+ redirect_to @group, notice: "Grupo atualizado com sucesso"
33
+ else
34
+ render :edit
35
+ end
36
+ end
37
+
38
+ private
39
+
40
+ def group_params
41
+ params.require(:group).permit(:name, :active, role_groups_attributes: [:id, :role_id, :_destroy])
42
+ end
43
+ end
@@ -0,0 +1,46 @@
1
+ class Curupira::PasswordsController < ApplicationController
2
+ before_filter :redirect_to_root_with_errors, if: :current_user
3
+
4
+ def new
5
+ @user = User.new
6
+ end
7
+
8
+ def create
9
+ @user = User.find_by(params[:user])
10
+ if @user.present?
11
+ @user.deliver_reset_password_instructions!
12
+ redirect_to new_session_path, notice: "Verifique seu email para receber instruções de recuperação de senha"
13
+ else
14
+ @user = User.new email: params[:user][:email]
15
+ flash[:alert] = "Email não encontrado"
16
+ render :new
17
+ end
18
+ end
19
+
20
+ def edit
21
+ @user = User.load_from_reset_password_token(params[:id])
22
+ if @user.present?
23
+ render :edit
24
+ else
25
+ redirect_to new_session_path, alert: "Token para resetar senha expirado ou inválido"
26
+ end
27
+ end
28
+
29
+ def update
30
+ @user = User.load_from_reset_password_token(params[:id])
31
+
32
+ if @user
33
+ @user.change_password!(params[:user][:password])
34
+ Curupira::ResetPasswordMailer.reseted(@user).deliver_now
35
+ redirect_to new_session_path, notice: "Senha atualizada com sucesso. Entre com sua nova senha"
36
+ else
37
+ redirect_to new_session_path, alert: "Token para resetar senha expirado ou inválido"
38
+ end
39
+ end
40
+
41
+ private
42
+
43
+ def redirect_to_root_with_errors
44
+ redirect_to root_path, alert: "Você já está logado"
45
+ end
46
+ end