Skip to content

Commit

Permalink
Merge pull request #1176 from animina-dating/beta-registration
Browse files Browse the repository at this point in the history
Added a new route and template for the first 4 fields
  • Loading branch information
wintermeyer authored Nov 30, 2024
2 parents cc82a75 + 935a725 commit 3c53b10
Show file tree
Hide file tree
Showing 6 changed files with 526 additions and 8 deletions.
45 changes: 39 additions & 6 deletions lib/animina/validations/bad_username.ex
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,50 @@ defmodule Animina.Validations.BadUsername do
username =
Ash.Changeset.get_attribute(changeset, opts[:attribute])

bad_usernames = ["my", "current_user", "profile"]
bad_usernames = [
"my",
"current_user",
"profile",
"beta",
"test",
"new",
"alpha",
"next",
"Stefan",
"Stephan",
"Aurelius",
"Juna",
"Miri",
"Miriam",
"aw",
"jw",
"sw"
]

if username &&
(Ash.CiString.value(username) in bad_usernames or has_at?(Ash.CiString.value(username))) do
{:error, field: :username, message: "This is a bad username"}
else
:ok
case more_than_2_chars?(username) do
false ->
{:error, field: :username, message: "Username must be at least 2 characters long"}

true ->
if username &&
(Ash.CiString.value(username) in bad_usernames or
has_at?(Ash.CiString.value(username))) do
{:error, field: :username, message: "This is a bad username"}
else
:ok
end
end
end

def has_at?(string) do
String.contains?(string, "@")
end

def more_than_2_chars?(nil) do
false
end

def more_than_2_chars?(string) do
string && String.length(Ash.CiString.value(string)) > 2
end
end
1 change: 1 addition & 0 deletions lib/animina_web.ex
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ defmodule AniminaWeb do
import AniminaWeb.PostsComponents
import AniminaWeb.ReportComponents
import AniminaWeb.WaitlistComponents
import AniminaWeb.BetaRegistrationComponents
import Gettext, only: [with_locale: 2]

# https://elixirforum.com/t/form-for-not-working-in-phoenix-1-7/52013
Expand Down
Loading

0 comments on commit 3c53b10

Please sign in to comment.