activity_notification 2.0.0 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (195) hide show
  1. checksums.yaml +4 -4
  2. data/.github/ISSUE_TEMPLATE/bug_report.md +22 -0
  3. data/.github/ISSUE_TEMPLATE/feature_request.md +17 -0
  4. data/.github/pull_request_template.md +13 -0
  5. data/.gitignore +10 -3
  6. data/.travis.yml +6 -5
  7. data/CHANGELOG.md +22 -0
  8. data/Gemfile +8 -2
  9. data/Procfile +1 -1
  10. data/README.md +153 -1510
  11. data/activity_notification.gemspec +4 -1
  12. data/app/channels/activity_notification/notification_api_channel.rb +12 -0
  13. data/app/channels/activity_notification/notification_api_with_devise_channel.rb +46 -0
  14. data/app/channels/activity_notification/notification_channel.rb +1 -1
  15. data/app/channels/activity_notification/notification_with_devise_channel.rb +1 -1
  16. data/app/controllers/activity_notification/apidocs_controller.rb +75 -0
  17. data/app/controllers/activity_notification/notifications_api_controller.rb +143 -0
  18. data/app/controllers/activity_notification/notifications_api_with_devise_controller.rb +7 -0
  19. data/app/controllers/activity_notification/notifications_controller.rb +79 -53
  20. data/app/controllers/activity_notification/subscriptions_api_controller.rb +197 -0
  21. data/app/controllers/activity_notification/subscriptions_api_with_devise_controller.rb +7 -0
  22. data/app/controllers/activity_notification/subscriptions_controller.rb +78 -69
  23. data/app/views/activity_notification/notifications/default/_default.html.erb +18 -18
  24. data/app/views/activity_notification/notifications/default/_default_without_grouping.html.erb +14 -14
  25. data/app/views/activity_notification/notifications/default/index.html.erb +6 -6
  26. data/app/views/activity_notification/optional_targets/default/action_cable_channel/_default.html.erb +176 -0
  27. data/app/views/activity_notification/subscriptions/default/_form.html.erb +1 -1
  28. data/app/views/activity_notification/subscriptions/default/_notification_keys.html.erb +3 -31
  29. data/app/views/activity_notification/subscriptions/default/_subscription.html.erb +7 -7
  30. data/app/views/activity_notification/subscriptions/default/index.html.erb +11 -7
  31. data/bin/deploy_on_heroku.sh +3 -1
  32. data/docs/CODE_OF_CONDUCT.md +76 -0
  33. data/docs/CONTRIBUTING.md +36 -0
  34. data/docs/Functions.md +1130 -0
  35. data/docs/Setup.md +674 -0
  36. data/docs/Testing.md +148 -0
  37. data/gemfiles/Gemfile.rails-4.2 +3 -0
  38. data/gemfiles/Gemfile.rails-5.0 +3 -0
  39. data/gemfiles/Gemfile.rails-5.1 +3 -0
  40. data/gemfiles/Gemfile.rails-5.2 +3 -0
  41. data/gemfiles/{Gemfile.rails-6.0.rc → Gemfile.rails-6.0} +5 -3
  42. data/lib/activity_notification.rb +13 -1
  43. data/lib/activity_notification/apis/notification_api.rb +29 -92
  44. data/lib/activity_notification/apis/subscription_api.rb +20 -8
  45. data/lib/activity_notification/apis/swagger.rb +6 -0
  46. data/lib/activity_notification/config.rb +41 -21
  47. data/lib/activity_notification/controllers/common_api_controller.rb +30 -0
  48. data/lib/activity_notification/controllers/common_controller.rb +44 -20
  49. data/lib/activity_notification/controllers/concerns/swagger/error_responses.rb +55 -0
  50. data/lib/activity_notification/controllers/concerns/swagger/notifications_api.rb +273 -0
  51. data/lib/activity_notification/controllers/concerns/swagger/notifications_parameters.rb +92 -0
  52. data/lib/activity_notification/controllers/concerns/swagger/subscriptions_api.rb +405 -0
  53. data/lib/activity_notification/controllers/concerns/swagger/subscriptions_parameters.rb +50 -0
  54. data/lib/activity_notification/controllers/devise_authentication_controller.rb +7 -6
  55. data/lib/activity_notification/gem_version.rb +14 -0
  56. data/lib/activity_notification/helpers/errors.rb +2 -0
  57. data/lib/activity_notification/helpers/view_helpers.rb +4 -0
  58. data/lib/activity_notification/mailers/helpers.rb +17 -10
  59. data/lib/activity_notification/models/concerns/notifiable.rb +26 -10
  60. data/lib/activity_notification/models/concerns/subscriber.rb +12 -1
  61. data/lib/activity_notification/models/concerns/swagger/error_schema.rb +36 -0
  62. data/lib/activity_notification/models/concerns/swagger/notification_schema.rb +209 -0
  63. data/lib/activity_notification/models/concerns/swagger/subscription_schema.rb +162 -0
  64. data/lib/activity_notification/models/concerns/target.rb +36 -10
  65. data/lib/activity_notification/models/notification.rb +1 -0
  66. data/lib/activity_notification/models/subscription.rb +1 -0
  67. data/lib/activity_notification/optional_targets/action_cable_api_channel.rb +69 -0
  68. data/lib/activity_notification/optional_targets/action_cable_channel.rb +68 -0
  69. data/lib/activity_notification/optional_targets/base.rb +7 -13
  70. data/lib/activity_notification/orm/active_record/notification.rb +17 -1
  71. data/lib/activity_notification/orm/active_record/subscription.rb +1 -1
  72. data/lib/activity_notification/orm/dynamoid.rb +28 -0
  73. data/lib/activity_notification/orm/dynamoid/extension.rb +79 -1
  74. data/lib/activity_notification/orm/dynamoid/notification.rb +1 -1
  75. data/lib/activity_notification/orm/dynamoid/subscription.rb +1 -1
  76. data/lib/activity_notification/orm/mongoid.rb +22 -0
  77. data/lib/activity_notification/orm/mongoid/notification.rb +17 -1
  78. data/lib/activity_notification/orm/mongoid/subscription.rb +1 -1
  79. data/lib/activity_notification/rails/routes.rb +132 -48
  80. data/lib/activity_notification/renderable.rb +13 -2
  81. data/lib/activity_notification/roles/acts_as_notifiable.rb +38 -20
  82. data/lib/activity_notification/version.rb +1 -1
  83. data/lib/generators/activity_notification/controllers_generator.rb +2 -1
  84. data/lib/generators/templates/activity_notification.rb +8 -0
  85. data/lib/generators/templates/controllers/notifications_api_controller.rb +31 -0
  86. data/lib/generators/templates/controllers/notifications_api_with_devise_controller.rb +31 -0
  87. data/lib/generators/templates/controllers/notifications_controller.rb +1 -37
  88. data/lib/generators/templates/controllers/notifications_with_devise_controller.rb +1 -45
  89. data/lib/generators/templates/controllers/subscriptions_api_controller.rb +61 -0
  90. data/lib/generators/templates/controllers/subscriptions_api_with_devise_controller.rb +61 -0
  91. data/lib/generators/templates/controllers/subscriptions_controller.rb +14 -37
  92. data/lib/generators/templates/controllers/subscriptions_with_devise_controller.rb +14 -45
  93. data/lib/generators/templates/models/README +8 -4
  94. data/lib/generators/templates/models/notification.rb +1 -1
  95. data/lib/generators/templates/models/subscription.rb +1 -1
  96. data/package.json +8 -0
  97. data/spec/channels/notification_api_channel_shared_examples.rb +59 -0
  98. data/spec/channels/notification_api_channel_spec.rb +51 -0
  99. data/spec/channels/notification_api_with_devise_channel_spec.rb +78 -0
  100. data/spec/concerns/apis/notification_api_spec.rb +37 -2
  101. data/spec/concerns/models/notifiable_spec.rb +64 -0
  102. data/spec/concerns/models/subscriber_spec.rb +13 -16
  103. data/spec/concerns/models/target_spec.rb +32 -0
  104. data/spec/concerns/renderable_spec.rb +2 -2
  105. data/spec/controllers/controller_spec_utility.rb +136 -0
  106. data/spec/controllers/notifications_api_controller_shared_examples.rb +506 -0
  107. data/spec/controllers/notifications_api_controller_spec.rb +19 -0
  108. data/spec/controllers/notifications_api_with_devise_controller_spec.rb +60 -0
  109. data/spec/controllers/notifications_controller_shared_examples.rb +54 -79
  110. data/spec/controllers/notifications_controller_spec.rb +1 -2
  111. data/spec/controllers/notifications_with_devise_controller_spec.rb +3 -12
  112. data/spec/controllers/subscriptions_api_controller_shared_examples.rb +750 -0
  113. data/spec/controllers/subscriptions_api_controller_spec.rb +19 -0
  114. data/spec/controllers/subscriptions_api_with_devise_controller_spec.rb +60 -0
  115. data/spec/controllers/subscriptions_controller_shared_examples.rb +94 -121
  116. data/spec/controllers/subscriptions_controller_spec.rb +1 -2
  117. data/spec/controllers/subscriptions_with_devise_controller_spec.rb +3 -12
  118. data/spec/helpers/view_helpers_spec.rb +4 -11
  119. data/spec/mailers/mailer_spec.rb +41 -0
  120. data/spec/models/notification_spec.rb +17 -0
  121. data/spec/models/subscription_spec.rb +0 -13
  122. data/spec/optional_targets/action_cable_api_channel_spec.rb +37 -0
  123. data/spec/optional_targets/action_cable_channel_spec.rb +44 -0
  124. data/spec/optional_targets/amazon_sns_spec.rb +0 -2
  125. data/spec/optional_targets/slack_spec.rb +0 -2
  126. data/spec/rails_app/Rakefile +9 -0
  127. data/spec/rails_app/app/assets/config/manifest.js +3 -0
  128. data/spec/rails_app/app/assets/images/.keep +0 -0
  129. data/spec/rails_app/app/controllers/admins_controller.rb +21 -0
  130. data/spec/rails_app/app/controllers/application_controller.rb +1 -1
  131. data/spec/rails_app/app/controllers/articles_controller.rb +6 -3
  132. data/spec/rails_app/app/controllers/spa_controller.rb +7 -0
  133. data/spec/rails_app/app/controllers/users/notifications_controller.rb +0 -65
  134. data/spec/rails_app/app/controllers/users/notifications_with_devise_controller.rb +0 -73
  135. data/spec/rails_app/app/controllers/users/subscriptions_controller.rb +0 -77
  136. data/spec/rails_app/app/controllers/users/subscriptions_with_devise_controller.rb +0 -85
  137. data/spec/rails_app/app/controllers/users_controller.rb +21 -0
  138. data/spec/rails_app/app/javascript/App.vue +104 -0
  139. data/spec/rails_app/app/javascript/components/DeviseTokenAuth.vue +83 -0
  140. data/spec/rails_app/app/javascript/components/Top.vue +99 -0
  141. data/spec/rails_app/app/javascript/components/notifications/Index.vue +200 -0
  142. data/spec/rails_app/app/javascript/components/notifications/Notification.vue +133 -0
  143. data/spec/rails_app/app/javascript/components/notifications/NotificationContent.vue +122 -0
  144. data/spec/rails_app/app/javascript/components/subscriptions/Index.vue +279 -0
  145. data/spec/rails_app/app/javascript/components/subscriptions/NewSubscription.vue +112 -0
  146. data/spec/rails_app/app/javascript/components/subscriptions/NotificationKey.vue +141 -0
  147. data/spec/rails_app/app/javascript/components/subscriptions/Subscription.vue +226 -0
  148. data/spec/rails_app/app/javascript/config/development.js +5 -0
  149. data/spec/rails_app/app/javascript/config/environment.js +7 -0
  150. data/spec/rails_app/app/javascript/config/production.js +5 -0
  151. data/spec/rails_app/app/javascript/config/test.js +5 -0
  152. data/spec/rails_app/app/javascript/packs/application.js +18 -0
  153. data/spec/rails_app/app/javascript/packs/spa.js +11 -0
  154. data/spec/rails_app/app/javascript/store/auth.js +37 -0
  155. data/spec/rails_app/app/models/admin.rb +16 -15
  156. data/spec/rails_app/app/models/article.rb +26 -21
  157. data/spec/rails_app/app/models/comment.rb +24 -71
  158. data/spec/rails_app/app/models/user.rb +43 -20
  159. data/spec/rails_app/app/views/activity_notification/notifications/default/article/_update.html.erb +146 -0
  160. data/spec/rails_app/app/views/articles/index.html.erb +51 -7
  161. data/spec/rails_app/app/views/articles/show.html.erb +1 -1
  162. data/spec/rails_app/app/views/layouts/_header.html.erb +8 -10
  163. data/spec/rails_app/app/views/spa/index.html.erb +2 -0
  164. data/spec/rails_app/babel.config.js +72 -0
  165. data/spec/rails_app/bin/webpack +18 -0
  166. data/spec/rails_app/bin/webpack-dev-server +18 -0
  167. data/spec/rails_app/config/application.rb +15 -2
  168. data/spec/rails_app/config/environment.rb +2 -1
  169. data/spec/rails_app/config/environments/development.rb +5 -0
  170. data/spec/rails_app/config/environments/production.rb +3 -0
  171. data/spec/rails_app/config/environments/test.rb +5 -0
  172. data/spec/rails_app/config/initializers/activity_notification.rb +8 -0
  173. data/spec/rails_app/config/initializers/devise_token_auth.rb +55 -0
  174. data/spec/rails_app/config/initializers/mysql.rb +9 -0
  175. data/spec/rails_app/config/locales/activity_notification.en.yml +2 -2
  176. data/spec/rails_app/config/routes.rb +33 -1
  177. data/spec/rails_app/config/webpack/development.js +5 -0
  178. data/spec/rails_app/config/webpack/environment.js +7 -0
  179. data/spec/rails_app/config/webpack/loaders/vue.js +6 -0
  180. data/spec/rails_app/config/webpack/production.js +5 -0
  181. data/spec/rails_app/config/webpack/test.js +5 -0
  182. data/spec/rails_app/config/webpacker.yml +97 -0
  183. data/spec/rails_app/db/migrate/20191201000000_add_tokens_to_users.rb +10 -0
  184. data/spec/rails_app/db/schema.rb +4 -1
  185. data/spec/rails_app/db/seeds.rb +1 -0
  186. data/spec/rails_app/lib/custom_optional_targets/raise_error.rb +14 -0
  187. data/spec/rails_app/package.json +23 -0
  188. data/spec/rails_app/postcss.config.js +12 -0
  189. data/spec/roles/acts_as_group_spec.rb +0 -2
  190. data/spec/roles/acts_as_notifiable_spec.rb +1 -3
  191. data/spec/roles/acts_as_notifier_spec.rb +0 -2
  192. data/spec/roles/acts_as_target_spec.rb +0 -4
  193. data/spec/spec_helper.rb +7 -15
  194. data/spec/version_spec.rb +31 -0
  195. metadata +187 -13
