Mirror, mirror, on the wall, who has the smallest brain of them all?
This commit is contained in:
parent
391d8e9cc7
commit
a23b2729cc
2 changed files with 79 additions and 289 deletions
|
@ -12,6 +12,60 @@ if ($settings_session === null) {
|
|||
return;
|
||||
}
|
||||
|
||||
$settings_profile_fields = [
|
||||
'twitter' => [
|
||||
'name' => 'Twitter',
|
||||
'regex' => '#^(?:https?://(?:www\.)?twitter.com/(?:\#!\/)?)?@?([A-Za-z0-9_]{1,20})/?$#u',
|
||||
'no-match' => 'Twitter field was invalid.',
|
||||
],
|
||||
'osu' => [
|
||||
'name' => 'osu!',
|
||||
'regex' => '#^(?:https?://osu.ppy.sh/u(?:sers)?/)?([a-zA-Z0-9-\[\]_ ]{1,20})/?$#u',
|
||||
'no-match' => 'osu! field was invalid.',
|
||||
],
|
||||
'website' => [
|
||||
'name' => 'Website',
|
||||
'type' => 'url',
|
||||
'regex' => '#^((?:https?)://.{1,240})$#u',
|
||||
'no-match' => 'Website field was invalid.',
|
||||
],
|
||||
'youtube' => [
|
||||
'name' => 'Youtube',
|
||||
'regex' => '#^(?:https?://(?:www.)?youtube.com/(?:(?:user|c|channel)/)?)?(UC[a-zA-Z0-9-_]{1,22}|[a-zA-Z0-9-_%]{1,100})/?$#u',
|
||||
'no-match' => 'Youtube field was invalid.',
|
||||
],
|
||||
'steam' => [
|
||||
'name' => 'Steam',
|
||||
'regex' => '#^(?:https?://(?:www.)?steamcommunity.com/(?:id|profiles)/)?([a-zA-Z0-9_-]{2,100})/?$#u',
|
||||
'no-match' => 'Steam field was invalid.',
|
||||
],
|
||||
'twitchtv' => [
|
||||
'name' => 'Twitch.tv',
|
||||
'regex' => '#^(?:https?://(?:www.)?twitch.tv/)?([0-9A-Za-z_]{3,25})/?$#u',
|
||||
'no-match' => 'Twitch.tv field was invalid.',
|
||||
],
|
||||
'lastfm' => [
|
||||
'name' => 'Last.fm',
|
||||
'regex' => '#^(?:https?://(?:www.)?last.fm/user/)?([a-zA-Z]{1}[a-zA-Z0-9_-]{1,14})/?$#u',
|
||||
'no-match' => 'Last.fm field was invalid.',
|
||||
],
|
||||
'github' => [
|
||||
'name' => 'Github',
|
||||
'regex' => '#^(?:https?://(?:www.)?github.com/?)?([a-zA-Z0-9](?:[a-zA-Z0-9]|-(?=[a-zA-Z0-9])){0,38})/?$#u',
|
||||
'no-match' => 'Github field was invalid.',
|
||||
],
|
||||
'skype' => [
|
||||
'name' => 'Skype',
|
||||
'regex' => '#^((?:live:)?[a-zA-Z][\w\.,\-_@]{1,100})$#u',
|
||||
'no-match' => 'Skype field was invalid.',
|
||||
],
|
||||
'discord' => [
|
||||
'name' => 'Discord',
|
||||
'regex' => '#^(.{1,32}\#[0-9]{4})$#u',
|
||||
'no-match' => 'Discord field was invalid.',
|
||||
],
|
||||
];
|
||||
|
||||
$settings_user = $settings_session->user;
|
||||
|
||||
$settings_mode = $_GET['m'] ?? null;
|
||||
|
@ -46,216 +100,27 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|||
}
|
||||
|
||||
if (isset($_POST['profile']) && is_array($_POST['profile'])) {
|
||||
if (isset($_POST['profile']['twitter'])) {
|
||||
$user_twitter = '';
|
||||
foreach ($settings_profile_fields as $name => $props) {
|
||||
if (isset($_POST['profile'][$name])) {
|
||||
$field_value = '';
|
||||
|
||||
if (!empty($_POST['profile']['twitter'])) {
|
||||
$twitter_regex = preg_match(
|
||||
'#^(?:https?://(?:www\.)?twitter.com/(?:\#!\/)?)?@?([A-Za-z0-9_]{1,20})/?$#u',
|
||||
$_POST['profile']['twitter'],
|
||||
$twitter_matches
|
||||
);
|
||||
if (!empty($_POST['profile'][$name])) {
|
||||
$field_regex = preg_match(
|
||||
$props['regex'],
|
||||
$_POST['profile'][$name],
|
||||
$field_matches
|
||||
);
|
||||
|
||||
if ($twitter_regex !== 1) {
|
||||
$settings_errors[] = "Invalid Twitter field.";
|
||||
break;
|
||||
if ($field_regex !== 1) {
|
||||
$settings_errors[] = $props['no-match'];
|
||||
break;
|
||||
}
|
||||
|
||||
$field_value = $field_matches[1];
|
||||
}
|
||||
|
||||
$user_twitter = $twitter_matches[1];
|
||||
$settings_user->{"user_{$name}"} = $field_value;
|
||||
}
|
||||
|
||||
$settings_user->user_twitter = $user_twitter;
|
||||
}
|
||||
|
||||
if (isset($_POST['profile']['osu'])) {
|
||||
$user_osu = '';
|
||||
|
||||
if (!empty($_POST['profile']['osu'])) {
|
||||
$osu_regex = preg_match(
|
||||
'#^(?:https?://osu.ppy.sh/u(?:sers)?/)?([a-zA-Z0-9-\[\]_ ]{1,20})/?$#u',
|
||||
$_POST['profile']['osu'],
|
||||
$osu_matches
|
||||
);
|
||||
|
||||
if ($osu_regex !== 1) {
|
||||
$settings_errors[] = "Invalid osu! field.";
|
||||
break;
|
||||
}
|
||||
|
||||
$user_osu = $osu_matches[1];
|
||||
}
|
||||
|
||||
$settings_user->user_osu = $user_osu;
|
||||
}
|
||||
|
||||
if (isset($_POST['profile']['website'])) {
|
||||
$user_website = '';
|
||||
|
||||
if (!empty($_POST['profile']['website'])) {
|
||||
$website_regex = preg_match(
|
||||
'#^(?:https?)://(.{1,240})$#u',
|
||||
$_POST['profile']['website'],
|
||||
$website_matches
|
||||
);
|
||||
|
||||
if ($website_regex !== 1) {
|
||||
$settings_errors[] = "Invalid website field.";
|
||||
break;
|
||||
}
|
||||
|
||||
$user_website = $website_matches[0];
|
||||
}
|
||||
|
||||
$settings_user->user_website = $user_website;
|
||||
}
|
||||
|
||||
if (isset($_POST['profile']['youtube'])) {
|
||||
$user_youtube = '';
|
||||
|
||||
if (!empty($_POST['profile']['youtube'])) {
|
||||
$youtube_regex = preg_match(
|
||||
'#^(?:https?://(?:www.)?youtube.com/(?:(?:user|c|channel)/)?)?'
|
||||
. '(UC[a-zA-Z0-9-_]{1,22}|[a-zA-Z0-9-_%]{1,100})/?$#u',
|
||||
$_POST['profile']['youtube'],
|
||||
$youtube_matches
|
||||
);
|
||||
|
||||
if ($youtube_regex !== 1) {
|
||||
$settings_errors[] = "Invalid Youtube field.";
|
||||
break;
|
||||
}
|
||||
|
||||
$user_youtube = $youtube_matches[1];
|
||||
}
|
||||
|
||||
$settings_user->user_youtube = $user_youtube;
|
||||
}
|
||||
|
||||
if (isset($_POST['profile']['steam'])) {
|
||||
$user_steam = '';
|
||||
|
||||
if (!empty($_POST['profile']['steam'])) {
|
||||
$steam_regex = preg_match(
|
||||
'#^(?:https?://(?:www.)?steamcommunity.com/(?:id|profiles)/)?([a-zA-Z0-9_-]{2,100})/?$#u',
|
||||
$_POST['profile']['steam'],
|
||||
$steam_matches
|
||||
);
|
||||
|
||||
if ($steam_regex !== 1) {
|
||||
$settings_errors[] = "Invalid Steam field.";
|
||||
break;
|
||||
}
|
||||
|
||||
$user_steam = $steam_matches[1];
|
||||
}
|
||||
|
||||
$settings_user->user_steam = $user_steam;
|
||||
}
|
||||
|
||||
if (isset($_POST['profile']['twitchtv'])) {
|
||||
$user_twitchtv = '';
|
||||
|
||||
if (!empty($_POST['profile']['twitchtv'])) {
|
||||
$twitchtv_regex = preg_match(
|
||||
'#^(?:https?://(?:www.)?twitch.tv/)?([0-9A-Za-z_]{3,25})/?$#u',
|
||||
$_POST['profile']['twitchtv'],
|
||||
$twitchtv_matches
|
||||
);
|
||||
|
||||
if ($twitchtv_regex !== 1) {
|
||||
$settings_errors[] = "Invalid Twitch.TV field.";
|
||||
break;
|
||||
}
|
||||
|
||||
$user_twitchtv = $twitchtv_matches[1];
|
||||
}
|
||||
|
||||
$settings_user->user_twitchtv = $user_twitchtv;
|
||||
}
|
||||
|
||||
if (isset($_POST['profile']['lastfm'])) {
|
||||
$user_lastfm = '';
|
||||
|
||||
if (!empty($_POST['profile']['lastfm'])) {
|
||||
$lastfm_regex = preg_match(
|
||||
'#^(?:https?://(?:www.)?last.fm/user/)?([a-zA-Z]{1}[a-zA-Z0-9_-]{1,14})/?$#u',
|
||||
$_POST['profile']['lastfm'],
|
||||
$lastfm_matches
|
||||
);
|
||||
|
||||
if ($lastfm_regex !== 1) {
|
||||
$settings_errors[] = "Invalid Last.fm field.";
|
||||
break;
|
||||
}
|
||||
|
||||
$user_lastfm = $lastfm_matches[1];
|
||||
}
|
||||
|
||||
$settings_user->user_lastfm = $user_lastfm;
|
||||
}
|
||||
|
||||
if (isset($_POST['profile']['github'])) {
|
||||
$user_github = '';
|
||||
|
||||
if (!empty($_POST['profile']['github'])) {
|
||||
$github_regex = preg_match(
|
||||
'#^(?:https?://(?:www.)?github.com/?)?'
|
||||
. '([a-zA-Z0-9](?:[a-zA-Z0-9]|-(?=[a-zA-Z0-9])){0,38})/?$#u',
|
||||
$_POST['profile']['github'],
|
||||
$github_matches
|
||||
);
|
||||
|
||||
if ($github_regex !== 1) {
|
||||
$settings_errors[] = "Invalid Github field.";
|
||||
break;
|
||||
}
|
||||
|
||||
$user_github = $github_matches[1];
|
||||
}
|
||||
|
||||
$settings_user->user_github = $user_github;
|
||||
}
|
||||
|
||||
if (isset($_POST['profile']['skype'])) {
|
||||
$user_skype = '';
|
||||
|
||||
if (!empty($_POST['profile']['skype'])) {
|
||||
$skype_regex = preg_match(
|
||||
'#^((?:live:)?[a-zA-Z][\w\.,\-_@]{1,100})$#u',
|
||||
$_POST['profile']['skype'],
|
||||
$skype_matches
|
||||
);
|
||||
|
||||
if ($skype_regex !== 1) {
|
||||
$settings_errors[] = "Invalid Skype field.";
|
||||
break;
|
||||
}
|
||||
|
||||
$user_skype = $skype_matches[1];
|
||||
}
|
||||
|
||||
$settings_user->user_skype = $user_skype;
|
||||
}
|
||||
|
||||
if (isset($_POST['profile']['discord'])) {
|
||||
$user_discord = '';
|
||||
|
||||
if (!empty($_POST['profile']['discord'])) {
|
||||
$discord_regex = preg_match(
|
||||
'#^(.{1,32}\#[0-9]{4})$#u',
|
||||
$_POST['profile']['discord'],
|
||||
$discord_matches
|
||||
);
|
||||
|
||||
if ($discord_regex !== 1) {
|
||||
$settings_errors[] = "Invalid Discord field.";
|
||||
break;
|
||||
}
|
||||
|
||||
$user_discord = $discord_matches[1];
|
||||
}
|
||||
|
||||
$settings_user->user_discord = $user_discord;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -335,6 +200,10 @@ $app->templating->vars(compact('settings_errors'));
|
|||
$app->templating->var('settings_title', $settings_modes[$settings_mode]);
|
||||
|
||||
switch ($settings_mode) {
|
||||
case 'account':
|
||||
$app->templating->vars(compact('settings_profile_fields'));
|
||||
break;
|
||||
|
||||
case 'sessions':
|
||||
$app->templating->var('user_sessions', $settings_user->sessions->reverse());
|
||||
break;
|
||||
|
|
|
@ -6,95 +6,16 @@
|
|||
<div class="mio__settings__account__column">
|
||||
<div class="mio__settings__account__title">Profile</div>
|
||||
|
||||
<label class="mio__settings__account__input">
|
||||
{% for name, props in settings_profile_fields %}
|
||||
<label class="mio__settings__account__input mio__settings__account__input--{{ name }}">
|
||||
<div class="mio__settings__account__input__name">
|
||||
Twitter
|
||||
{{ props.name }}
|
||||
</div>
|
||||
<div class="mio__settings__account__input__value">
|
||||
<input type="text" name="profile[twitter]" value="{{ settings_user.user_twitter }}" class="mio__input__text mio__settings__account__input__value__text">
|
||||
</div>
|
||||
</label>
|
||||
|
||||
<label class="mio__settings__account__input">
|
||||
<div class="mio__settings__account__input__name">
|
||||
osu!
|
||||
</div>
|
||||
<div class="mio__settings__account__input__value">
|
||||
<input type="text" name="profile[osu]" value="{{ settings_user.user_osu }}" class="mio__input__text mio__settings__account__input__value__text">
|
||||
</div>
|
||||
</label>
|
||||
|
||||
<label class="mio__settings__account__input">
|
||||
<div class="mio__settings__account__input__name">
|
||||
Website
|
||||
</div>
|
||||
<div class="mio__settings__account__input__value">
|
||||
<input type="url" name="profile[website]" value="{{ settings_user.user_website }}" class="mio__input__text mio__settings__account__input__value__text">
|
||||
</div>
|
||||
</label>
|
||||
|
||||
<label class="mio__settings__account__input">
|
||||
<div class="mio__settings__account__input__name">
|
||||
Youtube
|
||||
</div>
|
||||
<div class="mio__settings__account__input__value">
|
||||
<input type="text" name="profile[youtube]" value="{{ settings_user.user_youtube }}" class="mio__input__text mio__settings__account__input__value__text">
|
||||
</div>
|
||||
</label>
|
||||
|
||||
<label class="mio__settings__account__input">
|
||||
<div class="mio__settings__account__input__name">
|
||||
Steam
|
||||
</div>
|
||||
<div class="mio__settings__account__input__value">
|
||||
<input type="text" name="profile[steam]" value="{{ settings_user.user_steam }}" class="mio__input__text mio__settings__account__input__value__text">
|
||||
</div>
|
||||
</label>
|
||||
|
||||
<label class="mio__settings__account__input">
|
||||
<div class="mio__settings__account__input__name">
|
||||
Twitch.TV
|
||||
</div>
|
||||
<div class="mio__settings__account__input__value">
|
||||
<input type="text" name="profile[twitchtv]" value="{{ settings_user.user_twitchtv }}" class="mio__input__text mio__settings__account__input__value__text">
|
||||
</div>
|
||||
</label>
|
||||
|
||||
<label class="mio__settings__account__input">
|
||||
<div class="mio__settings__account__input__name">
|
||||
Last.fm
|
||||
</div>
|
||||
<div class="mio__settings__account__input__value">
|
||||
<input type="text" name="profile[lastfm]" value="{{ settings_user.user_lastfm }}" class="mio__input__text mio__settings__account__input__value__text">
|
||||
</div>
|
||||
</label>
|
||||
|
||||
<label class="mio__settings__account__input">
|
||||
<div class="mio__settings__account__input__name">
|
||||
Github
|
||||
</div>
|
||||
<div class="mio__settings__account__input__value">
|
||||
<input type="text" name="profile[github]" value="{{ settings_user.user_github }}" class="mio__input__text mio__settings__account__input__value__text">
|
||||
</div>
|
||||
</label>
|
||||
|
||||
<label class="mio__settings__account__input">
|
||||
<div class="mio__settings__account__input__name">
|
||||
Skype
|
||||
</div>
|
||||
<div class="mio__settings__account__input__value">
|
||||
<input type="text" name="profile[skype]" value="{{ settings_user.user_skype }}" class="mio__input__text mio__settings__account__input__value__text">
|
||||
</div>
|
||||
</label>
|
||||
|
||||
<label class="mio__settings__account__input">
|
||||
<div class="mio__settings__account__input__name">
|
||||
Discord
|
||||
</div>
|
||||
<div class="mio__settings__account__input__value">
|
||||
<input type="text" name="profile[discord]" value="{{ settings_user.user_discord }}" class="mio__input__text mio__settings__account__input__value__text">
|
||||
<input type="{{ props.type|default('text') }}" name="profile[{{ name }}]" value="{{ settings_user['user_' ~ name] }}" class="mio__input__text mio__settings__account__input__value__text">
|
||||
</div>
|
||||
</label>
|
||||
{% endfor %}
|
||||
</div>
|
||||
|
||||
<div class="mio__settings__account__column mio__settings__account__column--no-margin">
|
||||
|
|
Loading…
Add table
Reference in a new issue