infinum_id 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +12 -0
  3. data/.rspec +3 -0
  4. data/.rubocop.yml +40 -0
  5. data/.travis.yml +7 -0
  6. data/CODE_OF_CONDUCT.md +74 -0
  7. data/Gemfile +6 -0
  8. data/Gemfile.lock +262 -0
  9. data/LICENSE.txt +21 -0
  10. data/README.md +43 -0
  11. data/Rakefile +21 -0
  12. data/app/controllers/api/base_controller.rb +6 -0
  13. data/app/controllers/api/webhooks_controller.rb +42 -0
  14. data/app/controllers/infinum_id/application_controller.rb +6 -0
  15. data/app/controllers/infinum_id/users/omniauth_callbacks_controller.rb +30 -0
  16. data/app/controllers/infinum_id/users_controller.rb +9 -0
  17. data/app/helpers/infinum_id/path_helper.rb +7 -0
  18. data/app/mailers/application_mailer.rb +4 -0
  19. data/app/mailers/user_mailer.rb +20 -0
  20. data/app/models/infinum_id/application_record.rb +5 -0
  21. data/app/services/infinum_id/after_user_update.rb +5 -0
  22. data/app/services/infinum_id/requests/invite_sender.rb +90 -0
  23. data/app/services/infinum_id/users/finder.rb +9 -0
  24. data/app/services/infinum_id/users/invite.rb +29 -0
  25. data/app/services/infinum_id/users/updater.rb +31 -0
  26. data/app/views/user_mailer/invite_email.html.erb +8 -0
  27. data/app/views/user_mailer/invite_email.text.erb +5 -0
  28. data/app/views/user_mailer/welcome_email.html.erb +8 -0
  29. data/app/views/user_mailer/welcome_email.text.erb +5 -0
  30. data/app/workers/infinum_id/users/invite_worker.rb +11 -0
  31. data/bin/console +15 -0
  32. data/bin/setup +8 -0
  33. data/config/initializers/devise.rb +22 -0
  34. data/config/initializers/sidekiq.rb +7 -0
  35. data/config/routes.rb +11 -0
  36. data/infinum_id.gemspec +56 -0
  37. data/lib/generators/infinum_id/install_generator.rb +58 -0
  38. data/lib/generators/templates/migration.rb +25 -0
  39. data/lib/generators/templates/user.rb +19 -0
  40. data/lib/infinum_id/engine.rb +4 -0
  41. data/lib/infinum_id/version.rb +3 -0
  42. data/lib/infinum_id.rb +27 -0
  43. metadata +380 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 9d28e226d3fcc54e08082b744b6c40b0b025929e898d050509963234d6c69a6e
