gettext user session controller
This commit is contained in:
parent
7e61c5c59a
commit
9972299fc4
@ -14,13 +14,13 @@ defmodule CanneryWeb.UserSessionController do
|
||||
if user = Accounts.get_user_by_email_and_password(email, password) do
|
||||
UserAuth.log_in_user(conn, user, user_params)
|
||||
else
|
||||
render(conn, "new.html", error_message: "Invalid email or password")
|
||||
render(conn, "new.html", error_message: dgettext("errors", "Invalid email or password"))
|
||||
end
|
||||
end
|
||||
|
||||
def delete(conn, _params) do
|
||||
conn
|
||||
|> put_flash(:info, "Logged out successfully.")
|
||||
|> put_flash(:info, gettext("Logged out successfully."))
|
||||
|> UserAuth.log_out_user()
|
||||
end
|
||||
end
|
||||
|
@ -109,3 +109,8 @@ msgstr ""
|
||||
#: lib/cannery_web/templates/user_settings/edit.html.heex:3
|
||||
msgid "Settings"
|
||||
msgstr ""
|
||||
|
||||
#, elixir-format, ex-autogen
|
||||
#: lib/cannery_web/controllers/user_session_controller.ex:23
|
||||
msgid "Logged out successfully."
|
||||
msgstr ""
|
||||
|
@ -152,3 +152,8 @@ msgstr[1] ""
|
||||
#: lib/cannery_web/templates/user_settings/edit.html.heex:58
|
||||
msgid "Oops, something went wrong! Please check the errors below."
|
||||
msgstr ""
|
||||
|
||||
#, elixir-format, ex-autogen
|
||||
#: lib/cannery_web/controllers/user_session_controller.ex:17
|
||||
msgid "Invalid email or password"
|
||||
msgstr ""
|
||||
|
@ -1,8 +1,10 @@
|
||||
defmodule CanneryWeb.UserSessionControllerTest do
|
||||
use CanneryWeb.ConnCase, async: true
|
||||
|
||||
import CanneryWeb.Gettext
|
||||
import Cannery.AccountsFixtures
|
||||
|
||||
@moduletag :user_session_controller
|
||||
|
||||
setup do
|
||||
%{user: user_fixture()}
|
||||
end
|
||||
@ -11,9 +13,8 @@ defmodule CanneryWeb.UserSessionControllerTest do
|
||||
test "renders log in page", %{conn: conn} do
|
||||
conn = get(conn, Routes.user_session_path(conn, :new))
|
||||
response = html_response(conn, 200)
|
||||
assert response =~ "<h1>Log in</h1>"
|
||||
assert response =~ "Log in</a>"
|
||||
assert response =~ "Register</a>"
|
||||
assert response =~ dgettext("actions", "Log in")
|
||||
assert response =~ dgettext("actions", "Register")
|
||||
end
|
||||
|
||||
test "redirects if already logged in", %{conn: conn, user: user} do
|
||||
@ -36,8 +37,7 @@ defmodule CanneryWeb.UserSessionControllerTest do
|
||||
conn = get(conn, "/")
|
||||
response = html_response(conn, 200)
|
||||
assert response =~ user.email
|
||||
assert response =~ "Settings</a>"
|
||||
assert response =~ "Log out</a>"
|
||||
assert response =~ dgettext("prompts", "Are you sure you want to log out?")
|
||||
end
|
||||
|
||||
test "logs the user in with remember me", %{conn: conn, user: user} do
|
||||
@ -75,8 +75,8 @@ defmodule CanneryWeb.UserSessionControllerTest do
|
||||
})
|
||||
|
||||
response = html_response(conn, 200)
|
||||
assert response =~ "<h1>Log in</h1>"
|
||||
assert response =~ "Invalid email or password"
|
||||
assert response =~ dgettext("actions", "Log in")
|
||||
assert response =~ dgettext("errors", "Invalid email or password")
|
||||
end
|
||||
end
|
||||
|
||||
@ -85,14 +85,14 @@ defmodule CanneryWeb.UserSessionControllerTest do
|
||||
conn = conn |> log_in_user(user) |> delete(Routes.user_session_path(conn, :delete))
|
||||
assert redirected_to(conn) == "/"
|
||||
refute get_session(conn, :user_token)
|
||||
assert get_flash(conn, :info) =~ "Logged out successfully"
|
||||
assert get_flash(conn, :info) =~ gettext("Logged out successfully")
|
||||
end
|
||||
|
||||
test "succeeds even if the user is not logged in", %{conn: conn} do
|
||||
conn = delete(conn, Routes.user_session_path(conn, :delete))
|
||||
assert redirected_to(conn) == "/"
|
||||
refute get_session(conn, :user_token)
|
||||
assert get_flash(conn, :info) =~ "Logged out successfully"
|
||||
assert get_flash(conn, :info) =~ gettext("Logged out successfully")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -1,8 +1,7 @@
|
||||
defmodule CanneryWeb.AmmoGroupLiveTest do
|
||||
use CanneryWeb.ConnCase
|
||||
|
||||
import Phoenix.LiveViewTest
|
||||
|
||||
import CanneryWeb.Gettext
|
||||
alias Cannery.Ammo
|
||||
|
||||
@create_attrs %{count: 42, notes: "some notes", price_paid: 120.5}
|
||||
|
@ -1,8 +1,7 @@
|
||||
defmodule CanneryWeb.AmmoTypeLiveTest do
|
||||
use CanneryWeb.ConnCase
|
||||
|
||||
import Phoenix.LiveViewTest
|
||||
|
||||
import CanneryWeb.Gettext
|
||||
alias Cannery.Ammo
|
||||
|
||||
@create_attrs %{
|
||||
|
@ -1,7 +1,7 @@
|
||||
defmodule CanneryWeb.HomeLiveTest do
|
||||
use CanneryWeb.ConnCase
|
||||
|
||||
import Phoenix.LiveViewTest
|
||||
import CanneryWeb.Gettext
|
||||
|
||||
test "disconnected and connected render", %{conn: conn} do
|
||||
{:ok, home_live, disconnected_html} = live(conn, "/")
|
||||
|
@ -1,8 +1,7 @@
|
||||
defmodule CanneryWeb.InviteLiveTest do
|
||||
use CanneryWeb.ConnCase
|
||||
|
||||
import Phoenix.LiveViewTest
|
||||
|
||||
import CanneryWeb.Gettext
|
||||
alias Cannery.Invites
|
||||
|
||||
@create_attrs %{name: "some name", token: "some token"}
|
||||
|
@ -1,8 +1,7 @@
|
||||
defmodule CanneryWeb.TagLiveTest do
|
||||
use CanneryWeb.ConnCase
|
||||
|
||||
import Phoenix.LiveViewTest
|
||||
|
||||
import CanneryWeb.Gettext
|
||||
alias Cannery.Tags
|
||||
|
||||
@create_attrs %{
|
||||
|
Loading…
Reference in New Issue
Block a user