user_mgmt 0.0.522 → 0.0.611

Sign up to get free protection for your applications and to get access to all the features.
Files changed (143) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/user_mgmt/application_controller.rb +97 -0
  3. data/app/controllers/user_mgmt/registrations_controller.rb +9 -0
  4. data/app/controllers/user_mgmt/sessions_controller.rb +44 -3
  5. data/app/helpers/user_mgmt/application_helper.rb +9 -0
  6. data/app/models/user_mgmt/user.rb +15 -0
  7. data/app/views/layouts/user_mgmt/application.html.haml +6 -0
  8. data/app/views/user_mgmt/registrations/_user_form.html.haml +2 -2
  9. data/app/views/user_mgmt/registrations/new.html.haml +6 -1
  10. data/app/views/user_mgmt/sessions/new.html.haml +17 -1
  11. data/app/views/user_mgmt/sessions/oauth_email.html.haml +11 -0
  12. data/config/routes.rb +6 -1
  13. data/lib/generators/templates/README +17 -1
  14. data/lib/generators/templates/user_mgmt.rb +20 -0
  15. data/lib/user_mgmt/engine.rb +13 -0
  16. data/lib/user_mgmt/version.rb +1 -1
  17. data/lib/user_mgmt.rb +4 -0
  18. data/test/controllers/user_mgmt/registrations_controller_test.rb +16 -0
  19. data/test/controllers/user_mgmt/sessions_controller_test.rb +21 -0
  20. data/test/dummy/README.rdoc +28 -0
  21. data/test/dummy/Rakefile +6 -0
  22. data/test/dummy/app/assets/javascripts/application.js +13 -0
  23. data/test/dummy/app/assets/javascripts/simulate.js +2 -0
  24. data/test/dummy/app/assets/stylesheets/application.css +13 -0
  25. data/test/dummy/app/assets/stylesheets/simulate.css +4 -0
  26. data/test/dummy/app/controllers/application_controller.rb +8 -0
  27. data/test/dummy/app/controllers/simulate_controller.rb +5 -0
  28. data/test/dummy/app/helpers/application_helper.rb +2 -0
  29. data/test/dummy/app/helpers/simulate_helper.rb +2 -0
  30. data/test/dummy/app/views/layouts/application.html.haml +17 -0
  31. data/test/dummy/app/views/simulate/index.html.haml +15 -0
  32. data/test/dummy/bin/bundle +3 -0
  33. data/test/dummy/bin/rails +4 -0
  34. data/test/dummy/bin/rake +4 -0
  35. data/test/dummy/config/application.rb +23 -0
  36. data/test/dummy/config/boot.rb +5 -0
  37. data/test/dummy/config/database.yml +25 -0
  38. data/test/dummy/config/environment.rb +5 -0
  39. data/test/dummy/config/environments/development.rb +29 -0
  40. data/test/dummy/config/environments/production.rb +80 -0
  41. data/test/dummy/config/environments/test.rb +36 -0
  42. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  43. data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  44. data/test/dummy/config/initializers/inflections.rb +16 -0
  45. data/test/dummy/config/initializers/mime_types.rb +5 -0
  46. data/test/dummy/config/initializers/secret_token.rb +12 -0
  47. data/test/dummy/config/initializers/session_store.rb +3 -0
  48. data/test/dummy/config/initializers/user_mgmt.rb +30 -0
  49. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  50. data/test/dummy/config/locales/en.yml +23 -0
  51. data/test/dummy/config/routes.rb +7 -0
  52. data/test/dummy/config.ru +4 -0
  53. data/test/dummy/db/development.sqlite3 +0 -0
  54. data/test/dummy/db/test.sqlite3 +0 -0
  55. data/test/dummy/log/development.log +21894 -0
  56. data/test/dummy/log/test.log +30 -0
  57. data/test/dummy/public/404.html +58 -0
  58. data/test/dummy/public/422.html +58 -0
  59. data/test/dummy/public/500.html +57 -0
  60. data/test/dummy/public/favicon.ico +0 -0
  61. data/test/dummy/test/controllers/simulate_controller_test.rb +9 -0
  62. data/test/dummy/test/helpers/simulate_helper_test.rb +4 -0
  63. data/test/dummy/tmp/cache/assets/development/sass/0565465174accc9e5f0a8b0cca8d51019e5d5dcd/_accordion.scssc +0 -0
  64. data/test/dummy/tmp/cache/assets/development/sass/0565465174accc9e5f0a8b0cca8d51019e5d5dcd/_alerts.scssc +0 -0
  65. data/test/dummy/tmp/cache/assets/development/sass/0565465174accc9e5f0a8b0cca8d51019e5d5dcd/_breadcrumbs.scssc +0 -0
  66. data/test/dummy/tmp/cache/assets/development/sass/0565465174accc9e5f0a8b0cca8d51019e5d5dcd/_button-groups.scssc +0 -0
  67. data/test/dummy/tmp/cache/assets/development/sass/0565465174accc9e5f0a8b0cca8d51019e5d5dcd/_buttons.scssc +0 -0
  68. data/test/dummy/tmp/cache/assets/development/sass/0565465174accc9e5f0a8b0cca8d51019e5d5dcd/_carousel.scssc +0 -0
  69. data/test/dummy/tmp/cache/assets/development/sass/0565465174accc9e5f0a8b0cca8d51019e5d5dcd/_close.scssc +0 -0
  70. data/test/dummy/tmp/cache/assets/development/sass/0565465174accc9e5f0a8b0cca8d51019e5d5dcd/_code.scssc +0 -0
  71. data/test/dummy/tmp/cache/assets/development/sass/0565465174accc9e5f0a8b0cca8d51019e5d5dcd/_component-animations.scssc +0 -0
  72. data/test/dummy/tmp/cache/assets/development/sass/0565465174accc9e5f0a8b0cca8d51019e5d5dcd/_dropdowns.scssc +0 -0
  73. data/test/dummy/tmp/cache/assets/development/sass/0565465174accc9e5f0a8b0cca8d51019e5d5dcd/_forms.scssc +0 -0
  74. data/test/dummy/tmp/cache/assets/development/sass/0565465174accc9e5f0a8b0cca8d51019e5d5dcd/_grid.scssc +0 -0
  75. data/test/dummy/tmp/cache/assets/development/sass/0565465174accc9e5f0a8b0cca8d51019e5d5dcd/_hero-unit.scssc +0 -0
  76. data/test/dummy/tmp/cache/assets/development/sass/0565465174accc9e5f0a8b0cca8d51019e5d5dcd/_labels-badges.scssc +0 -0
  77. data/test/dummy/tmp/cache/assets/development/sass/0565465174accc9e5f0a8b0cca8d51019e5d5dcd/_layouts.scssc +0 -0
  78. data/test/dummy/tmp/cache/assets/development/sass/0565465174accc9e5f0a8b0cca8d51019e5d5dcd/_media.scssc +0 -0
  79. data/test/dummy/tmp/cache/assets/development/sass/0565465174accc9e5f0a8b0cca8d51019e5d5dcd/_mixins.scssc +0 -0
  80. data/test/dummy/tmp/cache/assets/development/sass/0565465174accc9e5f0a8b0cca8d51019e5d5dcd/_modals.scssc +0 -0
  81. data/test/dummy/tmp/cache/assets/development/sass/0565465174accc9e5f0a8b0cca8d51019e5d5dcd/_navbar.scssc +0 -0
  82. data/test/dummy/tmp/cache/assets/development/sass/0565465174accc9e5f0a8b0cca8d51019e5d5dcd/_navs.scssc +0 -0
  83. data/test/dummy/tmp/cache/assets/development/sass/0565465174accc9e5f0a8b0cca8d51019e5d5dcd/_pager.scssc +0 -0
  84. data/test/dummy/tmp/cache/assets/development/sass/0565465174accc9e5f0a8b0cca8d51019e5d5dcd/_pagination.scssc +0 -0
  85. data/test/dummy/tmp/cache/assets/development/sass/0565465174accc9e5f0a8b0cca8d51019e5d5dcd/_popovers.scssc +0 -0
  86. data/test/dummy/tmp/cache/assets/development/sass/0565465174accc9e5f0a8b0cca8d51019e5d5dcd/_progress-bars.scssc +0 -0
  87. data/test/dummy/tmp/cache/assets/development/sass/0565465174accc9e5f0a8b0cca8d51019e5d5dcd/_reset.scssc +0 -0
  88. data/test/dummy/tmp/cache/assets/development/sass/0565465174accc9e5f0a8b0cca8d51019e5d5dcd/_scaffolding.scssc +0 -0
  89. data/test/dummy/tmp/cache/assets/development/sass/0565465174accc9e5f0a8b0cca8d51019e5d5dcd/_sprites.scssc +0 -0
  90. data/test/dummy/tmp/cache/assets/development/sass/0565465174accc9e5f0a8b0cca8d51019e5d5dcd/_tables.scssc +0 -0
  91. data/test/dummy/tmp/cache/assets/development/sass/0565465174accc9e5f0a8b0cca8d51019e5d5dcd/_thumbnails.scssc +0 -0
  92. data/test/dummy/tmp/cache/assets/development/sass/0565465174accc9e5f0a8b0cca8d51019e5d5dcd/_tooltip.scssc +0 -0
  93. data/test/dummy/tmp/cache/assets/development/sass/0565465174accc9e5f0a8b0cca8d51019e5d5dcd/_type.scssc +0 -0
  94. data/test/dummy/tmp/cache/assets/development/sass/0565465174accc9e5f0a8b0cca8d51019e5d5dcd/_utilities.scssc +0 -0
  95. data/test/dummy/tmp/cache/assets/development/sass/0565465174accc9e5f0a8b0cca8d51019e5d5dcd/_variables.scssc +0 -0
  96. data/test/dummy/tmp/cache/assets/development/sass/0565465174accc9e5f0a8b0cca8d51019e5d5dcd/_wells.scssc +0 -0
  97. data/test/dummy/tmp/cache/assets/development/sass/0565465174accc9e5f0a8b0cca8d51019e5d5dcd/bootstrap.scssc +0 -0
  98. data/test/dummy/tmp/cache/assets/development/sass/08baa9190ae62c5825550f45deea7e16b5510676/application.css.scssc +0 -0
  99. data/test/dummy/tmp/cache/assets/development/sass/a3ac9b1bfb4134782c1d12f62ef348f552630183/bootstrap.scssc +0 -0
  100. data/test/dummy/tmp/cache/assets/development/sprockets/022f999a319cf56fc1b74e08c183f9ed +0 -0
  101. data/test/dummy/tmp/cache/assets/development/sprockets/07a0d9a230805c18391fb1fa9ad89f4d +0 -0
  102. data/test/dummy/tmp/cache/assets/development/sprockets/0c86f94d4cfadfd0d7faf85933499f7e +0 -0
  103. data/test/dummy/tmp/cache/assets/development/sprockets/11cd415976f0f9503651e5bf3dcffe55 +0 -0
  104. data/test/dummy/tmp/cache/assets/development/sprockets/13fe41fee1fe35b49d145bcc06610705 +0 -0
  105. data/test/dummy/tmp/cache/assets/development/sprockets/182256f2cdfcb7f65cad1a6556736742 +0 -0
  106. data/test/dummy/tmp/cache/assets/development/sprockets/1a2ab1c1d743ebe16dbc65177bd4aeb5 +0 -0
  107. data/test/dummy/tmp/cache/assets/development/sprockets/1d2a2e9172d1f187f17da4c56686b396 +0 -0
  108. data/test/dummy/tmp/cache/assets/development/sprockets/2734674f08a0218f05aa1c1220b78902 +0 -0
  109. data/test/dummy/tmp/cache/assets/development/sprockets/2f5173deea6c795b8fdde723bb4b63af +0 -0
  110. data/test/dummy/tmp/cache/assets/development/sprockets/322652c3fe53e3c12be9cdbf81f97103 +0 -0
  111. data/test/dummy/tmp/cache/assets/development/sprockets/32839c4373cf90b1de445a2c0d3dcbdc +0 -0
  112. data/test/dummy/tmp/cache/assets/development/sprockets/357970feca3ac29060c1e3861e2c0953 +0 -0
  113. data/test/dummy/tmp/cache/assets/development/sprockets/3ac898a768e6c22e5fc9e1d62f64b13b +0 -0
  114. data/test/dummy/tmp/cache/assets/development/sprockets/4d6b3c4d39931ed121044e1b76b67c66 +0 -0
  115. data/test/dummy/tmp/cache/assets/development/sprockets/4e334d8a78cce254ce765049c5d2ef2b +0 -0
  116. data/test/dummy/tmp/cache/assets/development/sprockets/5457651f4fd5c456bcf875b4aa72149e +0 -0
  117. data/test/dummy/tmp/cache/assets/development/sprockets/5bf88d72b841c26d7feb74250bae80f4 +0 -0
  118. data/test/dummy/tmp/cache/assets/development/sprockets/685244533311db6b641af2aa200c650f +0 -0
  119. data/test/dummy/tmp/cache/assets/development/sprockets/7a050aee25e0e30c5f640bb856d3db08 +0 -0
  120. data/test/dummy/tmp/cache/assets/development/sprockets/8e254fa9d715c6e5250bab91023a2eb1 +0 -0
  121. data/test/dummy/tmp/cache/assets/development/sprockets/a3ed9b085aa940ee68a2ac75caf6118d +0 -0
  122. data/test/dummy/tmp/cache/assets/development/sprockets/a94356ecde652bbdfbe926f4b20bbc62 +0 -0
  123. data/test/dummy/tmp/cache/assets/development/sprockets/b0ca28d54b5fd6ab0647874da233bcea +0 -0
  124. data/test/dummy/tmp/cache/assets/development/sprockets/c0eaef738b6bdad0afd285c3866dc00b +0 -0
  125. data/test/dummy/tmp/cache/assets/development/sprockets/c400393e6ee751e159c636d2f1b4ece1 +0 -0
  126. data/test/dummy/tmp/cache/assets/development/sprockets/cf9c898477d0d114419affee8fe5e94a +0 -0
  127. data/test/dummy/tmp/cache/assets/development/sprockets/cffd775d018f68ce5dba1ee0d951a994 +0 -0
  128. data/test/dummy/tmp/cache/assets/development/sprockets/d04a23ab8f76f67d5f032307a809446d +0 -0
  129. data/test/dummy/tmp/cache/assets/development/sprockets/d6491478c63d922c855dd1f7ae86405b +0 -0
  130. data/test/dummy/tmp/cache/assets/development/sprockets/d771ace226fc8215a3572e0aa35bb0d6 +0 -0
  131. data/test/dummy/tmp/cache/assets/development/sprockets/d850023c29aab778ee0cc7fedf82e69d +0 -0
  132. data/test/dummy/tmp/cache/assets/development/sprockets/f7cbd26ba1d28d48de824f0e94586655 +0 -0
  133. data/test/dummy/tmp/cache/assets/development/sprockets/f9fc91e06d98e04ba3cb00620d0bac5e +0 -0
  134. data/test/dummy/tmp/cache/assets/development/sprockets/fd1e5d1f7e9d675209dbf864cbc607fc +0 -0
  135. data/test/dummy/tmp/cache/assets/development/sprockets/fdc85097d4de3566cb0f9b8f424bb8b3 +0 -0
  136. data/test/dummy/tmp/cache/assets/development/sprockets/ff73f764c8df44829310dc9e5587025a +0 -0
  137. data/test/helpers/user_mgmt/registrations_helper_test.rb +6 -0
  138. data/test/helpers/user_mgmt/sessions_helper_test.rb +6 -0
  139. data/test/integration/navigation_test.rb +10 -0
  140. data/test/test_helper.rb +15 -0
  141. data/test/user_mgmt_test.rb +7 -0
  142. metadata +337 -4
  143. data/app/controllers/user_mgmt_controller.rb +0 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 06c47a30b98f0227e8771aecbd0b1a8ac3f8fe57