4
+ data.tar.gz: 117d6ae1a8a23b3a0fa91995edd8618a5ae5e123a21acaa9db9fdcaedaf9bc15
5
+ SHA512:
6
+ metadata.gz: ab443294be7de525a362096c2ae689aa751f4691fb0c15105a2d9ea0181d04cc1d929b9bfd2b3af475d10126c0b2750752dfd76edc3312f13157275891e6e75e
7
+ data.tar.gz: 2bb9e178d4b4129810d74e717c7fbf1b0ef1599d79f30754694f09e89dfe91801d587a5a371bc9152575b068fb04e82af649e792c126a744abcf1622ca801046
data/.gitignore ADDED
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
12
+ coverage
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,40 @@
1
+ require: rubocop-rspec
2
+
3
+ LineLength:
4
+ Max: 100
5
+
6
+ Documentation:
7
+ Enabled: false
8
+
9
+ FrozenStringLiteralComment:
10
+ Enabled: false
11
+
12
+ WordArray:
13
+ Enabled: false
14
+
15
+ SymbolArray:
16
+ Enabled: false
17
+
18
+ Rails:
19
+ Enabled: true
20
+
21
+ Rails/MultipleExpectations:
22
+ Enabled: false
23
+
24
+ RSpec/ExampleLength:
25
+ Max: 10
26
+
27
+ Style/MutableConstant:
28
+ Enabled: false
29
+
30
+ Metrics/BlockLength:
31
+ Exclude:
32
+ - 'spec/**/*_spec.rb'
33
+
34
+ AllCops:
35
+ Exclude:
36
+ - 'infinum_id.gemspec'
37
+ - 'db/schema.rb'
38
+ - 'db/migrate/*.rb'
39
+ - 'config/**/*.rb'
40
+ - 'spec/rails_app/db/schema.rb'
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.5.1
7
+ before_install: gem install bundler -v 1.16.5
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at dajana.jeroncic@infinum.hr. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in infinum_id.gemspec
6
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,262 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ infinum_id (1.0.0)
5
+ bundler
6
+ devise
7
+ http
8
+ omniauth-infinum_id
9
+ redis
10
+ redis-namespace
11
+ responders
12
+ sidekiq
13
+
14
+ GEM
15
+ remote: https://rubygems.org/
16
+ specs:
17
+ actioncable (5.2.2)
18
+ actionpack (= 5.2.2)
19
+ nio4r (~> 2.0)
20
+ websocket-driver (>= 0.6.1)
21
+ actionmailer (5.2.2)
22
+ actionpack (= 5.2.2)
23
+ actionview (= 5.2.2)
24
+ activejob (= 5.2.2)
25
+ mail (~> 2.5, >= 2.5.4)
26
+ rails-dom-testing (~> 2.0)
27
+ actionpack (5.2.2)
28
+ actionview (= 5.2.2)
29
+ activesupport (= 5.2.2)
30
+ rack (~> 2.0)
31
+ rack-test (>= 0.6.3)
32
+ rails-dom-testing (~> 2.0)
33
+ rails-html-sanitizer (~> 1.0, >= 1.0.2)
34
+ actionview (5.2.2)
35
+ activesupport (= 5.2.2)
36
+ builder (~> 3.1)
37
+ erubi (~> 1.4)
38
+ rails-dom-testing (~> 2.0)
39
+ rails-html-sanitizer (~> 1.0, >= 1.0.3)
40
+ activejob (5.2.2)
41
+ activesupport (= 5.2.2)
42
+ globalid (>= 0.3.6)
43
+ activemodel (5.2.2)
44
+ activesupport (= 5.2.2)
45
+ activerecord (5.2.2)
46
+ activemodel (= 5.2.2)
47
+ activesupport (= 5.2.2)
48
+ arel (>= 9.0)
49
+ activestorage (5.2.2)
50
+ actionpack (= 5.2.2)
51
+ activerecord (= 5.2.2)
52
+ marcel (~> 0.3.1)
53
+ activesupport (5.2.2)
54
+ concurrent-ruby (~> 1.0, >= 1.0.2)
55
+ i18n (>= 0.7, < 2)
56
+ minitest (~> 5.1)
57
+ tzinfo (~> 1.1)
58
+ addressable (2.6.0)
59
+ public_suffix (>= 2.0.2, < 4.0)
60
+ arel (9.0.0)
61
+ bcrypt (3.1.12)
62
+ builder (3.2.3)
63
+ byebug (10.0.2)
64
+ coderay (1.1.2)
65
+ concurrent-ruby (1.1.4)
66
+ connection_pool (2.2.2)
67
+ crack (0.4.3)
68
+ safe_yaml (~> 1.0.0)
69
+ crass (1.0.4)
70
+ devise (4.6.0)
71
+ bcrypt (~> 3.0)
72
+ orm_adapter (~> 0.1)
73
+ railties (>= 4.1.0, < 6.0)
74
+ responders
75
+ warden (~> 1.2.3)
76
+ diff-lcs (1.3)
77
+ docile (1.3.1)
78
+ domain_name (0.5.20180417)
79
+ unf (>= 0.0.5, < 1.0.0)
80
+ erubi (1.8.0)
81
+ factory_bot (5.0.0)
82
+ activesupport (>= 4.2.0)
83
+ factory_bot_rails (5.0.0)
84
+ factory_bot (~> 5.0.0)
85
+ railties (>= 4.2.0)
86
+ faker (1.9.1)
87
+ i18n (>= 0.7)
88
+ faraday (0.15.4)
89
+ multipart-post (>= 1.2, < 3)
90
+ globalid (0.4.2)
91
+ activesupport (>= 4.2.0)
92
+ hashdiff (0.3.8)
93
+ hashie (3.6.0)
94
+ http (4.0.3)
95
+ addressable (~> 2.3)
96
+ http-cookie (~> 1.0)
97
+ http-form_data (~> 2.0)
98
+ http_parser.rb (~> 0.6.0)
99
+ http-cookie (1.0.3)
100
+ domain_name (~> 0.5)
101
+ http-form_data (2.1.1)
102
+ http_parser.rb (0.6.0)
103
+ i18n (1.5.3)
104
+ concurrent-ruby (~> 1.0)
105
+ json (2.1.0)
106
+ jwt (2.1.0)
107
+ loofah (2.2.3)
108
+ crass (~> 1.0.2)
109
+ nokogiri (>= 1.5.9)
110
+ mail (2.7.1)
111
+ mini_mime (>= 0.1.1)
112
+ marcel (0.3.3)
113
+ mimemagic (~> 0.3.2)
114
+ method_source (0.9.2)
115
+ mimemagic (0.3.3)
116
+ mini_mime (1.0.1)
117
+ mini_portile2 (2.4.0)
118
+ minitest (5.11.3)
119
+ multi_json (1.13.1)
120
+ multi_xml (0.6.0)
121
+ multipart-post (2.0.0)
122
+ nio4r (2.3.1)
123
+ nokogiri (1.10.1)
124
+ mini_portile2 (~> 2.4.0)
125
+ oauth2 (1.4.1)
126
+ faraday (>= 0.8, < 0.16.0)
127
+ jwt (>= 1.0, < 3.0)
128
+ multi_json (~> 1.3)
129
+ multi_xml (~> 0.5)
130
+ rack (>= 1.2, < 3)
131
+ omniauth (1.9.0)
132
+ hashie (>= 3.4.6, < 3.7.0)
133
+ rack (>= 1.6.2, < 3)
134
+ omniauth-infinum_id (1.0.0)
135
+ omniauth-oauth2
136
+ omniauth-oauth2 (1.6.0)
137
+ oauth2 (~> 1.1)
138
+ omniauth (~> 1.9)
139
+ orm_adapter (0.5.0)
140
+ pry (0.12.2)
141
+ coderay (~> 1.1.0)
142
+ method_source (~> 0.9.0)
143
+ pry-byebug (3.6.0)
144
+ byebug (~> 10.0)
145
+ pry (~> 0.10)
146
+ pry-rails (0.3.9)
147
+ pry (>= 0.10.4)
148
+ public_suffix (3.0.3)
149
+ rack (2.0.6)
150
+ rack-protection (2.0.5)
151
+ rack
152
+ rack-test (1.1.0)
153
+ rack (>= 1.0, < 3)
154
+ rails (5.2.2)
155
+ actioncable (= 5.2.2)
156
+ actionmailer (= 5.2.2)
157
+ actionpack (= 5.2.2)
158
+ actionview (= 5.2.2)
159
+ activejob (= 5.2.2)
160
+ activemodel (= 5.2.2)
161
+ activerecord (= 5.2.2)
162
+ activestorage (= 5.2.2)
163
+ activesupport (= 5.2.2)
164
+ bundler (>= 1.3.0)
165
+ railties (= 5.2.2)
166
+ sprockets-rails (>= 2.0.0)
167
+ rails-dom-testing (2.0.3)
168
+ activesupport (>= 4.2.0)
169
+ nokogiri (>= 1.6)
170
+ rails-html-sanitizer (1.0.4)
171
+ loofah (~> 2.2, >= 2.2.2)
172
+ railties (5.2.2)
173
+ actionpack (= 5.2.2)
174
+ activesupport (= 5.2.2)
175
+ method_source
176
+ rake (>= 0.8.7)
177
+ thor (>= 0.19.0, < 2.0)
178
+ rake (10.5.0)
179
+ redis (4.1.0)
180
+ redis-namespace (1.6.0)
181
+ redis (>= 3.0.4)
182
+ responders (2.4.1)
183
+ actionpack (>= 4.2.0, < 6.0)
184
+ railties (>= 4.2.0, < 6.0)
185
+ rspec (3.8.0)
186
+ rspec-core (~> 3.8.0)
187
+ rspec-expectations (~> 3.8.0)
188
+ rspec-mocks (~> 3.8.0)
189
+ rspec-core (3.8.0)
190
+ rspec-support (~> 3.8.0)
191
+ rspec-expectations (3.8.2)
192
+ diff-lcs (>= 1.2.0, < 2.0)
193
+ rspec-support (~> 3.8.0)
194
+ rspec-mocks (3.8.0)
195
+ diff-lcs (>= 1.2.0, < 2.0)
196
+ rspec-support (~> 3.8.0)
197
+ rspec-rails (3.8.2)
198
+ actionpack (>= 3.0)
199
+ activesupport (>= 3.0)
200
+ railties (>= 3.0)
201
+ rspec-core (~> 3.8.0)
202
+ rspec-expectations (~> 3.8.0)
203
+ rspec-mocks (~> 3.8.0)
204
+ rspec-support (~> 3.8.0)
205
+ rspec-support (3.8.0)
206
+ safe_yaml (1.0.4)
207
+ sidekiq (5.2.5)
208
+ connection_pool (~> 2.2, >= 2.2.2)
209
+ rack (>= 1.5.0)
210
+ rack-protection (>= 1.5.0)
211
+ redis (>= 3.3.5, < 5)
212
+ simplecov (0.16.1)
213
+ docile (~> 1.1)
214
+ json (>= 1.8, < 3)
215
+ simplecov-html (~> 0.10.0)
216
+ simplecov-html (0.10.2)
217
+ sprockets (3.7.2)
218
+ concurrent-ruby (~> 1.0)
219
+ rack (> 1, < 3)
220
+ sprockets-rails (3.2.1)
221
+ actionpack (>= 4.0)
222
+ activesupport (>= 4.0)
223
+ sprockets (>= 3.0.0)
224
+ sqlite3 (1.3.13)
225
+ thor (0.20.3)
226
+ thread_safe (0.3.6)
227
+ tzinfo (1.2.5)
228
+ thread_safe (~> 0.1)
229
+ unf (0.1.4)
230
+ unf_ext
231
+ unf_ext (0.0.7.5)
232
+ warden (1.2.8)
233
+ rack (>= 2.0.6)
234
+ webmock (3.5.1)
235
+ addressable (>= 2.3.6)
236
+ crack (>= 0.3.2)
237
+ hashdiff
238
+ websocket-driver (0.7.0)
239
+ websocket-extensions (>= 0.1.0)
240
+ websocket-extensions (0.1.3)
241
+
242
+ PLATFORMS
243
+ ruby
244
+
245
+ DEPENDENCIES
246
+ bundler
247
+ factory_bot_rails
248
+ faker
249
+ infinum_id!
250
+ pry
251
+ pry-byebug
252
+ pry-rails
253
+ rails
254
+ rake (~> 10.0)
255
+ rspec (~> 3.0)
256
+ rspec-rails
257
+ simplecov
258
+ sqlite3
259
+ webmock
260
+
261
+ BUNDLED WITH
262
+ 2.0.1
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Dajana Jeroncic
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,43 @@
1
+ # InfinumId
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/infinum_id`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'infinum_id'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install infinum_id
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/infinum_id. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
36
+
37
+ ## License
38
+
39
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
40
+
41
+ ## Code of Conduct
42
+
43
+ Everyone interacting in the InfinumId project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/infinum_id/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,21 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+ #
7
+ APP_RAKEFILE = File.expand_path("spec/rails_app/Rakefile", __dir__)
8
+ load 'rails/tasks/engine.rake'
9
+
10
+ load 'rails/tasks/statistics.rake'
11
+
12
+ require 'bundler/gem_tasks'
13
+
14
+ # require 'rake/testtask'
15
+ require "rspec/core/rake_task"
16
+
17
+ RSpec::Core::RakeTask.new(:spec) do |spec|
18
+ spec.pattern = 'spec/**/*spec.rb'
19
+ end
20
+
21
+ task default: :spec
@@ -0,0 +1,6 @@
1
+ module Api
2
+ class BaseController < ActionController::Base
3
+ protect_from_forgery with: :null_session
4
+ respond_to :json
5
+ end
6
+ end
@@ -0,0 +1,42 @@
1
+ module Api
2
+ class WebhooksController < Api::BaseController
3
+ def update_user_callback
4
+ return render_not_found unless user
5
+
6
+ user.update(user_params)
7
+ InfinumId::AfterUserUpdate.call(user, params[:user])
8
+
9
+ render json: { user: 'updated' }
10
+ end
11
+
12
+ def create_user_callback
13
+ return render_already_exists if user
14
+
15
+ user = User.create(user_params.merge(provider: params[:provider]))
16
+ InfinumId::AfterUserUpdate.call(user, params[:user])
17
+
18
+ render json: { user: 'created' }
19
+ end
20
+
21
+ private
22
+
23
+ def user_params
24
+ params.require(:user).permit(
25
+ :uid, :email, :first_name, :last_name, :slack_username,
26
+ :time_zone, :deactivated_at, :avatar_url
27
+ )
28
+ end
29
+
30
+ def user
31
+ @user ||= User.find_by(uid: user_params[:uid])
32
+ end
33
+
34
+ def render_not_found
35
+ render json: { user: 'not found' }, status: :not_found
36
+ end
37
+
38
+ def render_already_exists
39
+ render json: { user: 'already exists' }, status: :unprocessable_entity
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,6 @@
1
+ module InfinumId
2
+ class ApplicationController < ActionController::Base
3
+ protect_from_forgery with: :exception
4
+ respond_to :html
5
+ end
6
+ end
@@ -0,0 +1,30 @@
1
+ module InfinumId
2
+ module Users
3
+ class OmniauthCallbacksController < Devise::OmniauthCallbacksController
4
+ def infinum_id
5
+ user = InfinumId::Users::Finder.from_omniauth(omniauth)
6
+
7
+ if user
8
+ InfinumId::Users::Updater.call(omniauth['info'], user)
9
+ flash[:notice] = I18n.t 'devise.omniauth_callbacks.success', kind: 'InfinumId'
10
+ sign_in_and_redirect user, event: :authentication
11
+ else
12
+ flash[:notice] = 'You do not have permission to access this application.'
13
+ redirect_to root_path
14
+ end
15
+ end
16
+
17
+ def failure
18
+ set_flash_message! :alert, :failure, kind: OmniAuth::Utils.camelize(failed_strategy.name),
19
+ reason: failure_message
20
+ redirect_to root_path
21
+ end
22
+
23
+ private
24
+
25
+ def omniauth
26
+ @omniauth ||= request.env['omniauth.auth']
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,9 @@
1
+ module InfinumId
2
+ class UsersController < ApplicationController
3
+ def destroy
4
+ sign_out current_user
5
+
6
+ redirect_to root_path
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,7 @@
1
+ module InfinumId
2
+ module PathHelper
3
+ def infinum_id_profile_edit_path
4
+ "#{InfinumId.url}/profile"
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,4 @@
1
+ class ApplicationMailer < ActionMailer::Base
2
+ default from: 'from@example.com'
3
+ layout 'mailer'
4
+ end
@@ -0,0 +1,20 @@
1
+ class UserMailer < ApplicationMailer
2
+ before_action :load_params
3
+
4
+ def welcome_email
5
+ mail(to: @user.email, subject: "Welcome to #{@service_name}")
6
+ end
7
+
8
+ def invite_email
9
+ @accept_path = params[:accept_path]
10
+
11
+ mail(to: @user.email, subject: "Invite to #{@service_name}")
12
+ end
13
+
14
+ def load_params
15
+ @user = User.find(params[:user_id])
16
+ @invited_by = User.find_by(uid: params[:invited_by_uid])
17
+ @service_name = Rails.configuration.name
18
+ @service_url = Rails.configuration.host_url
19
+ end
20
+ end
@@ -0,0 +1,5 @@
1
+ module InfinumId
2
+ class ApplicationRecord < ActiveRecord::Base
3
+ self.abstract_class = true
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ module InfinumId
2
+ class AfterUserUpdate
3
+ def self.call(user); end
4
+ end
5
+ end