Skip to content

Commit

Permalink
feat(profile): patterns for bsky and mastodon validation
Browse files Browse the repository at this point in the history
  • Loading branch information
Fenrikur committed Jan 30, 2024
1 parent c1066d4 commit 6914003
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
28 changes: 20 additions & 8 deletions app/Http/Controllers/ProfileController.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,10 @@ class ProfileController extends Controller

public function index()
{

}

public function create(Request $request)
{

}

public static function createOrUpdate(Request $request, int $applicationId): Profile
Expand Down Expand Up @@ -88,12 +86,10 @@ public static function getByApplicationId(int|null $applicationId): Profile|null

public function store(Request $request)
{

}

public function show(Profile $profile)
{

}

public function edit(Profile $profile)
Expand Down Expand Up @@ -148,13 +144,29 @@ public static function getValidations()
],
"mastodon" => [
'nullable',
'regex:/^([0-9a-z_]{3,64})@([0-9a-z_]{3,64})\.([0-9a-z_.]{2,64})$/i',
// TODO: improve validation
// Mastodon user name validation loosely based on
// https://docs.joinmastodon.org/spec/webfinger/#intro and
// https://datatracker.ietf.org/doc/html/rfc7565#section-7
/*
* acctURI = "acct" ":" userpart "@" host
* userpart = unreserved / sub-delims 0*( unreserved / pct-encoded / sub-delims )
* host = IP-literal / IPv4address / reg-name
* IP-literal = "[" ( IPv6address / IPvFuture ) "]"
* IPvFuture = "v" 1*HEXDIG "." 1*( unreserved / sub-delims / ":" )
* reg-name = *( unreserved / pct-encoded / sub-delims )
* reserved = gen-delims / sub-delims
* gen-delims = ":" / "/" / "?" / "#" / "[" / "]" / "@"
* sub-delims = "!" / "$" / "&" / "'" / "(" / ")"/ "*" / "+" / "," / ";" / "="
* pct-encoded = "%" HEXDIG HEXDIG
* unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~"
*/
'regex:/([A-Z0-9\-._~!$&\'\(\)\*,;=][A-Z0-9\-._~%!$&\'\(\)\*,;=]*)@([A-Z0-9\-._~%!$&\'\(\)\*,;=]+\.[A-Z]{2,})/i'
],
"bluesky" => [
'nullable',
'regex:/^[0-9a-z_.]{3,64}$/i',
// TODO: improve validation
// Bluesky user name validation:
// https://atproto.com/specs/handle
'regex:/^([a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?\.)+[a-zA-Z]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?$/',
],
"telegram" => [
'nullable',
Expand Down
4 changes: 2 additions & 2 deletions lang/en/validation.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@
'regex' => 'Please verify your Twitter handle, it must be between 4 and 15 characters and only contain letters, numbers and underscores (_).'
],
'mastodon' => [
'regex' => 'Please verify your Mastodon handle, it must be in the format [email protected]' // TODO: update if needed
'regex' => 'Please verify your Mastodon handle, it must be in the format [email protected]'
],
'bluesky' => [
'regex' => 'Please verify your Bluesky handle, it must be between 3 and 64 characters and only contain letters, numbers, dots (.) and underscores (_).' // TODO: update if needed
'regex' => 'Please verify your Bluesky handle, it may only contain letters, numbers, dots (.) and hyphens (-).'
],
'telegram' => [
'regex' => 'Please verify your Telegram handle, it must be between 5 and 32 characters and only contain letters, numbers and underscores (_).'
Expand Down

0 comments on commit 6914003

Please sign in to comment.