user_mgmt 0.0.621 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (115) hide show
  1. data/.gitignore +2 -0
  2. data/.rspec +0 -0
  3. data/Gemfile +0 -0
  4. data/LICENSE.txt +0 -0
  5. data/MIT-LICENSE +0 -0
  6. data/README.md +0 -0
  7. data/Rakefile +0 -0
  8. data/app/assets/images/user_mgmt/.keep +0 -0
  9. data/app/assets/javascripts/user_mgmt/application.js +0 -0
  10. data/app/assets/javascripts/user_mgmt/registrations.js +0 -0
  11. data/app/assets/javascripts/user_mgmt/sessions.js +0 -0
  12. data/app/assets/stylesheets/user_mgmt/application.css.scss +0 -0
  13. data/app/assets/stylesheets/user_mgmt/registrations.css +0 -0
  14. data/app/assets/stylesheets/user_mgmt/sessions.css +0 -0
  15. data/app/controllers/user_mgmt/application_controller.rb +0 -90
  16. data/app/controllers/user_mgmt/registrations_controller.rb +0 -0
  17. data/app/controllers/user_mgmt/sessions_controller.rb +13 -15
  18. data/app/controllers/user_mgmt_controller.rb +4 -0
  19. data/app/helpers/user_mgmt/application_helper.rb +98 -5
  20. data/app/helpers/user_mgmt/registrations_helper.rb +0 -0
  21. data/app/helpers/user_mgmt/sessions_helper.rb +0 -0
  22. data/app/models/user_mgmt/user.rb +0 -0
  23. data/app/views/layouts/user_mgmt/application.html.erb +14 -0
  24. data/app/views/user_mgmt/registrations/_user_form.html.haml +0 -0
  25. data/app/views/user_mgmt/registrations/edit.html.haml +0 -0
  26. data/app/views/user_mgmt/registrations/new.html.haml +1 -0
  27. data/app/views/user_mgmt/sessions/new.html.haml +0 -0
  28. data/app/views/user_mgmt/sessions/oauth_email.html.haml +0 -0
  29. data/config/routes.rb +1 -1
  30. data/lib/generators/templates/README +0 -0
  31. data/lib/generators/templates/user_mgmt.rb +0 -0
  32. data/lib/generators/user_mgmt/install_generator.rb +0 -0
  33. data/lib/tasks/user_mgmt_tasks.rake +0 -0
  34. data/lib/user_mgmt.rb +0 -0
  35. data/lib/user_mgmt/configurator.rb +8 -0
  36. data/lib/user_mgmt/engine.rb +0 -0
  37. data/lib/user_mgmt/version.rb +1 -1
  38. data/spec/generators/install_generator_spec.rb +0 -0
  39. data/spec/spec_helper.rb +0 -0
  40. data/spec/user_mgmt_spec.rb +0 -0
  41. data/test/controllers/user_mgmt/registrations_controller_test.rb +0 -0
  42. data/test/controllers/user_mgmt/sessions_controller_test.rb +0 -0
  43. data/test/dummy/README.rdoc +0 -0
  44. data/test/dummy/Rakefile +0 -0
  45. data/test/dummy/app/assets/images/.keep +0 -0
  46. data/test/dummy/app/assets/javascripts/application.js +0 -0
  47. data/test/dummy/app/assets/javascripts/simulate.js +0 -0
  48. data/test/dummy/app/assets/stylesheets/application.css +0 -0
  49. data/test/dummy/app/assets/stylesheets/simulate.css +0 -0
  50. data/test/dummy/app/controllers/application_controller.rb +0 -0
  51. data/test/dummy/app/controllers/concerns/.keep +0 -0
  52. data/test/dummy/app/controllers/simulate_controller.rb +0 -0
  53. data/test/dummy/app/helpers/application_helper.rb +0 -0
  54. data/test/dummy/app/helpers/simulate_helper.rb +0 -0
  55. data/test/dummy/app/mailers/.keep +0 -0
  56. data/test/dummy/app/models/.keep +0 -0
  57. data/test/dummy/app/models/concerns/.keep +0 -0
  58. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  59. data/test/dummy/app/views/layouts/application.html.haml +0 -0
  60. data/test/dummy/app/views/simulate/index.html.haml +0 -0
  61. data/test/dummy/bin/bundle +0 -0
  62. data/test/dummy/bin/rails +0 -0
  63. data/test/dummy/bin/rake +0 -0
  64. data/test/dummy/config.ru +0 -0
  65. data/test/dummy/config/application.rb +0 -0
  66. data/test/dummy/config/boot.rb +0 -0
  67. data/test/dummy/config/database.yml +0 -0
  68. data/test/dummy/config/environment.rb +0 -0
  69. data/test/dummy/config/environments/development.rb +0 -0
  70. data/test/dummy/config/environments/production.rb +0 -0
  71. data/test/dummy/config/environments/test.rb +0 -0
  72. data/test/dummy/config/initializers/backtrace_silencers.rb +0 -0
  73. data/test/dummy/config/initializers/filter_parameter_logging.rb +0 -0
  74. data/test/dummy/config/initializers/inflections.rb +0 -0
  75. data/test/dummy/config/initializers/mime_types.rb +0 -0
  76. data/test/dummy/config/initializers/secret_token.rb +0 -0
  77. data/test/dummy/config/initializers/session_store.rb +0 -0
  78. data/test/dummy/config/initializers/user_mgmt.rb +12 -12
  79. data/test/dummy/config/initializers/wrap_parameters.rb +0 -0
  80. data/test/dummy/config/locales/en.yml +0 -0
  81. data/test/dummy/config/routes.rb +0 -0
  82. data/test/dummy/db/migrate/20130806190900_create_studies.rb +10 -0
  83. data/test/dummy/db/migrate/20130806220801_change_type.rb +6 -0
  84. data/test/dummy/db/migrate/20130807174623_create_submissions.rb +10 -0
  85. data/test/dummy/db/migrate/20130807181717_add_belongs_to_study_to_submission.rb +7 -0
  86. data/test/dummy/db/migrate/20130808170540_add_status_to_submission.rb +5 -0
  87. data/test/dummy/db/migrate/20130808221923_create_documents.rb +13 -0
  88. data/test/dummy/db/migrate/20130808222548_change_belongs.rb +8 -0
  89. data/test/dummy/db/migrate/20130809185731_add_status_to_documents.rb +5 -0
  90. data/test/dummy/db/migrate/20130809192308_add_belongs_to_documents.rb +5 -0
  91. data/test/dummy/db/migrate/20130809193456_drop_table_documents.rb +16 -0
  92. data/test/dummy/db/migrate/20130809195742_change_to_documents.rb +6 -0
  93. data/test/dummy/db/migrate/20130812195326_remove_status_from_submission.rb +9 -0
  94. data/test/dummy/db/migrate/20130812205930_remove_version_from_document.rb +9 -0
  95. data/test/dummy/db/migrate/20130812210009_add_version_to_document.rb +6 -0
  96. data/test/dummy/db/migrate/20130814171636_create_sections.rb +12 -0
  97. data/test/dummy/db/schema.rb +54 -0
  98. data/test/dummy/db/seeds.rb +7 -0
  99. data/test/dummy/lib/assets/.keep +0 -0
  100. data/test/dummy/log/.keep +0 -0
  101. data/test/dummy/public/404.html +0 -0
  102. data/test/dummy/public/422.html +0 -0
  103. data/test/dummy/public/500.html +0 -0
  104. data/test/dummy/public/favicon.ico +0 -0
  105. data/test/dummy/test/controllers/simulate_controller_test.rb +0 -0
  106. data/test/dummy/test/helpers/simulate_helper_test.rb +0 -0
  107. data/test/helpers/user_mgmt/registrations_helper_test.rb +0 -0
  108. data/test/helpers/user_mgmt/sessions_helper_test.rb +0 -0
  109. data/test/integration/navigation_test.rb +0 -0
  110. data/test/test_helper.rb +0 -0
  111. data/test/user_mgmt_test.rb +0 -0
  112. data/user_mgmt.gemspec +1 -1
  113. metadata +118 -42
  114. checksums.yaml +0 -7
  115. data/app/views/layouts/user_mgmt/application.html.haml +0 -17
