Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Store routing context when mounting engine, Fix i18n path #14

Merged
merged 10 commits into from
Mar 8, 2018
Merged
5 changes: 1 addition & 4 deletions app/mailers/passwordless/mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@ class Mailer < ActionMailer::Base
def magic_link(session)
@session = session

authenticatable_resource_name =
@session.authenticatable_type.underscore.pluralize
@magic_link =
send(authenticatable_resource_name).token_sign_in_url(session.token)
@magic_link = send(Passwordless.router_context).token_sign_in_url(session.token)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line is too long. [86/80]

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line is too long. [86/80]


email_field = @session.authenticatable.class.passwordless_email_field
mail(
Expand Down
2 changes: 1 addition & 1 deletion app/views/passwordless/sessions/new.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<%= form_for @session, url: send(authenticatable_resource).sign_in_path do |f| %>
<%= form_for @session, url: send(Passwordless.router_context).sign_in_path do |f| %>
<% email_field_name = :"passwordless[#{@email_field}]" %>
<%= text_field_tag email_field_name, params.fetch(email_field_name, nil) %>
<%= f.submit I18n.t('passwordless.sessions.new.submit') %>
Expand Down
1 change: 1 addition & 0 deletions lib/passwordless.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ module Passwordless
mattr_accessor(:default_from_address) { '[email protected]' }
mattr_accessor(:token_generator) { UrlSafeBase64Generator.new }
mattr_accessor(:redirect_back_after_sign_in) { true }
mattr_accessor(:router_context) { :configured_when_mounting_passwordless }
end
8 changes: 5 additions & 3 deletions lib/passwordless/router_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@ module RouterHelpers
# <%= link_to 'Sign in', user_session_things.sign_in_path %>).
# (Default: resource.to_s)
def passwordless_for(resource, at: nil, as: nil)
mount_at = at || resource.to_s
mount_as = as || resource.to_s
mount(
Passwordless::Engine,
at: at || resource.to_s,
as: as || resource.to_s,
Passwordless::Engine, at: mount_at, as: mount_as,
defaults: { authenticatable: resource.to_s.singularize }
)

Passwordless.router_context = mount_at
end
end
end