4
- data.tar.gz: 5b053fe92b81d57eca4929929a038a8e1ff40919
3
+ metadata.gz: 908f5cbf67a73b29d0dc6bae42c6e86fff4f531a
4
+ data.tar.gz: f0858ed4cf791dbcb3b551e88bf000593ef123d7
5
5
  SHA512:
6
- metadata.gz: 02b67caa07bf99bfd533da8267e5a7557b3340e0ca6e1f1bf212e8c373a0f4a982074a1d3d7f7a94d22baa8b7438b0c26e9225db2c8edcc6430301afeddaff43
7
- data.tar.gz: e0fe1d78faf69d4a854bc3fb8198a6cbf79f54eb4880ff25f99c35222936067c747f654f5a151f779ec965537f252615a0f16a6915e2543cf522bc3779398bd7
6
+ metadata.gz: 8c9a518ad356755b33a91128b2835e295696a243a62224530433c98b6e5e59f018f2fb4f19517a6b0a0e1ac91b243978febe0138d3e4d16242b031316142ed5e
7
+ data.tar.gz: dfb72140942e96e9c0f12afb9873cd058a5301012c22ecfefecda9145616500fde30823f7ade270585c9205b0714b6fce07272fbb0306f728ce254b578870bc3
@@ -1,4 +1,101 @@
1
1
  module UserMgmt