data/.gitignore CHANGED
@@ -21,3 +21,5 @@ spec/reports
21
21
  test/tmp
22
22
  test/version_tmp
23
23
  tmp
24
+ *.DS_Store
25
+ test/ICF_mgmt
data/.rspec CHANGED
File without changes
data/Gemfile CHANGED
File without changes
File without changes
File without changes
data/README.md CHANGED
File without changes
data/Rakefile CHANGED
File without changes
File without changes
@@ -7,95 +7,5 @@ module UserMgmt
7
7
  redirect_to main_app.root_path
8
8
  end
9
9
 
10
- private
11
- def current_user
12
- @current_user ||= nil#User.find(session[:user_session_id]) if session[:user_session_id]
13
- end
14
- helper_method :current_user
15
-
16
- def sign_up email, password, password_confirmation, host= UserMgmt.external_database_URI
17
- send_request :post, :users, { user: { email: email, password: password,
18
- password_confirmation: password_confirmation }, method: :simple }, host
19
- end
20
-
21
- def sign_up_oauth uid, strategy, email, host= UserMgmt.external_database_URI
22
- send_request :post, :users, { user: { uid: uid, strategy: strategy, email: email }, method: :oauth }, host
23
- end
24
-
25
- def log_in email, password, host= UserMgmt.external_database_URI
26
- send_request :get, :login, { user: { email: email, password: password }, method: :simple }, host
27
- end
28
-
29
- def log_in_oauth uid, strategy, host= UserMgmt.external_database_URI
30
- send_request :get, :login, { user: { uid: uid, strategy: strategy }, method: :oauth }, host
31
- end
32
-
33
- def log_out umid, host= UserMgmt.external_database_URI
34
- send_request :delete, :logout, { user: umid }, host
35
- end
36
-
37
- def add_strategy uid, strategy, umid, session, host= UserMgmt.external_database_URI
38
- send_request :post, :add_strategy, { new_strategy: { uid: uid, strategy: strategy },
39
- user: umid, session_id: session }, host
40
- end
41
-
42
- def remove_strategy umid, strategy, session, host= UserMgmt.external_database_URI
43
- send_request :delete, :remove_strategy, { user: umid, strategy: strategy,
44
- session_id: session }, host
45
- end
46
-
47
- def delete_user umid, session, host= UserMgmt.external_database_URI
48
- send_request :delete, :destroy, { user: umid, session_id: session }, host
49
- end
50
-
51
- def change_password user, password, new_pw, new_pw_confirm, session, host= UserMgmt.external_database_URI
52
- send_request :put, :change_password, { user: user, password: password,
53
- new_password: new_pw, new_password_confirmation: new_pw_confirm,
54
- session: session }, host
55
- end
56
-
57
- def reset_password reset_token, new_pw, new_pw_confirm, host= UserMgmt.external_database_URI
58
- send_request :put, :change_password, { reset_token: reset_token, new_password: new_pw,
59
- new_password_confirmation: new_pw_confirm }, host
60
- end
61
-
62
- def reset_password_request email, host= UserMgmt.external_database_URI
63
- send_request :post, :reset_password, { email: email }, host
64
- end
65
-
66
- def change_email user, password, new_email, new_email_confirm, session, host= UserMgmt.external_database_URI
67
- send_request :put, :change_email, { email: user, password: password, new_email: new_email,
68
- new_email_confirmation: new_email_confirm, session: session }, host
69
- end
70
-
71
- private
72
-
73
- def send_request method, path='/', params={}, host= UserMgmt.external_database_URI
74
- path = path.to_s.downcase
75
- path = '/' << path unless path.start_with? '/'
76
- uri = URI.parse(host)
77
- http = Net::HTTP.new(uri.host, uri.port)
78
-
79
- case method.to_s.downcase
80
- when 'get'
81
- request = Net::HTTP::Get.new(uri.request_uri << path, initheader = {'Content-Type' =>'application/json'})
82
- when 'post'
83
- request = Net::HTTP::Post.new(uri.request_uri << path, initheader = {'Content-Type' =>'application/json'})
84
- when 'put'
85
- request = Net::HTTP::Put.new(uri.request_uri << path, initheader = {'Content-Type' =>'application/json'})
86
- when 'delete'
87
- request = Net::HTTP::Delete.new(uri.request_uri << path, initheader = {'Content-Type' =>'application/json'})
88
- end
89
-
90
- request.body = params.to_json
91
- response = http.request(request)
92
- begin
93
- return { body: JSON.parse(response.body), status: response.code }
94
- rescue
95
- return { body: response.body, status: response.code }
96
- end
97
- end
98
-
99
-
100
10
  end
