1
0
Fork 0
mirror of https://framagit.org/framasoft/mobilizon.git synced 2024-12-27 18:31:07 +00:00
mobilizon/lib/web/email/checker.ex
Thomas Citharel f4284e1d3a
Remove unused functions
Signed-off-by: Thomas Citharel <tcit@tcit.fr>
2021-10-05 16:05:51 +02:00

28 lines
853 B
Elixir
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

defmodule Mobilizon.Web.Email.Checker do
@moduledoc """
Provides a function to test emails against a "not so bad" regex.
"""
@email_regex ~r/^[\w.!#$%&*+\-\/=?\^`{|}~]+@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*$/i
@doc """
Returns whether the email is valid.
"""
@spec valid?(String.t()) :: boolean
def valid?(email), do: email =~ @email_regex
@spec validate_changeset(Ecto.Changeset.t()) :: Ecto.Changeset.t()
def validate_changeset(%Ecto.Changeset{} = changeset) do
changeset = Ecto.Changeset.validate_length(changeset, :email, min: 3, max: 250)
case Ecto.Changeset.fetch_change(changeset, :email) do
{:ok, email} ->
if valid?(email),
do: changeset,
else: Ecto.Changeset.add_error(changeset, :email, "Email doesn't fit required format")
:error ->
changeset
end
end
end