@@ -1,75 +1,2 @@
1
1
  class Users::NotificationsWithDeviseController < ActivityNotification::NotificationsWithDeviseController
2
- # GET /:target_type/:target_id/notifications
3
- # def index
4
- # super
5
- # end
6
-
7
- # POST /:target_type/:target_id/notifications/open_all
8
- # def open_all
9
- # super
10
- # end
11
-
12
- # GET /:target_type/:target_id/notifications/:id
13
- # def show
14
- # super
15
- # end
16
-
17
- # DELETE /:target_type/:target_id/notifications/:id
18
- # def destroy
19
- # super
20
- # end
21
-
22
- # POST /:target_type/:target_id/notifications/:id/open
23
- # def open
24
- # super
25
- # end
26
-
27
- # GET /:target_type/:target_id/notifications/:id/move
28
- # def move
29
- # super
30
- # end
31
-
32
- # No action routing
33
- # This method needs to be public since it is called from view helper
34
- # def target_view_path
35
- # super
36
- # end
37
-
38
- # protected
39
-
40
- # def set_target
41
- # super
42
- # end
43
-
44
- # def set_notification
45
- # super
46
- # end
47
-
48
- # def set_index_options
49
- # super
50
- # end
51
-
52
- # def load_notification_index(options = {})
53
- # super(options)
54
- # end
55
-
56
- # def controller_path
57
- # super
58
- # end
59
-
60
- # def set_view_prefixes
61
- # super
62
- # end
63
-
64
- # def return_back_or_ajax
65
- # super
66
- # end
67
-
68
- # def authenticate_devise_resource!
69
- # super
70
- # end
71
-
72
- # def authenticate_target!
73
- # super
74
- # end
75
2
  end
