mirror of
https://github.com/philomena-dev/philomena.git
synced 2024-11-30 14:57:59 +01:00
Fixes email validation (#74)
Co-authored-by: Parasprite <foalspeedahead@gmail.com>
This commit is contained in:
parent
7a6582bbc7
commit
b79f07b86d
6 changed files with 7 additions and 7 deletions
|
@ -161,7 +161,7 @@ defmodule Philomena.Users.User do
|
|||
defp validate_email(changeset) do
|
||||
changeset
|
||||
|> validate_required([:email])
|
||||
|> validate_format(:email, ~r/^[^\s]+@[^\s]+$/, message: "must have the @ sign and no spaces")
|
||||
|> validate_format(:email, ~r/^[^\s]+@[^\s]+\.[^\s]+$/, message: "must be valid (e.g., user@example.com)")
|
||||
|> validate_length(:email, max: 160)
|
||||
|> unsafe_validate_unique(:email, Philomena.Repo)
|
||||
end
|
||||
|
|
|
@ -35,7 +35,7 @@ h3 Change email
|
|||
p Oops, something went wrong! Please check the errors below.
|
||||
|
||||
.field
|
||||
= email_input f, :email, class: "input", placeholder: "Email", required: true, pattern: ".*@.*"
|
||||
= email_input f, :email, class: "input", placeholder: "Email", required: true, pattern: ~S/[^\s]+@[^\s]+\.[^\s]+/
|
||||
= error_tag f, :email
|
||||
|
||||
.field
|
||||
|
|
|
@ -16,7 +16,7 @@ h1 Register
|
|||
' You'll use your email address to log in, and we'll use this to get in
|
||||
' touch if we need to. Don't worry, we won't share this or spam you.
|
||||
.field
|
||||
= email_input f, :email, class: "input", placeholder: "Email", required: true, pattern: ".*@.*"
|
||||
= email_input f, :email, class: "input", placeholder: "Email", required: true, pattern: ~S/[^\s]+@[^\s]+\.[^\s]+/
|
||||
= error_tag f, :email
|
||||
|
||||
.fieldlabel
|
||||
|
|
|
@ -10,7 +10,7 @@ h1 Sign in
|
|||
p = link "Forgot your password?", to: Routes.password_path(@conn, :new)
|
||||
|
||||
.field
|
||||
= email_input f, :email, class: "input", required: true, placeholder: "Email", autofocus: true, pattern: ".*@.*"
|
||||
= email_input f, :email, class: "input", required: true, placeholder: "Email", autofocus: true, pattern: ~S/[^\s]+@[^\s]+\.[^\s]+/
|
||||
= error_tag f, :email
|
||||
|
||||
.field
|
||||
|
|
|
@ -97,7 +97,7 @@ defmodule Philomena.UsersTest do
|
|||
{:error, changeset} = Users.register_user(%{email: "not valid", password: "not valid"})
|
||||
|
||||
assert %{
|
||||
email: ["must have the @ sign and no spaces"],
|
||||
email: ["must be valid (e.g., user@example.com)"],
|
||||
password: ["should be at least 12 character(s)"]
|
||||
} = errors_on(changeset)
|
||||
end
|
||||
|
@ -167,7 +167,7 @@ defmodule Philomena.UsersTest do
|
|||
{:error, changeset} =
|
||||
Users.apply_user_email(user, valid_user_password(), %{email: "not valid"})
|
||||
|
||||
assert %{email: ["must have the @ sign and no spaces"]} = errors_on(changeset)
|
||||
assert %{email: ["must be valid (e.g., user@example.com)"]} = errors_on(changeset)
|
||||
end
|
||||
|
||||
test "validates maximum value for email for security", %{user: user} do
|
||||
|
|
|
@ -41,7 +41,7 @@ defmodule PhilomenaWeb.RegistrationControllerTest do
|
|||
})
|
||||
|
||||
response = html_response(conn, 200)
|
||||
assert response =~ "must have the @ sign and no spaces"
|
||||
assert response =~ "must be valid (e.g., user@example.com)"
|
||||
assert response =~ "should be at least 12 character"
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue