passwordless 0.4.4 → 0.5.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 307e6e1f46ccc9341e5ca07755b8c60cf5df9dfe7ce0827c2ff73e3b830d199b
4
- data.tar.gz: eced1cc3a2b2abdce1194beb887f217bce6752a131152e1a8020987126030a49
3
+ metadata.gz: d79c41fb0ddc3797af28166832ab336c3c3c2347c9336be03e04441554347772
4
+ data.tar.gz: 0f24f481eff8e766e7546e21c53fa196fa61421037a6543c58c7bca81e78899e
5
5
  SHA512:
6
- metadata.gz: 3c91e2385d7bfed3c083f3434426241052e0d0ca9566442c46d52e07ab107cb8dd70b5d81e5199ab56fb8ebba3dde6d47345a293be3dff40590f94b7290615d8
7
- data.tar.gz: e43f2ec499c6b9df234956f0560bcad613489ee8e2175f5cb3f9fbba3d6583f842afb703ec8ca3138b651fb41f226ca20ca52ddbf805167c51995e0bfc74ed76
6
+ metadata.gz: c3a7038ffd29a1cb8218905fb974fd3d59b45b11190e3df9e125e8fc5c200638d7f7cf1c954d3a17b256594c4429a144fcd5259a210fa3fed5b13a05551af6c4
7
+ data.tar.gz: 3a1506b2dfba720a3ca82df7ce992fb74d450691dd31e8b250d961a7c882680fda2fb36674a6d474fa7114dc922839448547ade16b6c1c57348c08b1c9c8de25
data/README.md CHANGED
@@ -19,6 +19,7 @@ Add authentication to your Rails app without all the icky-ness of passwords.
19
19
  * [Registering new users](#registering-new-users)
20
20
  * [Generating tokens](#generating-tokens)
21
21
  * [Redirecting back after sign-in](#redirecting-back-after-sign-in)
22
+ * [URLs and links](#urls-and-links)
22
23
  * [License](#license)
23
24
 
24
25
  ## Installation
@@ -172,6 +173,20 @@ end
172
173
 
173
174
  This can be turned off with `Passwordless.redirect_back_after_sign_in = false` but if you just don't save the previous destination, you'll be fine.
174
175
 
176
+ ### URLs and links
177
+
178
+ By default, Passwordless uses the resource name given to `passwordless_for` to generate its routes and helpers.
179
+
180
+ ```ruby
181
+ passwordless_for :users
182
+ # <%= users.sign_in_path %> # => /users/sign_in
183
+
184
+ passwordless_for :users, at: '/', as: :auth
185
+ # <%= auth.sign_in_path %> # => /sign_in
186
+ ```
187
+
188
+ Also be sure to [specify ActionMailer's `default_url_options.host`](http://guides.rubyonrails.org/action_mailer_basics.html#generating-urls-in-action-mailer-views).
189
+
175
190
  # License
176
191
 
177
192
  MIT
@@ -5,6 +5,9 @@ require 'bcrypt'
5
5
  module Passwordless
6
6
  # Controller for managing Passwordless sessions
7
7
  class SessionsController < ApplicationController
8
+ # Raise this exception when a session is expired.
9
+ class ExpiredSessionError < StandardError; end
10
+
8
11
  include ControllerHelpers
9
12
 
10
13
  helper_method :authenticatable_resource
@@ -31,6 +34,8 @@ module Passwordless
31
34
  render
32
35
  end
33
36
 
37
+ # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
38
+
34
39
  # get '/sign_in/:token'
35
40
  # Looks up session record by provided token. Signs in user if a match
36
41
  # is found. Redirects to either the user's original destination
@@ -42,6 +47,8 @@ module Passwordless
42
47
  BCrypt::Password.create(params[:token])
43
48
 
44
49
  session = find_session
50
+ raise ExpiredSessionError if session.expired?
51
+
45
52
  sign_in session.authenticatable
46
53
 
47
54
  redirect_enabled = Passwordless.redirect_back_after_sign_in
@@ -52,7 +59,11 @@ module Passwordless
52
59
  else
53
60
  redirect_to main_app.root_path
54
61
  end
62
+ rescue ExpiredSessionError
63
+ flash[:error] = I18n.t('.passwordless.sessions.create.session_expired')
64
+ redirect_to main_app.root_path
55
65
  end
66
+ # rubocop:enable Metrics/MethodLength, Metrics/AbcSize
56
67
 
57
68
  # match '/sign_out', via: %i[get delete].
58
69
  # Signs user out. Redirects to root_path
@@ -18,7 +18,7 @@ module Passwordless
18
18
  email_field = @session.authenticatable.class.passwordless_email_field
19
19
  mail(
20
20
  to: @session.authenticatable.send(email_field),
21
- subject: 'Your magic link ✨'
21
+ subject: I18n.t('passwordless.mailer.subject')
22
22
  )
23
23
  end
24
24
  end
@@ -18,9 +18,13 @@ module Passwordless
18
18
  before_validation :set_defaults
19
19
 
20
20
  scope :valid, lambda {
21
- where('timeout_at > ? AND expires_at > ?', Time.current, Time.current)
21
+ where('timeout_at > ?', Time.current)
22
22
  }
23
23
 
24
+ def expired?
25
+ expires_at <= Time.current
26
+ end
27
+
24
28
  private
25
29
 
26
30
  def set_defaults
@@ -1,2 +1 @@
1
- Here's your link:
2
- <%= @magic_link %>
1
+ <%= I18n.t('passwordless.mailer.magic_link', link: @magic_link) %>
@@ -1 +1 @@
1
- <p>If we found you in the system, we've sent you an email.</p>
1
+ <p><%= I18n.t('passwordless.sessions.success.email_sent_if_record_found') %></p>
@@ -1,5 +1,5 @@
1
1
  <%= form_for @session, url: send(authenticatable_resource).sign_in_path do |f| %>
2
2
  <% email_field_name = :"passwordless[#{@email_field}]" %>
3
3
  <%= text_field_tag email_field_name, params.fetch(email_field_name, nil) %>
4
- <%= f.submit 'Send magic link' %>
4
+ <%= f.submit I18n.t('passwordless.sessions.new.submit') %>
5
5
  <% end %>
@@ -0,0 +1,12 @@
1
+ ---
2
+ en:
3
+ passwordless:
4
+ sessions:
5
+ create:
6
+ session_expired: 'Your session has expired, please sign in again.'
7
+ email_sent_if_record_found: "If we found you in the system, we've sent you an email."
8
+ new:
9
+ submit: 'Send magic link'
10
+ mailer:
11
+ subject: "Your magic link ✨'"
12
+ magic_link: "Here's your link: %{link}"
@@ -12,5 +12,10 @@ module Passwordless
12
12
  ActiveRecord::Base.extend ModelHelpers
13
13
  require 'passwordless/controller_helpers'
14
14
  end
15
+
16
+ config.before_initialize do |app|
17
+ app.config.i18n.load_path +=
18
+ Dir[Engine.root.join('config', 'locales', '*.yml')]
19
+ end
15
20
  end
16
21
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Passwordless
4
- VERSION = '0.4.4' # :nodoc:
4
+ VERSION = '0.5.0' # :nodoc:
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: passwordless
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.4
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mikkel Malmberg
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-01-02 00:00:00.000000000 Z
11
+ date: 2018-02-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -98,6 +98,7 @@ files:
98
98
  - app/views/passwordless/mailer/magic_link.text.erb
99
99
  - app/views/passwordless/sessions/create.html.erb
100
100
  - app/views/passwordless/sessions/new.html.erb
101
+ - config/locales/en.yml
101
102
  - config/routes.rb
102
103
  - db/migrate/20171104221735_create_passwordless_sessions.rb
103
104
  - lib/passwordless.rb