2
2
  class ApplicationController < ActionController::Base
3
+ require "net/http"
4
+ require "uri"
5
+
6
+ def main_page
7
+ redirect_to main_app.root_path
8
+ end
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
+
3
100
  end
4
101
  end
@@ -11,7 +11,16 @@ module UserMgmt
11
11
  # POST /user
12
12
  def create
13
13
 
14
+ response = sign_up *params[:user].values
15
+
16
+ if response[:status] == "200"
17
+ flash[:notice] = "User was created succesfully!"
14
18
  redirect_to main_app.root_path
19
+ else
20
+ flash[:warning] = response[:body]#"User couldn't be created. Try again."
21
+ redirect_to sign_up_path
22
+ end
23
+
15
24
  end
16
25
 
17
26
  # GET /user/edit
@@ -11,13 +11,54 @@ module UserMgmt
11
11
  # POST /user/log_in
12
12
  def create
13
13
 
14
- redirect_to main_app.root_path
14
+ response = log_in *params[:user].values
15
+
16
+ if response[:status] == "200"
17
+ flash[:notice] = "User logged in!"
18
+ session[:user_session_id] = response[:body]["session"]
19
+ redirect_to main_app.root_path
20
+ else
21
+ flash[:warning] = response[:body]
22
+ redirect_to log_in_path
23
+ end
24
+
25
+ end
26
+
27
+ # GET 'auth/:provider/callback'
28
+ def oauth_email
29
+
30
+ @uid = env['omniauth.auth']["uid"]
31
+ @provider= env['omniauth.auth']["provider"]
32
+
33
+ response = log_in_oauth @uid, @provider
34
+
35
+ # if user logged in succesfully, just redirect to main page
36
+ if response[:status] == "200"
37
+ session[:user_session_id] = response[:body]["session"]
38
+ redirect_to main_app.root_path, notice: "User logged in!"
39
+ end
40
+
41
+ end
42
+
43
+ # POST '/oauth_log_in'
44
+ def create_oauth
45
+
46
+ sign_up_oauth params["uid"], params["provider"].to_sym, params["user"]["Email"]
47
+
48
+ response = log_in_oauth params["uid"], params["provider"].to_sym
49
+
50
+ session[:user_session_id] = response[:body]["session"]
51
+
52
+ redirect_to main_app.root_path, notice: "User logged in!"
53
+
15
54
  end