@@ -1,79 +1,2 @@
1
1
  class Users::SubscriptionsController < ActivityNotification::SubscriptionsController
2
- # GET /:target_type/:target_id/subscriptions
3
- # def index
4
- # super
5
- # end
6
-
7
- # POST /:target_type/:target_id/subscriptions
8
- # def create
9
- # super
10
- # end
11
-
12
- # GET /:target_type/:target_id/subscriptions/:id
13
- # def show
14
- # super
15
- # end
16
-
17
- # DELETE /:target_type/:target_id/subscriptions/:id
18
- # def destroy
19
- # super
20
- # end
21
-
22
- # POST /:target_type/:target_id/subscriptions/:id/subscribe
23
- # def subscribe
24
- # super
25
- # end
26
-
27
- # POST /:target_type/:target_id/subscriptions/:id/unsubscribe
28
- # def unsubscribe
29
- # super
30
- # end
31
-
32
- # POST /:target_type/:target_id/subscriptions/:id/subscribe_to_email
33
- # def subscribe_to_email
34
- # super
35
- # end
36
-
37
- # POST /:target_type/:target_id/subscriptions/:id/unsubscribe_to_email
38
- # def unsubscribe_to_email
39
- # super
40
- # end
41
-
42
- # protected
43
-
44
- # def set_target
45
- # super
46
- # end
47
-
48
- # def set_subscription
49
- # super
50
- # end
51
-
52
- # def subscription_params
53
- # super
54
- # end
55
-
56
- # def set_index_options
57
- # super
58
- # end
59
-
60
- # def load_subscription_index(options = {})
61
- # super(options)
62
- # end
63
-
64
- # def controller_path
65
- # super
66
- # end
67
-
68
- # def target_view_path
69
- # super
70
- # end
71
-
72
- # def set_view_prefixes
73
- # super
74
- # end
75
-
76
- # def return_back_or_ajax
77
- # super
78
- # end
79
2
  end
