aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorlambda <pleromagit@rogerbraun.net>2018-12-13 15:13:24 +0000
committerlambda <pleromagit@rogerbraun.net>2018-12-13 15:13:24 +0000
commitb19ee62252114d024b52aff3ebb01ac16244990c (patch)
treee78c217696a86d8c2e79eb297558016fa37686a4 /lib
parenta5a10988e87dfb7bc4bedf6c9cb3f52e739286d7 (diff)
parent7214d574630842e4efb76d6c3494a180cbc2a930 (diff)
downloadpleroma-b19ee62252114d024b52aff3ebb01ac16244990c.tar.gz
Merge branch 'username-underscores' into 'develop'
Allow underscores/dashes in usernames. Closes #429 See merge request pleroma/pleroma!537
Diffstat (limited to 'lib')
-rw-r--r--lib/pleroma/formatter.ex2
-rw-r--r--lib/pleroma/user.ex20
2 files changed, 17 insertions, 5 deletions
diff --git a/lib/pleroma/formatter.ex b/lib/pleroma/formatter.ex
index 5b03e9aeb..133683794 100644
--- a/lib/pleroma/formatter.ex
+++ b/lib/pleroma/formatter.ex
@@ -18,7 +18,7 @@ defmodule Pleroma.Formatter do
def parse_mentions(text) do
# Modified from https://www.w3.org/TR/html5/forms.html#valid-e-mail-address
regex =
- ~r/@[a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]*@?[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*/u
+ ~r/@[a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]*@?[a-zA-Z0-9_-](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*/u
Regex.scan(regex, text)
|> List.flatten()
diff --git a/lib/pleroma/user.ex b/lib/pleroma/user.ex
index e146b562c..49928bc13 100644
--- a/lib/pleroma/user.ex
+++ b/lib/pleroma/user.ex
@@ -11,6 +11,11 @@ defmodule Pleroma.User do
@type t :: %__MODULE__{}
+ @email_regex ~r/^[a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/
+
+ @strict_local_nickname_regex ~r/^[a-zA-Z\d]+$/
+ @extended_local_nickname_regex ~r/^[a-zA-Z\d_-]+$/
+
schema "users" do
field(:bio, :string)
field(:email, :string)
@@ -77,7 +82,6 @@ defmodule Pleroma.User do
}
end
- @email_regex ~r/^[a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/
def remote_user_creation(params) do
params =
params
@@ -117,7 +121,7 @@ defmodule Pleroma.User do
struct
|> cast(params, [:bio, :name, :avatar])
|> unique_constraint(:nickname)
- |> validate_format(:nickname, ~r/^[a-zA-Z\d]+$/)
+ |> validate_format(:nickname, local_nickname_regex())
|> validate_length(:bio, max: 5000)
|> validate_length(:name, min: 1, max: 100)
end
@@ -134,7 +138,7 @@ defmodule Pleroma.User do
struct
|> cast(params, [:bio, :name, :follower_address, :avatar, :last_refreshed_at])
|> unique_constraint(:nickname)
- |> validate_format(:nickname, ~r/^[a-zA-Z\d]+$/)
+ |> validate_format(:nickname, local_nickname_regex())
|> validate_length(:bio, max: 5000)
|> validate_length(:name, max: 100)
|> put_embed(:info, info_cng)
@@ -172,7 +176,7 @@ defmodule Pleroma.User do
|> validate_confirmation(:password)
|> unique_constraint(:email)
|> unique_constraint(:nickname)
- |> validate_format(:nickname, ~r/^[a-zA-Z\d]+$/)
+ |> validate_format(:nickname, local_nickname_regex())
|> validate_format(:email, @email_regex)
|> validate_length(:bio, max: 1000)
|> validate_length(:name, min: 1, max: 100)
@@ -861,4 +865,12 @@ defmodule Pleroma.User do
|> List.flatten()
|> Enum.map(&String.downcase(&1))
end
+
+ defp local_nickname_regex() do
+ if Pleroma.Config.get([:instance, :extended_nickname_format]) do
+ @extended_local_nickname_regex
+ else
+ @strict_local_nickname_regex
+ end
+ end
end