16
55
 
17
- # DELETE /user/log_out
56
+ # GET /user/log_out
18
57
  def destroy
19
58
 
20
- redirect_to main_app.root_path
59
+ session[:user_session_id] = nil
60
+ redirect_to main_app.root_path, notice: "Logged out!"
61
+
21
62
  end
22
63
 
23
64
  end
@@ -1,4 +1,13 @@
1
1
  module UserMgmt
2
2
  module ApplicationHelper
3
+
4
+ def user_logged_in
5
+ session[:user_session_id] != nil
6
+ end
7
+
8
+ def router_name
9
+ UserMgmt.router_name
10
+ end
11
+
3
12
  end
4
13
  end
@@ -0,0 +1,15 @@
1
+ module UserMgmt
2
+ class User
3
+
4
+ attr_accessor :email, :password, :password_confirmation
5
+
6
+ def self.find session_id
7
+
8
+ end
9
+
10
+ def self.dummy
11
+ "yay"
12
+ end
13
+
14
+ end
15
+ end
@@ -8,4 +8,10 @@
8
8
  = csrf_meta_tags
9
9
 
10
10
  %body
11
+ #main
12
+ - if flash[:notice]
13
+ #notice.message= flash[:notice]
14
+ - elsif flash[:warning]
15
+ #warning.message= flash[:warning]
16
+
11
17
  = yield
