arcadex 1.1.3 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (201) hide show
  1. checksums.yaml +4 -4
  2. data/db/migrate/20141020173616_add_max_uses_to_arcadex_tokens.rb +5 -0
  3. data/lib/arcadex/authentication.rb +45 -51
  4. data/lib/arcadex/create.rb +2 -1
  5. data/lib/arcadex/header.rb +8 -21
  6. data/lib/arcadex/version.rb +1 -1
  7. data/test/dummy/db/development.sqlite3 +0 -0
  8. data/test/dummy/db/schema.rb +2 -1
  9. data/test/dummy/db/test.sqlite3 +0 -0
  10. data/test/dummy/log/development.log +15 -0
  11. data/test/dummy/log/test.log +35 -0
  12. data/test/test_app/Gemfile +77 -0
  13. data/test/test_app/Gemfile.lock +281 -0
  14. data/test/test_app/README.md +1 -0
  15. data/test/test_app/Rakefile +6 -0
  16. data/test/test_app/app/admin/arcadex_token.rb +94 -0
  17. data/test/test_app/app/admin/dashboard.rb +69 -0
  18. data/test/test_app/app/admin/defcon_admin_user.rb +99 -0
  19. data/test/test_app/app/admin/people_user.rb +83 -0
  20. data/test/test_app/app/assets/javascripts/active_admin.js.coffee +1 -0
  21. data/test/test_app/app/assets/javascripts/application.js +16 -0
  22. data/test/test_app/app/assets/stylesheets/active_admin.css.scss +17 -0
  23. data/test/test_app/app/assets/stylesheets/application.css +13 -0
  24. data/test/test_app/app/controllers/api/v1/api_controller.rb +71 -0
  25. data/test/test_app/app/controllers/app_index_controller.rb +4 -0
  26. data/test/test_app/app/controllers/application_controller.rb +21 -0
  27. data/test/test_app/app/helpers/application_helper.rb +2 -0
  28. data/test/test_app/app/views/app_index/app.html.erb +0 -0
  29. data/test/test_app/app/views/layouts/app_index.html.erb +9 -0
  30. data/test/test_app/app/views/layouts/application.html.erb +14 -0
  31. data/test/test_app/bin/bundle +3 -0
  32. data/test/test_app/bin/rails +4 -0
  33. data/test/test_app/bin/rake +4 -0
  34. data/test/test_app/config.ru +4 -0
  35. data/test/test_app/config/application.rb +27 -0
  36. data/test/test_app/config/boot.rb +4 -0
  37. data/test/test_app/config/database.yml +25 -0
  38. data/test/test_app/config/environment.rb +5 -0
  39. data/test/test_app/config/environments/development.rb +29 -0
  40. data/test/test_app/config/environments/production.rb +80 -0
  41. data/test/test_app/config/environments/test.rb +36 -0
  42. data/test/test_app/config/initializers/active_admin.rb +252 -0
  43. data/test/test_app/config/initializers/backtrace_silencers.rb +7 -0
  44. data/test/test_app/config/initializers/filter_parameter_logging.rb +4 -0
  45. data/test/test_app/config/initializers/inflections.rb +16 -0
  46. data/test/test_app/config/initializers/mime_types.rb +5 -0
  47. data/test/test_app/config/initializers/secret_token.rb +12 -0
  48. data/test/test_app/config/initializers/session_store.rb +3 -0
  49. data/test/test_app/config/initializers/wrap_parameters.rb +14 -0
  50. data/test/test_app/config/locales/en.yml +23 -0
  51. data/test/test_app/config/routes.rb +66 -0
  52. data/test/test_app/config/schedule.rb +20 -0
  53. data/test/test_app/db/development.sqlite3 +0 -0
  54. data/test/test_app/db/migrate/20141016225515_create_active_admin_comments.rb +19 -0
  55. data/test/test_app/db/migrate/20141016225555_create_people_users.people.rb +14 -0
  56. data/test/test_app/db/migrate/20141016225556_create_arcadex_tokens.arcadex.rb +12 -0
  57. data/test/test_app/db/migrate/20141016225557_add_index_to_token.arcadex.rb +6 -0
  58. data/test/test_app/db/migrate/20141016225558_add_first_ip_address_to_arcadex_tokens.arcadex.rb +6 -0
  59. data/test/test_app/db/migrate/20141016225559_add_current_ip_address_to_arcadex_tokens.arcadex.rb +6 -0
  60. data/test/test_app/db/migrate/20141016225560_add_times_used_to_arcadex_tokens.arcadex.rb +6 -0
  61. data/test/test_app/db/migrate/20141016225561_add_expiration_minutes_to_arcadex_tokens.arcadex.rb +6 -0
  62. data/test/test_app/db/migrate/20141016225562_create_defcon_admin_users.defcon.rb +16 -0
  63. data/test/test_app/db/migrate/20141016225563_add_index_to_defcon_admin_users.defcon.rb +6 -0
  64. data/test/test_app/db/migrate/20141016225564_add_email_to_defcon_admin_users.defcon.rb +7 -0
  65. data/test/test_app/db/migrate/20141020173805_add_max_uses_to_arcadex_tokens.arcadex.rb +6 -0
  66. data/test/test_app/db/production.sqlite3 +0 -0
  67. data/test/test_app/db/schema.rb +73 -0
  68. data/test/test_app/db/seeds.rb +10 -0
  69. data/test/test_app/db/test.sqlite3 +0 -0
  70. data/test/test_app/engines/people/Gemfile +14 -0
  71. data/test/test_app/engines/people/Gemfile.lock +81 -0
  72. data/test/test_app/engines/people/MIT-LICENSE +20 -0
  73. data/test/test_app/engines/people/README.md +1 -0
  74. data/test/test_app/engines/people/Rakefile +34 -0
  75. data/test/test_app/engines/people/app/assets/javascripts/people/application.js +13 -0
  76. data/test/test_app/engines/people/app/assets/javascripts/people/users.js +2 -0
  77. data/test/test_app/engines/people/app/assets/stylesheets/people/application.css +13 -0
  78. data/test/test_app/engines/people/app/assets/stylesheets/people/users.css +4 -0
  79. data/test/test_app/engines/people/app/assets/stylesheets/scaffold.css +56 -0
  80. data/test/test_app/engines/people/app/controllers/people/api/v1/application_controller.rb +5 -0
  81. data/test/test_app/engines/people/app/controllers/people/api/v1/users_controller.rb +169 -0
  82. data/test/test_app/engines/people/app/controllers/people/application_controller.rb +4 -0
  83. data/test/test_app/engines/people/app/controllers/people/users_controller.rb +62 -0
  84. data/test/test_app/engines/people/app/helpers/people/application_helper.rb +4 -0
  85. data/test/test_app/engines/people/app/helpers/people/users_helper.rb +4 -0
  86. data/test/test_app/engines/people/app/models/people/user.rb +9 -0
  87. data/test/test_app/engines/people/app/models/people/v1/user.rb +32 -0
  88. data/test/test_app/engines/people/app/serializers/people/v1/user_serializer.rb +43 -0
  89. data/test/test_app/engines/people/app/views/layouts/people/default/application.html.erb +14 -0
  90. data/test/test_app/engines/people/app/views/people/users/_form.html.erb +29 -0
  91. data/test/test_app/engines/people/app/views/people/users/edit.html.erb +6 -0
  92. data/test/test_app/engines/people/app/views/people/users/index.html.erb +31 -0
  93. data/test/test_app/engines/people/app/views/people/users/new.html.erb +5 -0
  94. data/test/test_app/engines/people/app/views/people/users/show.html.erb +19 -0
  95. data/test/test_app/engines/people/bin/rails +12 -0
  96. data/test/test_app/engines/people/config/routes.rb +28 -0
  97. data/test/test_app/engines/people/db/migrate/20141016225548_create_people_users.rb +13 -0
  98. data/test/test_app/engines/people/lib/people.rb +4 -0
  99. data/test/test_app/engines/people/lib/people/engine.rb +5 -0
  100. data/test/test_app/engines/people/lib/people/version.rb +3 -0
  101. data/test/test_app/engines/people/lib/tasks/people_tasks.rake +4 -0
  102. data/test/test_app/engines/people/people.gemspec +33 -0
  103. data/test/test_app/engines/people/test/controllers/people/users_controller_test.rb +51 -0
  104. data/test/test_app/engines/people/test/dummy/README.rdoc +28 -0
  105. data/test/test_app/engines/people/test/dummy/Rakefile +6 -0
  106. data/test/test_app/engines/people/test/dummy/app/assets/javascripts/application.js +13 -0
  107. data/test/test_app/engines/people/test/dummy/app/assets/stylesheets/application.css +13 -0
  108. data/test/test_app/engines/people/test/dummy/app/controllers/application_controller.rb +5 -0
  109. data/test/test_app/engines/people/test/dummy/app/helpers/application_helper.rb +2 -0
  110. data/test/test_app/engines/people/test/dummy/app/views/layouts/application.html.erb +14 -0
  111. data/test/test_app/engines/people/test/dummy/bin/bundle +3 -0
  112. data/test/test_app/engines/people/test/dummy/bin/rails +4 -0
  113. data/test/test_app/engines/people/test/dummy/bin/rake +4 -0
  114. data/test/test_app/engines/people/test/dummy/config.ru +4 -0
  115. data/test/test_app/engines/people/test/dummy/config/application.rb +23 -0
  116. data/test/test_app/engines/people/test/dummy/config/boot.rb +5 -0
  117. data/test/test_app/engines/people/test/dummy/config/database.yml +25 -0
  118. data/test/test_app/engines/people/test/dummy/config/environment.rb +5 -0
  119. data/test/test_app/engines/people/test/dummy/config/environments/development.rb +29 -0
  120. data/test/test_app/engines/people/test/dummy/config/environments/production.rb +80 -0
  121. data/test/test_app/engines/people/test/dummy/config/environments/test.rb +36 -0
  122. data/test/test_app/engines/people/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  123. data/test/test_app/engines/people/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  124. data/test/test_app/engines/people/test/dummy/config/initializers/inflections.rb +16 -0
  125. data/test/test_app/engines/people/test/dummy/config/initializers/mime_types.rb +5 -0
  126. data/test/test_app/engines/people/test/dummy/config/initializers/secret_token.rb +12 -0
  127. data/test/test_app/engines/people/test/dummy/config/initializers/session_store.rb +3 -0
  128. data/test/test_app/engines/people/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  129. data/test/test_app/engines/people/test/dummy/config/locales/en.yml +23 -0
  130. data/test/test_app/engines/people/test/dummy/config/routes.rb +4 -0
  131. data/test/test_app/engines/people/test/dummy/public/404.html +58 -0
  132. data/test/test_app/engines/people/test/dummy/public/422.html +58 -0
  133. data/test/test_app/engines/people/test/dummy/public/500.html +57 -0
  134. data/test/test_app/engines/people/test/dummy/public/favicon.ico +0 -0
  135. data/test/test_app/engines/people/test/fixtures/people/users.yml +11 -0
  136. data/test/test_app/engines/people/test/helpers/people/users_helper_test.rb +6 -0
  137. data/test/test_app/engines/people/test/integration/navigation_test.rb +10 -0
  138. data/test/test_app/engines/people/test/models/people/user_test.rb +9 -0
  139. data/test/test_app/engines/people/test/people_test.rb +7 -0
  140. data/test/test_app/engines/people/test/test_helper.rb +15 -0
  141. data/test/test_app/gems/authorization/Gemfile +14 -0
  142. data/test/test_app/gems/authorization/Gemfile.lock +81 -0
  143. data/test/test_app/gems/authorization/MIT-LICENSE +20 -0
  144. data/test/test_app/gems/authorization/README.rdoc +3 -0
  145. data/test/test_app/gems/authorization/Rakefile +32 -0
  146. data/test/test_app/gems/authorization/authorization.gemspec +22 -0
  147. data/test/test_app/gems/authorization/lib/authorization.rb +4 -0
  148. data/test/test_app/gems/authorization/lib/authorization/people/v1/user.rb +90 -0
  149. data/test/test_app/gems/authorization/lib/authorization/version.rb +3 -0
  150. data/test/test_app/gems/authorization/lib/tasks/authorization_tasks.rake +4 -0
  151. data/test/test_app/gems/authorization/test/authorization_test.rb +7 -0
  152. data/test/test_app/gems/authorization/test/dummy/README.rdoc +28 -0
  153. data/test/test_app/gems/authorization/test/dummy/Rakefile +6 -0
  154. data/test/test_app/gems/authorization/test/dummy/app/assets/javascripts/application.js +13 -0
  155. data/test/test_app/gems/authorization/test/dummy/app/assets/stylesheets/application.css +13 -0
  156. data/test/test_app/gems/authorization/test/dummy/app/controllers/application_controller.rb +5 -0
  157. data/test/test_app/gems/authorization/test/dummy/app/helpers/application_helper.rb +2 -0
  158. data/test/test_app/gems/authorization/test/dummy/app/views/layouts/application.html.erb +14 -0
  159. data/test/test_app/gems/authorization/test/dummy/bin/bundle +3 -0
  160. data/test/test_app/gems/authorization/test/dummy/bin/rails +4 -0
  161. data/test/test_app/gems/authorization/test/dummy/bin/rake +4 -0
  162. data/test/test_app/gems/authorization/test/dummy/config.ru +4 -0
  163. data/test/test_app/gems/authorization/test/dummy/config/application.rb +23 -0
  164. data/test/test_app/gems/authorization/test/dummy/config/boot.rb +5 -0
  165. data/test/test_app/gems/authorization/test/dummy/config/database.yml +25 -0
  166. data/test/test_app/gems/authorization/test/dummy/config/environment.rb +5 -0
  167. data/test/test_app/gems/authorization/test/dummy/config/environments/development.rb +29 -0
  168. data/test/test_app/gems/authorization/test/dummy/config/environments/production.rb +80 -0
  169. data/test/test_app/gems/authorization/test/dummy/config/environments/test.rb +36 -0
  170. data/test/test_app/gems/authorization/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  171. data/test/test_app/gems/authorization/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  172. data/test/test_app/gems/authorization/test/dummy/config/initializers/inflections.rb +16 -0
  173. data/test/test_app/gems/authorization/test/dummy/config/initializers/mime_types.rb +5 -0
  174. data/test/test_app/gems/authorization/test/dummy/config/initializers/secret_token.rb +12 -0
  175. data/test/test_app/gems/authorization/test/dummy/config/initializers/session_store.rb +3 -0
  176. data/test/test_app/gems/authorization/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  177. data/test/test_app/gems/authorization/test/dummy/config/locales/en.yml +23 -0
  178. data/test/test_app/gems/authorization/test/dummy/config/routes.rb +56 -0
  179. data/test/test_app/gems/authorization/test/dummy/public/404.html +58 -0
  180. data/test/test_app/gems/authorization/test/dummy/public/422.html +58 -0
  181. data/test/test_app/gems/authorization/test/dummy/public/500.html +57 -0
  182. data/test/test_app/gems/authorization/test/dummy/public/favicon.ico +0 -0
  183. data/test/test_app/gems/authorization/test/test_helper.rb +15 -0
  184. data/test/test_app/log/development.log +79 -0
  185. data/test/test_app/log/production.log +12 -0
  186. data/test/test_app/log/test.log +13884 -0
  187. data/test/test_app/public/404.html +58 -0
  188. data/test/test_app/public/422.html +58 -0
  189. data/test/test_app/public/500.html +57 -0
  190. data/test/test_app/public/favicon.ico +0 -0
  191. data/test/test_app/public/robots.txt +5 -0
  192. data/test/test_app/spec/controllers/app_index_controller_spec.rb +12 -0
  193. data/test/test_app/spec/engines/people/api/v1/models/user_spec.rb +61 -0
  194. data/test/test_app/spec/engines/people/api/v1/requests/user_spec.rb +244 -0
  195. data/test/test_app/spec/engines/people/api/v1/routing/user_spec.rb +91 -0
  196. data/test/test_app/spec/factories/people_user_1_factory.rb +14 -0
  197. data/test/test_app/spec/rails_helper.rb +47 -0
  198. data/test/test_app/spec/spec_helper.rb +78 -0
  199. data/test/test_app/spec/support/factory_girl.rb +16 -0
  200. data/test/test_app/spec/support/request_helpers.rb +7 -0
  201. metadata +381 -2
