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

use form_with, requre email, handle rails 7 form redirect #128

Merged
merged 8 commits into from
Nov 30, 2022
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,10 @@ Then specify which field on your `User` record is the email field with:

```ruby
class User < ApplicationRecord
validates :email, presence: true, uniqueness: { case_sensitive: false }
validates :email,
presence: true,
uniqueness: { case_sensitive: false },
format: { with: URI::MailTo::EMAIL_REGEXP }

passwordless_with :email # <-- here!
end
Expand Down
4 changes: 2 additions & 2 deletions app/views/passwordless/sessions/new.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<%= form_for @session, url: send(Passwordless.mounted_as).sign_in_path do |f| %>
<%= form_with model: @session, url: send(Passwordless.mounted_as).sign_in_path, data: { turbo: 'false' } do |f| %>
<% email_field_name = :"passwordless[#{@email_field}]" %>
<%= text_field_tag email_field_name, params.fetch(email_field_name, nil) %>
<%= text_field_tag email_field_name, params.fetch(email_field_name, nil), required: true %>
<%= f.submit I18n.t('passwordless.sessions.new.submit') %>
<% end %>
13 changes: 13 additions & 0 deletions config/locales/ua.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
ua:
passwordless:
sessions:
create:
session_expired: 'Ваш сеанс закінчився, будь ласка увійдіть знову.'
email_sent_if_record_found: "Якщо ми знайшли вас у системі, ми надіслали вам електронного листа."
token_claimed: "Це посилання вже використовувалося, спробуйте надіслати запит на посилання ще раз"
new:
submit: 'Надіслати магічне посилання'
mailer:
subject: "Ваше магічне посилання ✨"
magic_link: "Ось ваше магічне посилання: %{link}"
2 changes: 1 addition & 1 deletion test/dummy/app/views/registrations/new.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<%= form_for @user, url: registrations_path do |f| %>
<%= form_with model: @user, url: registrations_path do |f| %>
<%= f.label :email %>
<%= f.email_field :email %>
<%= f.submit %>
Expand Down