@@ -9,7 +9,7 @@
9
9
  = text_field :user, 'Email', :class => "input-block-level", :placeholder => 'Email'
10
10
 
11
11
  %div
12
- = text_field :user, 'Password', :class => "input-block-level", :placeholder => 'Password'
12
+ = text_field :user, 'Password', :class => "input-block-level", :type => "password", :placeholder => 'Password'
13
13
 
14
14
  %div
15
- = text_field :user, 'Password Confirmation', :class => "input-block-level", :placeholder => 'Password Confirmation'
15
+ = text_field :user, 'Password Confirmation', :class => "input-block-level", :type => "password", :placeholder => 'Password Confirmation'
@@ -2,4 +2,9 @@
2
2
  = form_tag user_path, :class => "form-signin", :method => :post do
3
3
  %h2 Sign up
4
4
  = render :partial => 'user_form'
5
- = submit_tag 'submit', :class => "btn btn-large btn-primary"
5
+ = submit_tag 'submit', :class => "btn btn-large btn-primary"
6
+ %ul.unstyled
7
+ %li
8
+ = link_to "Sign up with Facebook", "auth/facebook"
9
+ %li
10
+ = link_to "Sign up with Twitter", "auth/twitter"
@@ -6,9 +6,25 @@
6
6
  = text_field :user, 'Email', :class => "input-block-level", :placeholder => "Email"
