Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ Default Devise modules included in `Alchemy::User` model
- `:validatable`
- `:timeoutable`
- `:recoverable`
- `:rememberable`

If you want to add additional modules into the Alchemy user class append them to `Alchemy::Devise.config.devise_modules` in an initializer in your app.

Expand Down
10 changes: 10 additions & 0 deletions app/views/alchemy/admin/user_sessions/new.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,16 @@
<%= f.input Devise.authentication_keys.first, autofocus: true, required: true,
input_html: {autocomplete: Devise.authentication_keys.first == :email ? "email" : "username"} %>
<%= f.input :password, required: true, input_html: {autocomplete: "current-password"} %>
<% if devise_mapping.rememberable? %>
<div class="input">
<span class="control-label">&nbsp;</span>

<%= f.label :remember_me, class: "checkbox" do %>
<%= f.check_box :remember_me, checked: true %>
<%= Alchemy.t(:remember_me, scope: 'admin.login', days: Devise.remember_for.in_days.to_i) %>
<% end %>
</div>
<% end %>
<div class="submit">
<%= link_to Alchemy.t('Forgot your password?'), admin_new_password_path %>
<button type="submit"><%= Alchemy.t(:login) %></button>
Expand Down
5 changes: 5 additions & 0 deletions config/locales/de.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
de:
alchemy:
admin:
login:
remember_me: "Für %{days} Tage angemeldet bleiben"
5 changes: 5 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
en:
alchemy:
admin:
login:
remember_me: "Remember me for %{days} days"
5 changes: 5 additions & 0 deletions db/migrate/20251127170649_add_rememberable_column.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddRememberableColumn < ActiveRecord::Migration[7.1]
def change
add_column :alchemy_users, :remember_created_at, :datetime, if_not_exists: true
end
end
6 changes: 4 additions & 2 deletions lib/alchemy/devise/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ class Configuration < Alchemy::Configuration
# :trackable,
# :validatable,
# :timeoutable,
# :recoverable
# :recoverable,
# :rememberable
# ]
#
# If you want to add additional modules into the Alchemy user class append
Expand All @@ -37,7 +38,8 @@ class Configuration < Alchemy::Configuration
:trackable,
:validatable,
:timeoutable,
:recoverable
:recoverable,
:rememberable
]
end
end
Expand Down
24 changes: 24 additions & 0 deletions spec/features/login_feature_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,29 @@
Devise.authentication_keys = default_key
end
end

context "with rememberable Devise module enabled" do
before do
allow_any_instance_of(Devise::Mapping).to receive(:rememberable?).and_return(true)
end

it "displays a remember me checkbox" do
visit "/admin/login"
expect(page).to have_css("label input#user_remember_me[checked]")
expect(page).to have_content("Remember me for 14 days")
end
end

context "with rememberable Devise module disabled" do
before do
allow_any_instance_of(Devise::Mapping).to receive(:rememberable?).and_return(false)
end

it "does not display a remember me checkbox" do
visit "/admin/login"
expect(page).to have_css(":not(:has(input#user_remember_me))")
expect(page).to_not have_content("Remember me for 14 days")
end
end
end
end