cm-devise_token_auth 0.1.30.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (117) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +13 -0
  3. data/README.md +688 -0
  4. data/Rakefile +34 -0
  5. data/app/controllers/devise_token_auth/application_controller.rb +17 -0
  6. data/app/controllers/devise_token_auth/concerns/set_user_by_token.rb +109 -0
  7. data/app/controllers/devise_token_auth/confirmations_controller.rb +31 -0
  8. data/app/controllers/devise_token_auth/omniauth_callbacks_controller.rb +171 -0
  9. data/app/controllers/devise_token_auth/passwords_controller.rb +155 -0
  10. data/app/controllers/devise_token_auth/registrations_controller.rb +123 -0
  11. data/app/controllers/devise_token_auth/sessions_controller.rb +98 -0
  12. data/app/controllers/devise_token_auth/token_validations_controller.rb +23 -0
  13. data/app/models/devise_token_auth/concerns/user.rb +231 -0
  14. data/app/views/devise/mailer/confirmation_instructions.html.erb +5 -0
  15. data/app/views/devise/mailer/reset_password_instructions.html.erb +8 -0
  16. data/app/views/devise/mailer/unlock_instructions.html.erb +7 -0
  17. data/app/views/devise_token_auth/omniauth_failure.html.erb +2 -0
  18. data/app/views/devise_token_auth/omniauth_success.html.erb +8 -0
  19. data/app/views/layouts/omniauth_response.html.erb +31 -0
  20. data/config/initializers/devise.rb +203 -0
  21. data/config/locales/devise.en.yml +59 -0
  22. data/config/routes.rb +5 -0
  23. data/lib/devise_token_auth.rb +7 -0
  24. data/lib/devise_token_auth/controllers/helpers.rb +129 -0
  25. data/lib/devise_token_auth/controllers/url_helpers.rb +8 -0
  26. data/lib/devise_token_auth/engine.rb +25 -0
  27. data/lib/devise_token_auth/rails/routes.rb +65 -0
  28. data/lib/devise_token_auth/version.rb +3 -0
  29. data/lib/generators/devise_token_auth/USAGE +31 -0
  30. data/lib/generators/devise_token_auth/install_generator.rb +115 -0
  31. data/lib/generators/devise_token_auth/install_views_generator.rb +16 -0
  32. data/lib/generators/devise_token_auth/templates/devise_token_auth.rb +22 -0
  33. data/lib/generators/devise_token_auth/templates/devise_token_auth_create_users.rb.erb +54 -0
  34. data/lib/generators/devise_token_auth/templates/user.rb +3 -0
  35. data/lib/tasks/devise_token_auth_tasks.rake +4 -0
  36. data/test/controllers/demo_group_controller_test.rb +126 -0
  37. data/test/controllers/demo_mang_controller_test.rb +263 -0
  38. data/test/controllers/demo_user_controller_test.rb +262 -0
  39. data/test/controllers/devise_token_auth/confirmations_controller_test.rb +107 -0
  40. data/test/controllers/devise_token_auth/omniauth_callbacks_controller_test.rb +167 -0
  41. data/test/controllers/devise_token_auth/passwords_controller_test.rb +287 -0
  42. data/test/controllers/devise_token_auth/registrations_controller_test.rb +458 -0
  43. data/test/controllers/devise_token_auth/sessions_controller_test.rb +221 -0
  44. data/test/controllers/overrides/confirmations_controller_test.rb +44 -0
  45. data/test/controllers/overrides/omniauth_callbacks_controller_test.rb +44 -0
  46. data/test/controllers/overrides/passwords_controller_test.rb +62 -0
  47. data/test/controllers/overrides/registrations_controller_test.rb +40 -0
  48. data/test/controllers/overrides/sessions_controller_test.rb +33 -0
  49. data/test/controllers/overrides/token_validations_controller_test.rb +38 -0
  50. data/test/dummy/README.rdoc +28 -0
  51. data/test/dummy/Rakefile +6 -0
  52. data/test/dummy/app/assets/images/logo.jpg +0 -0
  53. data/test/dummy/app/assets/images/omniauth-provider-settings.png +0 -0
  54. data/test/dummy/app/assets/javascripts/application.js +13 -0
  55. data/test/dummy/app/assets/stylesheets/application.css +15 -0
  56. data/test/dummy/app/controllers/application_controller.rb +16 -0
  57. data/test/dummy/app/controllers/demo_group_controller.rb +13 -0
  58. data/test/dummy/app/controllers/demo_mang_controller.rb +12 -0
  59. data/test/dummy/app/controllers/demo_user_controller.rb +12 -0
  60. data/test/dummy/app/controllers/overrides/confirmations_controller.rb +32 -0
  61. data/test/dummy/app/controllers/overrides/omniauth_callbacks_controller.rb +14 -0
  62. data/test/dummy/app/controllers/overrides/passwords_controller.rb +39 -0
  63. data/test/dummy/app/controllers/overrides/registrations_controller.rb +27 -0
  64. data/test/dummy/app/controllers/overrides/sessions_controller.rb +43 -0
  65. data/test/dummy/app/controllers/overrides/token_validations_controller.rb +23 -0
  66. data/test/dummy/app/helpers/application_helper.rb +1065 -0
  67. data/test/dummy/app/models/evil_user.rb +3 -0
  68. data/test/dummy/app/models/mang.rb +3 -0
  69. data/test/dummy/app/models/user.rb +18 -0
  70. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  71. data/test/dummy/bin/bundle +3 -0
  72. data/test/dummy/bin/rails +8 -0
  73. data/test/dummy/bin/rake +8 -0
  74. data/test/dummy/bin/spring +18 -0
  75. data/test/dummy/config.ru +16 -0
  76. data/test/dummy/config/application.rb +23 -0
  77. data/test/dummy/config/application.yml.bk +0 -0
  78. data/test/dummy/config/boot.rb +5 -0
  79. data/test/dummy/config/database.yml +31 -0
  80. data/test/dummy/config/environment.rb +5 -0
  81. data/test/dummy/config/environments/development.rb +44 -0
  82. data/test/dummy/config/environments/production.rb +82 -0
  83. data/test/dummy/config/environments/test.rb +40 -0
  84. data/test/dummy/config/initializers/assets.rb +8 -0
  85. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  86. data/test/dummy/config/initializers/cookies_serializer.rb +3 -0
  87. data/test/dummy/config/initializers/devise_token_auth.rb +22 -0
  88. data/test/dummy/config/initializers/figaro.rb +1 -0
  89. data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  90. data/test/dummy/config/initializers/inflections.rb +16 -0
  91. data/test/dummy/config/initializers/mime_types.rb +4 -0
  92. data/test/dummy/config/initializers/omniauth.rb +8 -0
  93. data/test/dummy/config/initializers/session_store.rb +3 -0
  94. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  95. data/test/dummy/config/locales/en.yml +23 -0
  96. data/test/dummy/config/routes.rb +30 -0
  97. data/test/dummy/config/secrets.yml +22 -0
  98. data/test/dummy/config/spring.rb +1 -0
  99. data/test/dummy/db/migrate/20140715061447_devise_token_auth_create_users.rb +56 -0
  100. data/test/dummy/db/migrate/20140715061805_devise_token_auth_create_mangs.rb +56 -0
  101. data/test/dummy/db/migrate/20140829044006_add_operating_thetan_to_user.rb +6 -0
  102. data/test/dummy/db/migrate/20140916224624_add_favorite_color_to_mangs.rb +5 -0
  103. data/test/dummy/db/migrate/20140928231203_devise_token_auth_create_evil_users.rb +57 -0
  104. data/test/dummy/db/schema.rb +114 -0
  105. data/test/dummy/public/404.html +67 -0
  106. data/test/dummy/public/422.html +67 -0
  107. data/test/dummy/public/500.html +66 -0
  108. data/test/dummy/public/favicon.ico +0 -0
  109. data/test/fixtures/evil_users.yml +29 -0
  110. data/test/fixtures/mangs.yml +29 -0
  111. data/test/fixtures/users.yml +29 -0
  112. data/test/integration/navigation_test.rb +10 -0
  113. data/test/lib/generators/devise_token_auth/install_generator_test.rb +178 -0
  114. data/test/lib/generators/devise_token_auth/install_views_generator_test.rb +23 -0
  115. data/test/models/user_test.rb +90 -0
  116. data/test/test_helper.rb +60 -0
  117. metadata +310 -0