7
7
 
8
8
  %div
9
- = text_field :user, 'Password', :class => "input-block-level", :placeholder => 'Password'
9
+ = text_field :user, 'Password', :class => "input-block-level", :type => "password", :placeholder => 'Password'
10
10
 
11
11
  = submit_tag 'submit', :class => "btn btn-large btn-primary"
12
12
 
13
+ %ul.unstyled
14
+ %li
15
+
16
+ = link_to "Log in with Facebook", "auth/facebook"
17
+ %li
18
+ = link_to "Log in with Twitter", "auth/twitter"
19
+ %li
20
+ = link_to "Log in with Outlook", "auth/windowslive"
21
+ %li
22
+ = link_to "Log in with LinkedIn", "auth/linkedin"
23
+ %li
24
+ = link_to "Log in with Yahoo", "auth/yahoo"
25
+ %li
26
+ = link_to "Log in with GMail", "auth/google"
27
+
28
+
13
29
 
14
30
 
@@ -0,0 +1,11 @@
1
+ .container
2
+
3
+ = form_tag oauth_log_in_path(:uid => @uid, :provider => @provider), :class => "form-signin", :method => :post do
4
+ %h2.form-signin-heading Sign up
5
+
6
+ %h4 Tell us your email address please:
7
+
8
+ %div
9
+ = text_field :user, 'Email', :class => "input-block-level", :placeholder => "Email"
10
+
11
+ = submit_tag 'submit', :class => "btn btn-large btn-primary"
data/config/routes.rb CHANGED
@@ -2,10 +2,15 @@ UserMgmt::Engine.routes.draw do
2
2
 
3
3
  get '/log_in' => "sessions#new", as: 'log_in'
4
4
  post '/log_in' => "sessions#create", as: 'user_log_in'
5
- delete '/log_out' => "sessions#destroy", as: 'log_out'
5
+ get '/log_out' => "sessions#destroy", as: 'log_out'
6
+ post '/oauth_log_in' => "sessions#create_oauth", as: 'oauth_log_in'
6
7
 
7
8
  get '/sign_up' => 'registrations#new', as: 'sign_up'
8
9
  get '/edit' => 'registrations#edit', as: 'edit'
9
10
  post '/' => 'registrations#create', as: 'user'
10
11
 
12
+ get 'auth/:provider/callback' => 'sessions#oauth_email', as: 'oauth_email'
13
+ get 'auth/failure' => 'application#main_page'
14
+
15
+
11
16
  end
@@ -3,8 +3,24 @@
3
3
  Some setup you must do manually if you haven't yet:
4
4
 
5
5
  1. Ensure you have defined your external database URI, in
6
- config/initializers/user_mgmt.rb:
6
+ config/initializers/user_mgmt.rb.
7
+ For example:
7
8
 
8
9
  config.external_database_URI = "http://localhost:3000/"
9
10
 
11
+ 2. Ensure you have defined root_url to *something* in your config/routes.rb.
12
+ For example:
13
+
14
+ root :to => "home#index"
15
+
16
+ 3. Ensure you have flash messages in app/views/layouts/application.html.haml.
17
+ For example:
18
+
19
+ %body
20
+ #main
21
+ - if flash[:notice]
22
+ #notice.message= flash[:notice]
23
+ - elsif flash[:warning]
24
+ #warning.message= flash[:warning]
25
+
10
26
  ===============================================================================
