mirror of
https://github.com/philomena-dev/philomena.git
synced 2024-12-17 22:47:59 +01:00
fix filters page for authenticated users
This commit is contained in:
parent
4915fb5044
commit
9c638c0e3b
3 changed files with 22 additions and 19 deletions
|
@ -117,14 +117,9 @@ defmodule Philomena.Users.User do
|
||||||
|> validate_required([])
|
|> validate_required([])
|
||||||
end
|
end
|
||||||
|
|
||||||
def failure_changeset(user) do
|
def filter_changeset(user, filter) do
|
||||||
changeset = change(user)
|
change(user)
|
||||||
user = changeset.data
|
|> put_change(:current_filter_id, filter.id)
|
||||||
|
|
||||||
user
|
|
||||||
|> change(%{
|
|
||||||
failed_attempts: user.failed_attempts + 1,
|
|
||||||
})
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def create_totp_secret_changeset(user) do
|
def create_totp_secret_changeset(user) do
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
defmodule PhilomenaWeb.Filter.CurrentController do
|
defmodule PhilomenaWeb.Filter.CurrentController do
|
||||||
use PhilomenaWeb, :controller
|
use PhilomenaWeb, :controller
|
||||||
|
|
||||||
alias Philomena.{Filters, Filters.Filter}
|
alias Philomena.{Filters, Filters.Filter, Users.User}
|
||||||
|
alias Philomena.Repo
|
||||||
|
|
||||||
plug :load_resource, model: Filter
|
plug :load_resource, model: Filter
|
||||||
|
|
||||||
|
@ -16,16 +17,23 @@ defmodule PhilomenaWeb.Filter.CurrentController do
|
||||||
Filters.default_filter()
|
Filters.default_filter()
|
||||||
end
|
end
|
||||||
|
|
||||||
conn =
|
conn
|
||||||
if user do
|
|> update_filter(user, filter)
|
||||||
nil
|
|> put_flash(:info, "Switched to filter #{filter.name}")
|
||||||
else
|
|> redirect(to: Routes.filter_path(conn, :index))
|
||||||
conn
|
end
|
||||||
|> put_session(:filter_id, filter.id)
|
|
||||||
end
|
defp update_filter(conn, nil, filter) do
|
||||||
|
conn
|
||||||
|
|> put_session(:filter_id, filter.id)
|
||||||
|
end
|
||||||
|
|
||||||
|
defp update_filter(conn, user, filter) do
|
||||||
|
{:ok, user} =
|
||||||
|
user
|
||||||
|
|> User.filter_changeset(filter)
|
||||||
|
|> Repo.update()
|
||||||
|
|
||||||
conn
|
conn
|
||||||
|> put_flash(:info, "Switched to filter #{filter.name}")
|
|
||||||
|> redirect(to: "/")
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -24,7 +24,7 @@
|
||||||
strong Your current filter
|
strong Your current filter
|
||||||
- else
|
- else
|
||||||
li
|
li
|
||||||
= button_to "Use this filter", Routes.filter_current_path(@conn, :update, @filter), method: "put", class: "button"
|
= button_to "Use this filter", Routes.filter_current_path(@conn, :update, id: @filter), method: "put", class: "button"
|
||||||
p
|
p
|
||||||
em
|
em
|
||||||
= @filter.description
|
= @filter.description
|
||||||
|
|
Loading…
Reference in a new issue