@@ -0,0 +1,5 @@
1
+ <p>Welcome <%= @email %>!</p>
2
+
3
+ <p>You can confirm your account email through the link below:</p>
4
+
5
+ <p><%= link_to 'Confirm my account', confirmation_url(@resource, confirmation_token: @token, config: message['client-config'].to_s, redirect_url: message['redirect-url']) %></p>
@@ -0,0 +1,8 @@
1
+ <p>Hello <%= @resource.email %>!</p>
2
+
3
+ <p>Someone has requested a link to change your password. You can do this through the link below.</p>
4
+
5
+ <p><%= link_to 'Change my password', edit_password_url(@resource, reset_password_token: @token, config: message['client-config'].to_s, redirect_url: message['redirect-url'].to_s) %></p>
6
+
7
+ <p>If you didn't request this, please ignore this email.</p>
8
+ <p>Your password won't change until you access the link above and create a new one.</p>
@@ -0,0 +1,7 @@
1
+ <p>Hello <%= @resource.email %>!</p>
2
+
3
+ <p>Your account has been locked due to an excessive number of unsuccessful sign in attempts.</p>
4
+
5
+ <p>Click the link below to unlock your account:</p>
6
+
7
+ <p><%= link_to 'Unlock my account', unlock_url(@resource, unlock_token: @token) %></p>
@@ -0,0 +1,2 @@
1
+ message: "authFailure",
2
+ error: "<%= @error %>"
@@ -0,0 +1,8 @@
1
+ <% @resource.as_json.each do |attr, val| %>
2
+ "<%= attr %>": "<%= val %>",
3
+ <% end %>
4
+
5
+ "auth_token": "<%= @token %>",
6
+ "message": "deliverCredentials",
7
+ "client_id": "<%= @client_id %>",
8
+ "expiry": "<%= @expiry %>"
@@ -0,0 +1,31 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <script>
5
+ var usingExternalWindow = function() {
6
+ var nav = navigator.userAgent.toLowerCase(),
7
+ ieLTE10 = (nav && nav.indexOf('msie') != -1),
8
+ ie11 = !!navigator.userAgent.match(/Trident.*rv\:11\./);
9
+ return !(ieLTE10 || ie11);
10
+ }
11
+
12
+ if (usingExternalWindow()) {
13
+ window.addEventListener("message", function(ev) {
14
+ if (ev.data === "requestCredentials") {
15
+ ev.source.postMessage({
16
+ <%= yield %>
17
+ }, '*');
18
+ window.close();
19
+ }
20
+ });
21
+ } else {
22
+ window.location.href = "<%= @auth_origin_url %>";
23
+ }
24
+ </script>
25
+ </head>
26
+ <body>
27
+ <pre>
28
+ Redirecting...
29
+ </pre>
30
+ </body>
31
+ </html>
@@ -0,0 +1,203 @@
1
+ # Use this hook to configure devise mailer, warden hooks and so forth.
2
+ # Many of these configuration options can be set straight in your model.
3
+ Devise.setup do |config|
4
+ # The secret key used by Devise. Devise uses this key to generate
5
+ # random tokens. Changing this key will render invalid all existing
6
+ # confirmation, reset password and unlock tokens in the database.
7
+ # config.secret_key = 'd029dbc7262359b4f9906ec029bae825981dee112d9a1425643719765c8fd4884f12a37add35607fa3fa2d6fa6945a0077d7fe0f10a67f8ee66d69e9cc6ac19b'
8
+
9
+ # ==> Mailer Configuration
10
+ # Configure the e-mail address which will be shown in Devise::Mailer,
11
+ # note that it will be overwritten if you use your own mailer class
12
+ # with default "from" parameter.
13
+ config.mailer_sender = 'please-change-me-at-config-initializers-devise@example.com'
14
+
15
+ # Configure the class responsible to send e-mails.
16
+ # config.mailer = 'Devise::Mailer'
17
+
18
+ # ==> ORM configuration
19
+ # Load and configure the ORM. Supports :active_record (default) and
20
+ # :mongoid (bson_ext recommended) by default. Other ORMs may be
21
+ # available as additional gems.
22
+ require 'devise/orm/active_record'
23
+
24
+ # ==> Configuration for any authentication mechanism
25
+ # Configure which keys are used when authenticating a user. The default is
26
+ # just :email. You can configure it to use [:username, :subdomain], so for
27
+ # authenticating a user, both parameters are required. Remember that those
28
+ # parameters are used only when authenticating and not when retrieving from
29
+ # session. If you need permissions, you should implement that in a before filter.
30
+ # You can also supply a hash where the value is a boolean determining whether
31
+ # or not authentication should be aborted when the value is not present.
32
+ # config.authentication_keys = [ :email ]
33
+
34
+ # Configure parameters from the request object used for authentication. Each entry
35
+ # given should be a request method and it will automatically be passed to the
36
+ # find_for_authentication method and considered in your model lookup. For instance,
37
+ # if you set :request_keys to [:subdomain], :subdomain will be used on authentication.
38
+ # The same considerations mentioned for authentication_keys also apply to request_keys.
39
+ # config.request_keys = []
40
+
41
+ # Configure which authentication keys should be case-insensitive.
42
+ # These keys will be downcased upon creating or modifying a user and when used
43
+ # to authenticate or find a user. Default is :email.
44
+ config.case_insensitive_keys = [ :email ]
45
+
46
+ # Configure which authentication keys should have whitespace stripped.
47
+ # These keys will have whitespace before and after removed upon creating or
48
+ # modifying a user and when used to authenticate or find a user. Default is :email.
49
+ config.strip_whitespace_keys = [ :email ]
50
+
51
+ # Tell if authentication through request.params is enabled. True by default.
52
+ # It can be set to an array that will enable params authentication only for the
53
+ # given strategies, for example, `config.params_authenticatable = [:database]` will
54
+ # enable it only for database (email + password) authentication.
55
+ # config.params_authenticatable = true
56
+
57
+ # Tell if authentication through HTTP Auth is enabled. False by default.
58
+ # It can be set to an array that will enable http authentication only for the
59
+ # given strategies, for example, `config.http_authenticatable = [:database]` will
60
+ # enable it only for database authentication. The supported strategies are:
61
+ # :database = Support basic authentication with authentication key + password
62
+ # config.http_authenticatable = false
63
+
64
+ # If http headers should be returned for AJAX requests. True by default.
65
+ # config.http_authenticatable_on_xhr = true
66
+
67
+ # The realm used in Http Basic Authentication. 'Application' by default.
68
+ # config.http_authentication_realm = 'Application'
69
+
70
+ # It will change confirmation, password recovery and other workflows
71
+ # to behave the same regardless if the e-mail provided was right or wrong.
72
+ # Does not affect registerable.
73
+ # config.paranoid = true
74
+
75
+ # By default Devise will store the user in session. You can skip storage for
76
+ # particular strategies by setting this option.
77
+ # Notice that if you are skipping storage for all authentication paths, you
78
+ # may want to disable generating routes to Devise's sessions controller by
79
+ # passing skip: :sessions to `devise_for` in your config/routes.rb
80
+ config.skip_session_storage = [:http_auth]
81
+
82
+ # By default, Devise cleans up the CSRF token on authentication to
83
+ # avoid CSRF token fixation attacks. This means that, when using AJAX
84
+ # requests for sign in and sign up, you need to get a new CSRF token
85
+ # from the server. You can disable this option at your own risk.
86
+ # config.clean_up_csrf_token_on_authentication = true
87
+
88
+ # ==> Configuration for :database_authenticatable
89
+ # For bcrypt, this is the cost for hashing the password and defaults to 10. If
90
+ # using other encryptors, it sets how many times you want the password re-encrypted.
91
+ #
92
+ # Limiting the stretches to just one in testing will increase the performance of
93
+ # your test suite dramatically. However, it is STRONGLY RECOMMENDED to not use
94
+ # a value less than 10 in other environments. Note that, for bcrypt (the default
95
+ # encryptor), the cost increases exponentially with the number of stretches (e.g.
96
+ # a value of 20 is already extremely slow: approx. 60 seconds for 1 calculation).
97
+ config.stretches = Rails.env.test? ? 1 : 10
98
+
99
+ # Setup a pepper to generate the encrypted password.
100
+ # config.pepper = '8ff086600aff82d68ff1e00d23c99c821e66652ec8c2a5b48f58de4a56b325cb532f6db660cf58fc5ecb473b9d851be8cd1badff0a1053bc9dc045f78b6e6772'
101
+
102
+ # ==> Configuration for :confirmable
103
+ # A period that the user is allowed to access the website even without
104
+ # confirming their account. For instance, if set to 2.days, the user will be
105
+ # able to access the website for two days without confirming their account,
106
+ # access will be blocked just in the third day. Default is 0.days, meaning
107
+ # the user cannot access the website without confirming their account.
108
+ # config.allow_unconfirmed_access_for = 2.days
109
+
110
+ # A period that the user is allowed to confirm their account before their
111
+ # token becomes invalid. For example, if set to 3.days, the user can confirm
112
+ # their account within 3 days after the mail was sent, but on the fourth day
113
+ # their account can't be confirmed with the token any more.
114
+ # Default is nil, meaning there is no restriction on how long a user can take
115
+ # before confirming their account.
116
+ # config.confirm_within = 3.days
117
+
118
+ # If true, requires any email changes to be confirmed (exactly the same way as
119
+ # initial account confirmation) to be applied. Requires additional unconfirmed_email
120
+ # db field (see migrations). Until confirmed, new email is stored in
121
+ # unconfirmed_email column, and copied to email column on successful confirmation.
122
+ config.reconfirmable = true
123
+
124
+ # Defines which key will be used when confirming an account
125
+ # config.confirmation_keys = [ :email ]
126
+
127
+ # ==> Configuration for :rememberable
128
+ # The time the user will be remembered without asking for credentials again.
129
+ # config.remember_for = 2.weeks
130
+
131
+ # If true, extends the user's remember period when remembered via cookie.
132
+ # config.extend_remember_period = false
133
+
134
+ # Options to be passed to the created cookie. For instance, you can set
135
+ # secure: true in order to force SSL only cookies.
136
+ # config.rememberable_options = {}
137
+
138
+ # ==> Configuration for :validatable
139
+ # Range for password length.
140
+ config.password_length = 8..128
141
+
142
+ # Email regex used to validate email formats. It simply asserts that
143
+ # one (and only one) @ exists in the given string. This is mainly
144
+ # to give user feedback and not to assert the e-mail validity.
145
+ # config.email_regexp = /\A[^@]+@[^@]+\z/
146
+
147
+ # ==> Configuration for :timeoutable
148
+ # The time you want to timeout the user session without activity. After this
149
+ # time the user will be asked for credentials again. Default is 30 minutes.
150
+ # config.timeout_in = 30.minutes
151
+
152
+ # If true, expires auth token on session timeout.
153
+ # config.expire_auth_token_on_timeout = false
154
+
155
+ # ==> Configuration for :lockable
156
+ # Defines which strategy will be used to lock an account.
157
+ # :failed_attempts = Locks an account after a number of failed attempts to sign in.
158
+ # :none = No lock strategy. You should handle locking by yourself.
159
+ # config.lock_strategy = :failed_attempts
160
+
161
+ # Defines which key will be used when locking and unlocking an account
162
+ # config.unlock_keys = [ :email ]
163
+
164
+ # Defines which strategy will be used to unlock an account.
165
+ # :email = Sends an unlock link to the user email
166
+ # :time = Re-enables login after a certain amount of time (see :unlock_in below)
167
+ # :both = Enables both strategies
168
+ # :none = No unlock strategy. You should handle unlocking by yourself.
169
+ # config.unlock_strategy = :both
170
+
171
+ # Number of authentication tries before locking an account if lock_strategy
172
+ # is failed attempts.
173
+ # config.maximum_attempts = 20
174
+
175
+ # Time interval to unlock the account if :time is enabled as unlock_strategy.
176
+ # config.unlock_in = 1.hour
177
+
178
+ # Warn on the last attempt before the account is locked.
179
+ # config.last_attempt_warning = false
180
+
181
+ # ==> Configuration for :recoverable
182
+ #
183
+ # Defines which key will be used when recovering the password for an account
184
+ # config.reset_password_keys = [ :email ]
185
+
186
+ # Time interval you can reset your password with a reset password key.
187
+ # Don't put a too small interval or your users won't have the time to
188
+ # change their passwords.
189
+ config.reset_password_within = 6.hours
190
+
191
+ # The default HTTP method used to sign out a resource. Default is :delete.
192
+ config.sign_out_via = :delete
193
+
194
+ # don't serialize tokens
195
+ Devise::Models::Authenticatable::BLACKLIST_FOR_SERIALIZATION << :tokens
196
+
197
+ # mounted routes will point to this
198
+ Rails.application.config.after_initialize do
199
+ if defined?(::OmniAuth)
200
+ ::OmniAuth::config.path_prefix = config.omniauth_path_prefix = DeviseTokenAuth.omniauth_prefix
201
+ end
202
+ end
203
+ end
@@ -0,0 +1,59 @@
1
+ # Additional translations at https://github.com/plataformatec/devise/wiki/I18n
2
+
3
+ en:
4
+ devise:
5
+ confirmations:
6
+ confirmed: "Your account was successfully confirmed."
7
+ send_instructions: "You will receive an email with instructions about how to confirm your account in a few minutes."
8
+ send_paranoid_instructions: "If your email address exists in our database, you will receive an email with instructions about how to confirm your account in a few minutes."
9
+ failure:
10
+ already_authenticated: "You are already signed in."
11
+ inactive: "Your account is not activated yet."
12
+ invalid: "Invalid email or password."
13
+ locked: "Your account is locked."
14
+ last_attempt: "You have one more attempt before your account will be locked."
15
+ not_found_in_database: "Invalid email or password."
16
+ timeout: "Your session expired. Please sign in again to continue."
17
+ unauthenticated: "You need to sign in or sign up before continuing."
18
+ unconfirmed: "You have to confirm your account before continuing."
19
+ mailer:
20
+ confirmation_instructions:
21
+ subject: "Confirmation instructions"
22
+ reset_password_instructions:
23
+ subject: "Reset password instructions"
24
+ unlock_instructions:
25
+ subject: "Unlock Instructions"
26
+ omniauth_callbacks:
27
+ failure: "Could not authenticate you from %{kind} because \"%{reason}\"."
28
+ success: "Successfully authenticated from %{kind} account."
29
+ passwords:
30
+ no_token: "You can't access this page without coming from a password reset email. If you do come from a password reset email, please make sure you used the full URL provided."
31
+ send_instructions: "You will receive an email with instructions on how to reset your password in a few minutes."
32
+ send_paranoid_instructions: "If your email address exists in our database, you will receive a password recovery link at your email address in a few minutes."
33
+ updated: "Your password was changed successfully. You are now signed in."
34
+ updated_not_active: "Your password was changed successfully."
35
+ registrations:
36
+ destroyed: "Bye! Your account was successfully cancelled. We hope to see you again soon."
37
+ signed_up: "Welcome! You have signed up successfully."
38
+ signed_up_but_inactive: "You have signed up successfully. However, we could not sign you in because your account is not yet activated."
39
+ signed_up_but_locked: "You have signed up successfully. However, we could not sign you in because your account is locked."
40
+ signed_up_but_unconfirmed: "A message with a confirmation link has been sent to your email address. Please open the link to activate your account."
41
+ update_needs_confirmation: "You updated your account successfully, but we need to verify your new email address. Please check your email and click on the confirm link to finalize confirming your new email address."
42
+ updated: "You updated your account successfully."
43
+ sessions:
44
+ signed_in: "Signed in successfully."
45
+ signed_out: "Signed out successfully."
46
+ unlocks:
47
+ send_instructions: "You will receive an email with instructions about how to unlock your account in a few minutes."
48
+ send_paranoid_instructions: "If your account exists, you will receive an email with instructions about how to unlock it in a few minutes."
49
+ unlocked: "Your account has been unlocked successfully. Please sign in to continue."
50
+ errors:
51
+ messages:
52
+ already_confirmed: "was already confirmed, please try signing in"
53
+ confirmation_period_expired: "needs to be confirmed within %{period}, please request a new one"
54
+ expired: "has expired, please request a new one"
55
+ not_found: "not found"
56
+ not_locked: "was not locked"
57
+ not_saved:
58
+ one: "1 error prohibited this %{resource} from being saved:"
59
+ other: "%{count} errors prohibited this %{resource} from being saved:"
@@ -0,0 +1,5 @@
1
+ Rails.application.routes.draw do
2
+ if defined?(::OmniAuth)
3
+ get "#{::OmniAuth::config.path_prefix}/:provider/callback", to: "devise_token_auth/omniauth_callbacks#redirect_callbacks"
4
+ end
5
+ end
@@ -0,0 +1,7 @@
1
+ require "devise"
2
+ require "devise_token_auth/engine"
3
+ require "devise_token_auth/controllers/helpers"
4
+ require "devise_token_auth/controllers/url_helpers"
5
+
6
+ module DeviseTokenAuth
7
+ end
@@ -0,0 +1,129 @@
1
+ module DeviseTokenAuth
2
+ module Controllers
3
+ module Helpers
4
+ extend ActiveSupport::Concern
5
+
6
+ module ClassMethods
7
+ # Define authentication filters and accessor helpers for a group of mappings.
8
+ # These methods are useful when you are working with multiple mappings that
9
+ # share some functionality. They are pretty much the same as the ones
10
+ # defined for normal mappings.
11
+ #
12
+ # Example:
13
+ #
14
+ # inside BlogsController (or any other controller, it doesn't matter which):
15
+ # devise_group :blogger, contains: [:user, :admin]
16
+ #
17
+ # Generated methods:
18
+ # authenticate_blogger! # Redirects unless user or admin are signed in
19
+ # blogger_signed_in? # Checks whether there is either a user or an admin signed in
20
+ # current_blogger # Currently signed in user or admin
21
+ # current_bloggers # Currently signed in user and admin
22
+ #
23
+ # Use:
24
+ # before_filter :authenticate_blogger! # Redirects unless either a user or an admin are authenticated
25
+ # before_filter ->{ authenticate_blogger! :admin } # Redirects to the admin login page
26
+ # current_blogger :user # Preferably returns a User if one is signed in
27
+ #
28
+ def devise_token_auth_group(group_name, opts={})
29
+ mappings = "[#{ opts[:contains].map { |m| ":#{m}" }.join(',') }]"
30
+
31
+ class_eval <<-METHODS, __FILE__, __LINE__ + 1
32
+ def authenticate_#{group_name}!(favourite=nil, opts={})
33
+ unless #{group_name}_signed_in?
34
+ mappings = #{mappings}
35
+ mappings.unshift mappings.delete(favourite.to_sym) if favourite
36
+ mappings.each do |mapping|
37
+ set_user_by_token(mapping)
38
+ end
39
+ end
40
+ end
41
+
42
+ def #{group_name}_signed_in?
43
+ #{mappings}.any? do |mapping|
44
+ set_user_by_token(mapping)
45
+ end
46
+ end
47
+
48
+ def current_#{group_name}(favourite=nil)
49
+ mappings = #{mappings}
50
+ mappings.unshift mappings.delete(favourite.to_sym) if favourite
51
+ mappings.each do |mapping|
52
+ current = set_user_by_token(mapping)
53
+ return current if current
54
+ end
55
+ nil
56
+ end
57
+
58
+ def current_#{group_name.to_s.pluralize}
59
+ #{mappings}.map do |mapping|
60
+ set_user_by_token(mapping)
61
+ end.compact
62
+ end
63
+
64
+ helper_method "current_#{group_name}", "current_#{group_name.to_s.pluralize}", "#{group_name}_signed_in?"
65
+ METHODS
66
+ end
67
+
68
+ def log_process_action(payload)
69
+ payload[:status] ||= 401 unless payload[:exception]
70
+ super
71
+ end
72
+ end
73
+
74
+ # Define authentication filters and accessor helpers based on mappings.
75
+ # These filters should be used inside the controllers as before_filters,
76
+ # so you can control the scope of the user who should be signed in to
77
+ # access that specific controller/action.
78
+ # Example:
79
+ #
80
+ # Roles:
81
+ # User
82
+ # Admin
83
+ #
84
+ # Generated methods:
85
+ # authenticate_user! # Signs user in or 401
86
+ # authenticate_admin! # Signs admin in or 401
87
+ # user_signed_in? # Checks whether there is a user signed in or not
88
+ # admin_signed_in? # Checks whether there is an admin signed in or not
89
+ # current_user # Current signed in user
90
+ # current_admin # Current signed in admin
91
+ # user_session # Session data available only to the user scope
92
+ # admin_session # Session data available only to the admin scope
93
+ #
94
+ # Use:
95
+ # before_filter :authenticate_user! # Tell devise to use :user map
96
+ # before_filter :authenticate_admin! # Tell devise to use :admin map
97
+ #
98
+ def self.define_helpers(mapping) #:nodoc:
99
+ mapping = mapping.name
100
+
101
+ class_eval <<-METHODS, __FILE__, __LINE__ + 1
102
+ def authenticate_#{mapping}!
103
+ unless current_#{mapping}
104
+ return render json: {
105
+ errors: ["Authorized users only."]
106
+ }, status: 401
107
+ end
108
+ end
109
+
110
+ def #{mapping}_signed_in?
111
+ !!current_#{mapping}
112
+ end
113
+
114
+ def current_#{mapping}
115
+ @current_#{mapping} ||= set_user_by_token(:#{mapping})
116
+ end
117
+
118
+ def #{mapping}_session
119
+ current_#{mapping} && warden.session(:#{mapping})
120
+ end
121
+ METHODS
122
+
123
+ ActiveSupport.on_load(:action_controller) do
124
+ helper_method "current_#{mapping}", "#{mapping}_signed_in?", "#{mapping}_session"
125
+ end
126
+ end
127
+ end
128
+ end
129
+ end