@@ -6,4 +6,24 @@ UserMgmt.setup do |config|
6
6
  # authentication won't be possible to happen
7
7
  config.external_database_URI = "http://localhost:3000/"
8
8
 
9
+ # Namespace router name. It is gonna appear in front of every route that the gem generates.
10
+ # If you change this name, you are gonna have to change it as well in your app's routes file:
11
+ # mount UserMgmt::Engine => "/new_name"
12
+ config.router_name = "user/"
13
+
9
14
  end
15
+
16
+ # Edit your strategy keys:
17
+
18
+ ENV['TWITTER_KEY'] = ""
19
+ ENV['TWITTER_SECRET'] = ""
20
+
21
+ ENV['FACEBOOK_KEY'] = ""
22
+ ENV['FACEBOOK_SECRET'] = ""
23
+
24
+ # The code below include the view helpers from user_mgmt in the main app.
25
+ # NOTE: Do not change this code.
26
+ ActiveSupport.on_load :action_controller do
27
+ helper UserMgmt::ApplicationHelper
28
+ end
29
+
@@ -1,6 +1,19 @@
1
1
  module UserMgmt
2
+
2
3
  require "rails"
4
+ require 'omniauth'
5
+ require 'omniauth-facebook'
6
+ require 'omniauth-twitter'
7
+
3
8
  class Engine < ::Rails::Engine
4
9
  isolate_namespace UserMgmt
10
+
11
+ #http://stackoverflow.com/questions/8304225/omniauth-route-issue-related-to-ruby-version
12
+ middleware.use OmniAuth::Builder do
13
+ # provider :developer unless Rails.env.production?
14
+ provider :twitter, ENV['TWITTER_KEY'], ENV['TWITTER_SECRET']
15
+ provider :facebook, ENV['FACEBOOK_KEY'], ENV['FACEBOOK_SECRET']
16
+ end
17
+
5
18
  end
6
19
  end
@@ -1,3 +1,3 @@
1
1
  module UserMgmt
2
- VERSION = "0.0.522"
2
+ VERSION = "0.0.611"
3
3
  end
data/lib/user_mgmt.rb CHANGED
@@ -8,6 +8,10 @@ module UserMgmt
8
8
  mattr_accessor :external_database_URI
9
9
  @@external_database_URI = "http://localhost:3000/"
10
10
 
11
+ # Namespace router name. It is gonna appear in front of every route that the gem generates.
12
+ mattr_accessor :router_name
13
+ @@router_name = "user/"
14
+
11
15
  # Default way to setup UserMgmt. Run rails generate user_mgmt:install to create
12
16
  # a fresh initializer with all configuration values.
13
17
  def self.setup