101
11
  end
@@ -1,7 +1,9 @@
1
1
  require_dependency "user_mgmt/application_controller"
2
+ require_dependency "user_mgmt/application_helper"
2
3
 
3
4
  module UserMgmt
4
5
  class SessionsController < ApplicationController
6
+ include ApplicationHelper
5
7
 
6
8
  # GET /user/log_in
7
9
  def new
@@ -14,8 +16,8 @@ module UserMgmt
14
16
  response = log_in *params[:user].values
15
17
 
16
18
  if response[:status] == "200"
17
- flash[:notice] = "User logged in!"
18
- session[:user_session_id] = response[:body]["session"]
19
+ flash[:success] = "User logged in!"
20
+ cookies.permanent[:user_session_id] = response[:body]["session"]
19
21
  redirect_to main_app.root_path
20
22
  else
21
23
  flash[:warning] = response[:body]
@@ -45,8 +47,8 @@ module UserMgmt
45
47
  # otherwise it means the user doesn't exist yet, so continue
46
48
  # normaly (user will be asked for his email).
47
49
  if response[:status] == "200"
48
- session[:user_session_id] = response[:body]["session"]
49
- redirect_to main_app.root_path, notice: "User logged in!"
50
+ cookies.permanent[:user_session_id] = response[:body]["session"]
51
+ redirect_to main_app.root_path, flash: { success: "User logged in!" }
50
52
  end