@@ -1,87 +1,2 @@
1
1
  class Users::SubscriptionsWithDeviseController < ActivityNotification::SubscriptionsWithDeviseController
2
- # GET /:target_type/:target_id/subscriptions
3
- # def index
4
- # super
5
- # end
6
-
7
- # POST /:target_type/:target_id/subscriptions
8
- # def create
9
- # super
10
- # end
11
-
12
- # GET /:target_type/:target_id/subscriptions/:id
13
- # def show
14
- # super
15
- # end
16
-
17
- # DELETE /:target_type/:target_id/subscriptions/:id
18
- # def destroy
19
- # super
20
- # end
21
-
22
- # POST /:target_type/:target_id/subscriptions/:id/subscribe
23
- # def subscribe
24
- # super
25
- # end
26
-
27
- # POST /:target_type/:target_id/subscriptions/:id/unsubscribe
28
- # def unsubscribe
29
- # super
30
- # end
31
-
32
- # POST /:target_type/:target_id/subscriptions/:id/subscribe_to_email
33
- # def subscribe_to_email
34
- # super
35
- # end
36
-
37
- # POST /:target_type/:target_id/subscriptions/:id/unsubscribe_to_email
38
- # def unsubscribe_to_email
39
- # super
40
- # end
41
-
42
- # protected
43
-
44
- # def set_target
45
- # super
46
- # end
47
-
48
- # def set_subscription
49
- # super
50
- # end
51
-
52
- # def subscription_params
53
- # super
54
- # end
55
-
56
- # def set_index_options
57
- # super
58
- # end
59
-
60
- # def load_subscription_index(options = {})
61
- # super(options)
62
- # end
63
-
64
- # def controller_path
65
- # super
66
- # end
67
-
68
- # def target_view_path
69
- # super
70
- # end
71
-
72
- # def set_view_prefixes
73
- # super
74
- # end
75
-
76
- # def return_back_or_ajax
77
- # super
78
- # end
79
-
80
- # def authenticate_devise_resource!
81
- # super
82
- # end
83
-
84
- # def authenticate_target!
85
- # super
86
- # end
87
2
  end