@@ -0,0 +1,20 @@
1
+ Copyright 2014 YOURNAME
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1 @@
1
+ # Describe your engine here
@@ -0,0 +1,34 @@
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
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'People'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.rdoc')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+ APP_RAKEFILE = File.expand_path("../test/dummy/Rakefile", __FILE__)
18
+ load 'rails/tasks/engine.rake'
19
+
20
+
21
+
22
+ Bundler::GemHelper.install_tasks
23
+
24
+ require 'rake/testtask'
25
+
26
+ Rake::TestTask.new(:test) do |t|
27
+ t.libs << 'lib'
28
+ t.libs << 'test'
29
+ t.pattern = 'test/**/*_test.rb'
30
+ t.verbose = false
31
+ end
32
+
33
+
34
+ task default: :test
@@ -0,0 +1,13 @@
1
+ // This is a manifest file that'll be compiled into application.js, which will include all the files
2
+ // listed below.
3
+ //
4
+ // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5
+ // or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
6
+ //
7
+ // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
+ // compiled file.
9
+ //
10
+ // Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details
11
+ // about supported directives.
12
+ //
13
+ //= require_tree .
@@ -0,0 +1,2 @@
1
+ // Place all the behaviors and hooks related to the matching controller here.
2
+ // All this logic will automatically be available in application.js.
@@ -0,0 +1,13 @@
1
+ /*
2
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
3
+ * listed below.
4
+ *
5
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
+ * or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
7
+ *
8
+ * You're free to add application-wide styles to this file and they'll appear at the top of the
9
+ * compiled file, but it's generally better to create a new file per style scope.
10
+ *
11
+ *= require_self
12
+ *= require_tree .
13
+ */
@@ -0,0 +1,4 @@
1
+ /*
2
+ Place all the styles related to the matching controller here.
3
+ They will automatically be included in application.css.
4
+ */
@@ -0,0 +1,56 @@
1
+ body { background-color: #fff; color: #333; }
2
+
3
+ body, p, ol, ul, td {
4
+ font-family: verdana, arial, helvetica, sans-serif;
5
+ font-size: 13px;
6
+ line-height: 18px;
7
+ }
8
+
9
+ pre {
10
+ background-color: #eee;
11
+ padding: 10px;
12
+ font-size: 11px;
13
+ }
14
+
15
+ a { color: #000; }
16
+ a:visited { color: #666; }
17
+ a:hover { color: #fff; background-color:#000; }
18
+
19
+ div.field, div.actions {
20
+ margin-bottom: 10px;
21
+ }
22
+
23
+ #notice {
24
+ color: green;
25
+ }
26
+
27
+ .field_with_errors {
28
+ padding: 2px;
29
+ background-color: red;
30
+ display: table;
31
+ }
32
+
33
+ #error_explanation {
34
+ width: 450px;
35
+ border: 2px solid red;
36
+ padding: 7px;
37
+ padding-bottom: 0;
38
+ margin-bottom: 20px;
39
+ background-color: #f0f0f0;
40
+ }
41
+
42
+ #error_explanation h2 {
43
+ text-align: left;
44
+ font-weight: bold;
45
+ padding: 5px 5px 5px 15px;
46
+ font-size: 12px;
47
+ margin: -7px;
48
+ margin-bottom: 0px;
49
+ background-color: #c00;
50
+ color: #fff;
51
+ }
52
+
53
+ #error_explanation ul li {
54
+ font-size: 12px;
55
+ list-style: square;
56
+ }
@@ -0,0 +1,5 @@
1
+ module People
2
+ class Api::V1::ApplicationController < ::Api::V1::ApiController
3
+
4
+ end
5
+ end
@@ -0,0 +1,169 @@
1
+ require_dependency "people/api/v1/application_controller"
2
+ require 'authorization'
3
+
4
+ module People
5
+ class Api::V1::UsersController < Api::V1::ApplicationController
6
+
7
+ skip_before_filter :authenticate_user, :only => [:register, :login]
8
+
9
+ before_action :set_user, only: [:show, :edit, :update, :authenticate]
10
+ before_action :register_authorize, only: [:register]
11
+ before_action :login_authorize, only: [:login]
12
+ before_action :logout_authorize, only: [:logout]
13
+ before_action :index_authorize, only: [:index]
14
+ before_action :show_authorize, only: [:show]
15
+ before_action :update_authorize, only: [:update]
16
+
17
+
18
+ # POST /api/1/users/register
19
+ def register
20
+ #Create a new user
21
+ user = ::People::V1::User.new(user_params)
22
+ if user.save
23
+ #If the user is saved, return a token
24
+ token = user.tokens[0]
25
+ ::Arcadex::Create.set_token(token,360,request,nil)
26
+ userHash = {id: user.id, username: user.username, email: user.email}
27
+ tokenHash = {auth_token: token.auth_token}
28
+ render :json => {user: userHash,token: tokenHash}
29
+ else
30
+ #Return an error if not saved
31
+ render :json => {errors: user.errors.full_messages}, status: :unprocessable_entity
32
+ end
33
+ end
34
+
35
+ # POST /api/1/users/login
36
+ def login
37
+ #Should I delete the current token or ignore it?
38
+ #Find user from email and password. Create and return a new token
39
+ user = ::People::V1::User.find_by(email: get_email)
40
+ if user && user.authenticate(params[:user][:password])
41
+ token = user.tokens.create
42
+ ::Arcadex::Create.set_token(token,360,request,nil)
43
+ userHash = {id: user.id, username: user.username, email: user.email}
44
+ tokenHash = {auth_token: token.auth_token}
45
+ render :json => {user: userHash,token: tokenHash}
46
+ else
47
+ render :json => {errors: "Email and/or Password is incorrect"}, status: :unauthorized
48
+ end
49
+ end
50
+
51
+ # POST /api/1/users/logout
52
+ def logout
53
+ #Destroy the current token
54
+ token = current_token
55
+ token.destroy
56
+ render json: {}
57
+ end
58
+
59
+ # GET /api/1/users/login_status
60
+ def login_status
61
+ # Will give an unauthorized if not logged in
62
+ render json: {}
63
+ end
64
+
65
+
66
+ # POST /api/1/users/authenticate
67
+ def authenticate
68
+ if user_authenticate_password
69
+ return
70
+ end
71
+ render json: {}
72
+ end
73
+
74
+ # GET /api/1/users
75
+ def index
76
+ @users = ::People::V1::User.all
77
+ render json: @users
78
+ end
79
+
80
+ # GET /api/1/users/1
81
+ def show
82
+ render json: @user
83
+ end
84
+
85
+ # PATCH/PUT /api/1/users/1
86
+ def update
87
+ if user_authenticate_password
88
+ return
89
+ end
90
+ if @user.update(user_params)
91
+ render json: @user
92
+ else
93
+ render :json => {errors: @user.errors.full_messages}, status: :unprocessable_entity
94
+ end
95
+ end
96
+
97
+ private
98
+ # Use callbacks to share common setup or constraints between actions.
99
+
100
+ def user_authenticate_password
101
+ if authenticate_password
102
+ render :json => {errors: "Email and/or Password is incorrect"}, status: :unauthorized
103
+ return true
104
+ end
105
+ return false
106
+ end
107
+
108
+ def get_email
109
+ if !params[:user][:email].nil?
110
+ return params[:user][:email].downcase
111
+ else
112
+ return nil
113
+ end
114
+ end
115
+
116
+ def set_user
117
+ @user = ::People::V1::User.find_by_id(params[:id])
118
+ if @user.nil?
119
+ render :json => {errors: "User was not found"}, status: :not_found
120
+ end
121
+ end
122
+
123
+ # Only allow a trusted parameter "white list" through.
124
+
125
+ def user_params
126
+ params.require(:user).permit(:username, :email, :password, :password_confirmation)
127
+ end
128
+
129
+ # Authorizations below here
130
+
131
+
132
+ def register_authorize
133
+ if !::Authorization::People::V1::User.register?
134
+ render :json => {errors: "User is not authorized for this action"}, status: :forbidden
135
+ end
136
+ end
137
+
138
+ def login_authorize
139
+ if !::Authorization::People::V1::User.login?
140
+ render :json => {errors: "User is not authorized for this action"}, status: :forbidden
141
+ end
142
+ end
143
+
144
+ def logout_authorize
145
+ if !::Authorization::People::V1::User.logout?(current_user)
146
+ render :json => {errors: "User is not authorized for this action"}, status: :forbidden
147
+ end
148
+ end
149
+
150
+
151
+ def index_authorize
152
+ if !::Authorization::People::V1::User.index?(current_user)
153
+ render :json => {errors: "User is not authorized for this action"}, status: :forbidden
154
+ end
155
+ end
156
+
157
+ def show_authorize
158
+ if !::Authorization::People::V1::User.show?(@user,current_user)
159
+ render :json => {errors: "User is not authorized for this action"}, status: :forbidden
160
+ end
161
+ end
162
+
163
+ def update_authorize
164
+ if !::Authorization::People::V1::User.update?(@user,current_user)
165
+ render :json => {errors: "User is not authorized for this action"}, status: :forbidden
166
+ end
167
+ end
168
+ end
169
+ end
@@ -0,0 +1,4 @@
1
+ module People
2
+ class ApplicationController < ::ApplicationController
3
+ end
4
+ end
@@ -0,0 +1,62 @@
1
+ require_dependency "people/application_controller"
2
+
3
+ module People
4
+ class UsersController < ApplicationController
5
+ before_action :set_user, only: [:show, :edit, :update, :destroy]
6
+
7
+ # GET /users
8
+ def index
9
+ @users = User.all
10
+ end
11
+
12
+ # GET /users/1
13
+ def show
14
+ end
15
+
16
+ # GET /users/new
17
+ def new
18
+ @user = User.new
19
+ end
20
+
21
+ # GET /users/1/edit
22
+ def edit
23
+ end
24
+
25
+ # POST /users
26
+ def create
27
+ @user = User.new(user_params)
28
+
29
+ if @user.save
30
+ redirect_to @user, notice: 'User was successfully created.'
31
+ else
32
+ render action: 'new'
33
+ end
34
+ end
35
+
36
+ # PATCH/PUT /users/1
37
+ def update
38
+ if @user.update(user_params)
39
+ redirect_to @user, notice: 'User was successfully updated.'
40
+ else
41
+ render action: 'edit'
42
+ end
43
+ end
44
+
45
+ # DELETE /users/1
46
+ def destroy
47
+ @user.destroy
48
+ redirect_to users_url, notice: 'User was successfully destroyed.'
49
+ end
50
+
51
+ private
52
+ # Use callbacks to share common setup or constraints between actions.
53
+ def set_user
54
+ @user = User.find(params[:id])
55
+ end
56
+
57
+ # Only allow a trusted parameter "white list" through.
58
+ def user_params
59
+ params.require(:user).permit(:username, :email, :password_digest)
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,4 @@
1
+ module People
2
+ module ApplicationHelper
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module People
2
+ module UsersHelper
3
+ end
4
+ end
@@ -0,0 +1,9 @@
1
+ module People
2
+ class User < ActiveRecord::Base
3
+
4
+ def self.recent(num)
5
+ ::People::User.order("created_at DESC").limit(num)
6
+ end
7
+
8
+ end
9
+ end
@@ -0,0 +1,32 @@
1
+ require 'type_cartographer'
2
+
3
+ module People
4
+ class V1::User < ActiveRecord::Base
5
+ self.table_name = 'people_users'
6
+
7
+ before_save { self.email = email.downcase }
8
+ before_save { self.username = username.downcase }
9
+
10
+
11
+ has_many :tokens, :as => :imageable, :class_name => "::Arcadex::Token"
12
+
13
+ has_secure_password
14
+
15
+ after_create :setup_user
16
+
17
+ validates :username, presence: true, :uniqueness => { :case_sensitive => false }
18
+ #validates_format_of :username, :with => /\A[A-Za-z0-9\d]+\Z/i
19
+ validates :email, presence: true, :uniqueness => { :case_sensitive => false }
20
+ #Might need a regex for emails, or just rather confirm them
21
+
22
+
23
+ def setup_user
24
+ create_token
25
+ end
26
+
27
+ def create_token
28
+ self.tokens.create!
29
+ end
30
+
31
+ end
32
+ end