51
53
 
52
54
  end
@@ -58,23 +60,19 @@ module UserMgmt
58
60
 
59
61
  #if for some reason, the user couldn't be created
60
62
  if response[:status] == "400"
61
- redirect_to sign_up_path, notice: response[:body]
63
+ redirect_to sign_up_path, flash: { warning: response[:body] }
64
+ else
65
+ response = log_in_oauth params["uid"], params["provider"].to_sym
66
+ cookies.permanent[:user_session_id] = response[:body]["session"]
67
+ redirect_to main_app.root_path, flash: { success: "User logged in!" }
62
68
  end
63
69
 
64
- response = log_in_oauth params["uid"], params["provider"].to_sym
65
-
66
- session[:user_session_id] = response[:body]["session"]
67
-
68
- redirect_to main_app.root_path, notice: "User logged in!"
69
-
70
70
  end
71
71
 
72
72
  # GET /user/log_out
73
73
  def destroy
74
-
75
- session[:user_session_id] = nil
76
- redirect_to main_app.root_path, notice: "Logged out!"
77
-
74
+ cookies.delete(:user_session_id)
75
+ redirect_to main_app.root_path, flash: { success: "Logged out!" }
78
76
  end
79
77
 
80
78
  end
@@ -0,0 +1,4 @@
1
+ # All controllers are inherited from here.
2
+ class UserMgmtController < UserMgmt.parent_controller.constantize
3
+
4
+ end
@@ -1,9 +1,102 @@
1
1
  module UserMgmt
2
- module ApplicationHelper
2
+ module ApplicationHelper
3
3
 
4
- def user_logged_in
5
- session[:user_session_id] != nil
6
- end
4
+ def user_logged_in?
5
+ cookies[:user_session_id] != nil
6
+ end
7
+
8
+ def current_user
9
+ @current_user ||= user_info(cookies[:user_session_id])[:body] if cookies[:user_session_id]
10
+ end
11
+
12
+ def sign_up email, password, password_confirmation, host=UserMgmt.external_database_URI
13
+ send_request :post, :users, { user: { email: email, password: password,
14
+ password_confirmation: password_confirmation }, method: :simple }, host
15
+ end
16
+
17
+ def sign_up_oauth uid, strategy, email, host=UserMgmt.external_database_URI
18
+ send_request :post, :users, { user: { uid: uid, strategy: strategy, email: email }, method: :oauth }, host
19
+ end
20
+
21
+ def log_in email, password, host=UserMgmt.external_database_URI
22
+ send_request :get, :login, { user: { email: email, password: password }, method: :simple }, host
23
+ end
24
+
25
+ def log_in_oauth uid, strategy, host=UserMgmt.external_database_URI
26
+ send_request :get, :login, { user: { uid: uid, strategy: strategy }, method: :oauth }, host
27
+ end
28
+
29
+ def log_out umid, host=UserMgmt.external_database_URI
30
+ send_request :delete, :logout, { user: umid }, host
31
+ end
32
+
33
+ def user_info session, host=UserMgmt.external_database_URI
34
+ send_request :get, :user_info, { session_id: session }, host
35
+ end
36
+
37
+ def add_strategy uid, strategy, umid, session, host=UserMgmt.external_database_URI
38
+ send_request :post, :add_strategy, { new_strategy: { uid: uid, strategy: strategy },
39
+ user: umid, session_id: session }, host
40
+ end
41
+
42
+ def remove_strategy umid, strategy, session, host=UserMgmt.external_database_URI
43
+ send_request :delete, :remove_strategy, { user: umid, strategy: strategy,
44
+ session_id: session }, host
45
+ end
7
46
 