@@ -0,0 +1,21 @@
1
+ class UsersController < ApplicationController
2
+ before_action :set_user, only: [:show]
3
+
4
+ # GET /users
5
+ def index
6
+ render json: {
7
+ users: User.all
8
+ }
9
+ end
10
+
11
+ # GET /users/:id
12
+ def show
13
+ render json: @user
14
+ end
15
+
16
+ private
17
+ # Use callbacks to share common setup or constraints between actions.
18
+ def set_user
19
+ @user = User.find(params[:id])
20
+ end
21
+ end
@@ -0,0 +1,104 @@
1
+ <template>
2
+ <div>
3
+ <router-view />
4
+ </div>
5
+ </template>
6
+
7
+ <script>
8
+ import Vue from 'vue'
9
+ import VueRouter from 'vue-router'
10
+ import VueMoment from 'vue-moment'
11
+ import moment from 'moment-timezone'
12
+ import VuePluralize from 'vue-pluralize'
13
+ import ActionCableVue from 'actioncable-vue'
14
+ import axios from 'axios'
15
+ import env from './config/environment'
16
+ import authStore from "./store/auth"
17
+ import Top from './components/Top.vue'
18
+ import DeviseTokenAuth from './components/DeviseTokenAuth.vue'
19
+ import NotificationsIndex from './components/notifications/Index.vue'
20
+ import SubscriptionsIndex from './components/subscriptions/Index.vue'
21
+
22
+ const router = new VueRouter({
23
+ routes: [
24
+ { path: '/', component: Top },
25
+ { path: '/login', component: DeviseTokenAuth },
26
+ { path: '/logout', component: DeviseTokenAuth, props: { isLogout: true } },
27
+ // Routes for single page application working with activity_notification REST API backend for users
28
+ {
29
+ path: '/notifications',
30
+ name: 'AuthenticatedUserNotificationsIndex',
31
+ component: NotificationsIndex,
32
+ props: () => ({ target_type: 'users', target: authStore.getters.currentUser }),
33
+ meta: { requiresAuth: true }
34
+ },
35
+ {
36
+ path: '/subscriptions',
37
+ name: 'AuthenticatedUserSubscriptionsIndex',
38
+ component: SubscriptionsIndex,
39
+ props: () => ({ target_type: 'users', target: authStore.getters.currentUser }),
40
+ meta: { requiresAuth: true }
41
+ },
42
+ // Routes for single page application working with activity_notification REST API backend for admins
43
+ {
44
+ path: '/admins/notifications',
45
+ name: 'AuthenticatedAdminNotificationsIndex',
46
+ component: NotificationsIndex,
47
+ props: () => ({ target_type: 'admins', targetApiPath: 'admins', target: authStore.getters.currentUser.admin }),
48
+ meta: { requiresAuth: true }
49
+ },
50
+ {
51
+ path: '/admins/subscriptions',
52
+ name: 'AuthenticatedAdminSubscriptionsIndex',
53
+ component: SubscriptionsIndex,
54
+ props: () => ({ target_type: 'admins', targetApiPath: 'admins', target: authStore.getters.currentUser.admin }),
55
+ meta: { requiresAuth: true }
56
+ },
57
+ // Routes for single page application working with activity_notification REST API backend for unauthenticated targets
58
+ {
59
+ path: '/:target_type/:target_id/notifications',
60
+ name: 'UnauthenticatedTargetNotificationsIndex',
61
+ component: NotificationsIndex,
62
+ props : true
63
+ },
64
+ {
65
+ path: '/:target_type/:target_id/subscriptions',
66
+ name: 'UnauthenticatedTargetSubscriptionsIndex',
67
+ component: SubscriptionsIndex,
68
+ props : true
69
+ }
70
+ ]
71
+ })
72
+
73
+ router.beforeEach((to, from, next) => {
74
+ if (to.matched.some(record => record.meta.requiresAuth) && !authStore.getters.userSignedIn) {
75
+ next({ path: '/login', query: { redirect: to.fullPath }});
76
+ } else {
77
+ next();
78
+ }
79
+ })
80
+
81
+ if (authStore.getters.userSignedIn) {
82
+ for (var authHeader of Object.keys(authStore.getters.authHeaders)) {
83
+ axios.defaults.headers.common[authHeader] = authStore.getters.authHeaders[authHeader];
84
+ }
85
+ }
86
+
87
+ Vue.use(VueRouter)
88
+ Vue.use(VueMoment, { moment })
89
+ Vue.use(VuePluralize)
90
+ Vue.use(ActionCableVue, {
91
+ debug: true,
92
+ debugLevel: 'error',
93
+ connectionUrl: env.ACTION_CABLE_CONNECTION_URL,
94
+ connectImmediately: true
95
+ })
96
+
97
+ export default {
98
+ name: 'App',
99
+ router
100
+ }
101
+ </script>
102
+
103
+ <style scoped>
104
+ </style>
@@ -0,0 +1,83 @@
1
+ <template>
2
+ <div id="login">
3
+ <h2>Log in</h2>
4
+ <form class="new_user" @submit.prevent="login">
5
+ <div class="field">
6
+ <label for="user_email">Email</label><br />
7
+ <input v-model="loginParams.email" autofocus="autofocus" autocomplete="email" type="email" value="" name="user[email]" id="user_email" />
8
+ </div>
9
+ <div class="field">
10
+ <label for="user_password">Password</label><br />
11
+ <input v-model="loginParams.password" autocomplete="current-password" type="password" name="user[password]" id="user_password" />
12
+ </div>
13
+ <div class="actions">
14
+ <input type="submit" name="commit" value="Log in" data-disable-with="Log in" />
15
+ </div>
16
+ </form>
17
+ </div>
18
+ </template>
19
+
20
+ <script>
21
+ import axios from 'axios'
22
+ import authStore from "../store/auth"
23
+
24
+ export default {
25
+ name: 'DeviseTokenAuth',
26
+ props: {
27
+ isLogout: {
28
+ type: Boolean,
29
+ default: false
30
+ }
31
+ },
32
+ data () {
33
+ return {
34
+ loginParams: {
35
+ email: "",
36
+ password: ""
37
+ }
38
+ }
39
+ },
40
+ mounted () {
41
+ if (this.isLogout) {
42
+ this.logout();
43
+ }
44
+ },
45
+ methods: {
46
+ login () {
47
+ axios
48
+ .post('/auth/sign_in', { email: this.loginParams.email, password: this.loginParams.password })
49
+ .then(response => {
50
+ if (response.status == 200) {
51
+ let authHeaders = {};
52
+ for (let authHeader of ['access-token', 'client', 'uid']) {
53
+ authHeaders[authHeader] = response.headers[authHeader];
54
+ axios.defaults.headers.common[authHeader] = authHeaders[authHeader];
55
+ }
56
+ authStore.commit('signIn', { user: response.data.data, authHeaders: authHeaders });
57
+ if (this.$route.query.redirect) {
58
+ this.$router.push(this.$route.query.redirect);
59
+ } else {
60
+ this.$router.push('/');
61
+ }
62
+ }
63
+ })
64
+ .catch (error => {
65
+ console.log("Authentication failed");
66
+ if (error.response.status == 401) {
67
+ this.$router.go({path: this.$router.currentRoute.path});
68
+ }
69
+ })
70
+ },
71
+ logout () {
72
+ for (var authHeader of Object.keys(authStore.getters.authHeaders)) {
73
+ delete axios.defaults.headers.common[authHeader];
74
+ }
75
+ authStore.commit('signOut');
76
+ this.$router.push('/');
77
+ }
78
+ }
79
+ }
80
+ </script>
81
+
82
+ <style scoped>
83
+ </style>