@@ -0,0 +1,16 @@
1
+ require 'test_helper'
2
+
3
+ module UserMgmt
4
+ class RegistrationsControllerTest < ActionController::TestCase
5
+ test "should get new" do
6
+ get :new
7
+ assert_response :success
8
+ end
9
+
10
+ test "should get create" do
11
+ get :create
12
+ assert_response :success
13
+ end
14
+
15
+ end
16
+ end
@@ -0,0 +1,21 @@
1
+ require 'test_helper'
2
+
3
+ module UserMgmt
4
+ class SessionsControllerTest < ActionController::TestCase
5
+ test "should get new" do
6
+ get :new
7
+ assert_response :success
8
+ end
9
+
10
+ test "should get create" do
11
+ get :create
12
+ assert_response :success
13
+ end
14
+
15
+ test "should get destroy" do
16
+ get :destroy
17
+ assert_response :success
18
+ end
19
+
20
+ end
21
+ end
@@ -0,0 +1,28 @@
1
+ == README
2
+
3
+ This README would normally document whatever steps are necessary to get the
4
+ application up and running.
5
+
6
+ Things you may want to cover:
7
+
8
+ * Ruby version
9
+
10
+ * System dependencies
11
+
12
+ * Configuration
13
+
14
+ * Database creation
15
+
16
+ * Database initialization
17
+
18
+ * How to run the test suite
19
+
20
+ * Services (job queues, cache servers, search engines, etc.)
21
+
22
+ * Deployment instructions
23
+
24
+ * ...
25
+
26
+
27
+ Please feel free to use a different markup language if you do not plan to run
28
+ <tt>rake doc:app</tt>.
@@ -0,0 +1,6 @@
1
+ # Add your own tasks in files placed in lib/tasks ending in .rake,
2
+ # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
3
+
4
+ require File.expand_path('../config/application', __FILE__)
5
+
6
+ Dummy::Application.load_tasks
@@ -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,8 @@
1
+ class ApplicationController < ActionController::Base
2
+ # Prevent CSRF attacks by raising an exception.
3
+ # For APIs, you may want to use :null_session instead.
4
+ protect_from_forgery with: :exception
5
+
6
+ # helper UserMgmt::ApplicationHelper
7
+
8
+ end
@@ -0,0 +1,5 @@
1
+ class SimulateController < ApplicationController
2
+ def index
3
+
4
+ end
5
+ end
@@ -0,0 +1,2 @@
1
+ module ApplicationHelper
2
+ end
@@ -0,0 +1,2 @@
1
+ module SimulateHelper
2
+ end
@@ -0,0 +1,17 @@
1
+ !!! 5
2
+ %html
3
+ %head
4
+
5
+ %title Dummy
6
+ = stylesheet_link_tag "application", media: "all", "data-turbolinks-track" => true
7
+ = javascript_include_tag "application", "data-turbolinks-track" => true
8
+ = csrf_meta_tags
9
+
10
+ %body
11
+ #main
12
+ - if flash[:notice]
13
+ #notice.message= flash[:notice]
14
+ - elsif flash[:warning]
15
+ #warning.message= flash[:warning]
16
+
17
+ = yield
@@ -0,0 +1,15 @@
1
+ %h1 Main Page
2
+ =#debug(session[:user_session_id])
3
+ =#debug(session[:user_session_id] != nil)
4
+ =#debug(user_logged_in)
5
+ %br
6
+ - if user_logged_in
7
+ Logged In
8
+ = link_to "Log Out", user_mgmt.log_out_path
9
+ - else
10
+ Logged Out
11
+ %ul
12
+ %li
13
+ = link_to "Sign up", user_mgmt.sign_up_path
14
+ %li
15
+ = link_to "Log in", user_mgmt.log_in_path
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
3
+ load Gem.bin_path('bundler', 'bundle')
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ APP_PATH = File.expand_path('../../config/application', __FILE__)
3
+ require_relative '../config/boot'
4
+ require 'rails/commands'
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ require_relative '../config/boot'
3
+ require 'rake'
4
+ Rake.application.run
@@ -0,0 +1,23 @@
1
+ require File.expand_path('../boot', __FILE__)
2
+
3
+ require 'rails/all'
4
+
5
+ Bundler.require(*Rails.groups)
6
+ require "user_mgmt"
7
+
8
+ module Dummy
9
+ class Application < Rails::Application
10
+ # Settings in config/environments/* take precedence over those specified here.
11
+ # Application configuration should go into files in config/initializers
12
+ # -- all .rb files in that directory are automatically loaded.
13
+
14
+ # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
15
+ # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
16
+ # config.time_zone = 'Central Time (US & Canada)'
17
+
18
+ # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
19
+ # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
20
+ # config.i18n.default_locale = :de
21
+ end
22
+ end
23
+
@@ -0,0 +1,5 @@
1
+ # Set up gems listed in the Gemfile.
2
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../../../Gemfile', __FILE__)
3
+
4
+ require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE'])
5
+ $LOAD_PATH.unshift File.expand_path('../../../../lib', __FILE__)
@@ -0,0 +1,25 @@
1
+ # SQLite version 3.x
2
+ # gem install sqlite3
3
+ #
4
+ # Ensure the SQLite 3 gem is defined in your Gemfile
5
+ # gem 'sqlite3'
6
+ development:
7
+ adapter: sqlite3
8
+ database: db/development.sqlite3
9
+ pool: 5
10
+ timeout: 5000
11
+
12
+ # Warning: The database defined as "test" will be erased and
13
+ # re-generated from your development database when you run "rake".
14
+ # Do not set this db to the same as development or production.
15
+ test:
16
+ adapter: sqlite3
17
+ database: db/test.sqlite3
18
+ pool: 5
19
+ timeout: 5000
20
+
21
+ production:
22
+ adapter: sqlite3
23
+ database: db/production.sqlite3
24
+ pool: 5
25
+ timeout: 5000