8
- end
47
+ def delete_user umid, session, host=UserMgmt.external_database_URI
48
+ send_request :delete, :destroy, { user: umid, session_id: session }, host
49
+ end
50
+
51
+ def change_password user, password, new_pw, new_pw_confirm, session, host=UserMgmt.external_database_URI
52
+ send_request :put, :change_password, { user: user, password: password,
53
+ new_password: new_pw, new_password_confirmation: new_pw_confirm,
54
+ session: session }, host
55
+ end
56
+
57
+ def reset_password reset_token, new_pw, new_pw_confirm, host=UserMgmt.external_database_URI
58
+ send_request :put, :change_password, { reset_token: reset_token, new_password: new_pw,
59
+ new_password_confirmation: new_pw_confirm }, host
60
+ end
61
+
62
+ def reset_password_request email, host=UserMgmt.external_database_URI
63
+ send_request :post, :reset_password, { email: email }, host
64
+ end
65
+
66
+ def change_email user, password, new_email, new_email_confirm, session, host=UserMgmt.external_database_URI
67
+ send_request :put, :change_email, { email: user, password: password, new_email: new_email,
68
+ new_email_confirmation: new_email_confirm, session: session }, host
69
+ end
70
+
71
+ private
72
+
73
+ def send_request method, path='/', params={}, host=UserMgmt.external_database_URI
74
+ path = path.to_s.downcase
75
+ path = '/' << path unless path.start_with? '/'
76
+ uri = URI.parse(host)
77
+ http = Net::HTTP.new(uri.host, uri.port)
78
+
79
+ case method.to_s.downcase
80
+ when 'get'
81
+ request = Net::HTTP::Get.new(uri.request_uri << path, initheader = {'Content-Type' =>'application/json'})
82
+ when 'post'
83
+ request = Net::HTTP::Post.new(uri.request_uri << path, initheader = {'Content-Type' =>'application/json'})
84
+ when 'put'
85
+ request = Net::HTTP::Put.new(uri.request_uri << path, initheader = {'Content-Type' =>'application/json'})
86
+ when 'delete'
87
+ request = Net::HTTP::Delete.new(uri.request_uri << path, initheader = {'Content-Type' =>'application/json'})
88
+ end
89
+
90
+ request.body = params.to_json
91
+ response = http.request(request)
92
+ begin
93
+ r = { body: JSON.parse(response.body), status: response.code }
94
+ return r
95
+ rescue
96
+ r = { body: response.body, status: response.code }
97
+ return r
98
+ end
99
+ end
100
+
101
+ end
9
102
  end
File without changes
File without changes
@@ -0,0 +1,14 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>UserMgmt</title>
5
+ <%= stylesheet_link_tag "user_mgmt/application", media: "all" %>
6
+ <%= javascript_include_tag "user_mgmt/application" %>
7
+ <%= csrf_meta_tags %>
8
+ </head>
9
+ <body>
10
+
11
+ <%= yield %>
12
+
13
+ </body>
14
+ </html>
@@ -3,6 +3,7 @@
3
3
  %h2 Sign up
4
4
  = render :partial => 'user_form'
5
5
  = submit_tag 'submit', :class => "btn btn-large btn-primary"
6
+ = link_to 'cancel', cancel_path, :class => "btn btn-large btn-primary"
6
7
  %ul.unstyled
7
8
  %li
8
9
  = link_to "Log in with Facebook", "auth/facebook"
@@ -10,7 +10,7 @@ UserMgmt::Engine.routes.draw do
10
10
  post '/' => 'registrations#create', as: 'user'
11
11
 
12
12
  get 'auth/:provider/callback' => 'sessions#oauth_email', as: 'oauth_email'
13
- get 'auth/failure' => 'application#main_page'
13
+ get 'auth/failure' => 'application#main_page', as: 'cancel'
14
14
 
15
15
 
16
16
  end
File without changes
File without changes
File without changes
File without changes
@@ -0,0 +1,8 @@
1
+ # module UserMgmt
2
+
3
+
4
+ # class Configurator
5
+
6
+ # def
7
+
8
+ # end
File without changes
@@ -1,3 +1,3 @@
1
1
  module UserMgmt
2
- VERSION = "0.0.621"
2
+ VERSION = "0.1.0"
3
3
  end
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -0,0 +1,14 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Dummy</title>
5
+ <%= stylesheet_link_tag "application", media: "all", "data-turbolinks-track" => true %>
6
+ <%= javascript_include_tag "application", "data-turbolinks-track" => true %>
7
+ <%= csrf_meta_tags %>
8
+ </head>
9
+ <body>
10
+
11
+ <%= yield %>
12
+
13
+ </body>
14
+ </html>