dynamicness!!!
This commit is contained in:
parent
a6069caaa4
commit
c2d60e216c
5 changed files with 71 additions and 29 deletions
|
@ -30,7 +30,6 @@ class AccountController extends Controller
|
||||||
}
|
}
|
||||||
|
|
||||||
if (session_check()) {
|
if (session_check()) {
|
||||||
$redirect = route('settings.account.profile');
|
|
||||||
$save = [];
|
$save = [];
|
||||||
$allowed = [
|
$allowed = [
|
||||||
'website',
|
'website',
|
||||||
|
@ -64,9 +63,9 @@ class AccountController extends Controller
|
||||||
if (!checkdate($month, $day, $year ? $year : 1)
|
if (!checkdate($month, $day, $year ? $year : 1)
|
||||||
|| $year > date("Y")
|
|| $year > date("Y")
|
||||||
|| ($year != 0 && $year < (date("Y") - 100))) {
|
|| ($year != 0 && $year < (date("Y") - 100))) {
|
||||||
$message = "Your birthdate was invalid, everything else was saved though!";
|
return $this->json(
|
||||||
|
['error' => "Your birthdate was invalid, everything else was saved though!"]
|
||||||
return view('global/information', compact('message', 'redirect'));
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Combine it into a YYYY-MM-DD format
|
// Combine it into a YYYY-MM-DD format
|
||||||
|
@ -80,8 +79,7 @@ class AccountController extends Controller
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
redirect($redirect);
|
return $this->json(['error' => null]);
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return view('settings/account/profile');
|
return view('settings/account/profile');
|
||||||
|
@ -110,20 +108,21 @@ class AccountController extends Controller
|
||||||
$username_allow = $edit_usern && (time() - $last_name_change) > 2592000;
|
$username_allow = $edit_usern && (time() - $last_name_change) > 2592000;
|
||||||
|
|
||||||
if (isset($_POST['session']) && session_check()) {
|
if (isset($_POST['session']) && session_check()) {
|
||||||
$redirect = route('settings.account.details');
|
|
||||||
$email = $_POST['email'] ?? null;
|
$email = $_POST['email'] ?? null;
|
||||||
|
|
||||||
if ($email) {
|
if ($email) {
|
||||||
// Validate e-mail address
|
// Validate e-mail address
|
||||||
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
|
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
|
||||||
$message = "The e-mail address you supplied is invalid!";
|
return $this->json(
|
||||||
return view('global/information', compact('redirect', 'message'));
|
['error' => "The e-mail address you supplied is invalid!"]
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check the MX record of the email
|
// Check the MX record of the email
|
||||||
if (!check_mx_record($email)) {
|
if (!check_mx_record($email)) {
|
||||||
$message = 'No valid MX-Record found on the e-mail address you supplied.';
|
return $this->json(
|
||||||
return view('global/information', compact('redirect', 'message'));
|
['error' => 'No valid MX-Record found on the e-mail address you supplied.']
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if the e-mail has already been used
|
// Check if the e-mail has already been used
|
||||||
|
@ -131,8 +130,9 @@ class AccountController extends Controller
|
||||||
->where('email', $email)
|
->where('email', $email)
|
||||||
->count();
|
->count();
|
||||||
if ($emailCheck) {
|
if ($emailCheck) {
|
||||||
$message = 'Someone already used this e-mail!';
|
return $this->json(
|
||||||
return view('global/information', compact('redirect', 'message'));
|
['error' => 'Someone already used this e-mail!']
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
$user->setMail($email);
|
$user->setMail($email);
|
||||||
|
@ -145,14 +145,16 @@ class AccountController extends Controller
|
||||||
|
|
||||||
// Check if the username is too short
|
// Check if the username is too short
|
||||||
if (strlen($username_clean) < config('user.name_min')) {
|
if (strlen($username_clean) < config('user.name_min')) {
|
||||||
$message = "This username is too short!";
|
return $this->json(
|
||||||
return view('global/information', compact('redirect', 'message'));
|
['error' => 'This username is too short!']
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if the username is too long
|
// Check if the username is too long
|
||||||
if (strlen($username_clean) > config('user.name_max')) {
|
if (strlen($username_clean) > config('user.name_max')) {
|
||||||
$message = "This username is too long!";
|
return $this->json(
|
||||||
return view('global/information', compact('redirect', 'message'));
|
['error' => 'This username is too long!']
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if this username hasn't been used in the last amount of days set in the config
|
// Check if this username hasn't been used in the last amount of days set in the config
|
||||||
|
@ -164,8 +166,9 @@ class AccountController extends Controller
|
||||||
|
|
||||||
// Check if anything was returned
|
// Check if anything was returned
|
||||||
if ($getOld && $getOld->user_id != $user->id) {
|
if ($getOld && $getOld->user_id != $user->id) {
|
||||||
$message = "The username you tried to use is reserved, try again later!";
|
return $this->json(
|
||||||
return view('global/information', compact('redirect', 'message'));
|
['error' => 'The username you tried to use is reserved, try again later!']
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if the username is already in use
|
// Check if the username is already in use
|
||||||
|
@ -175,8 +178,9 @@ class AccountController extends Controller
|
||||||
|
|
||||||
// Check if anything was returned
|
// Check if anything was returned
|
||||||
if ($getInUse) {
|
if ($getInUse) {
|
||||||
$message = "Someone is already using this name!";
|
return $this->json(
|
||||||
return view('global/information', compact('redirect', 'message'));
|
['error' => 'Someone is already using this name!']
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
$user->setUsername($username);
|
$user->setUsername($username);
|
||||||
|
@ -186,8 +190,9 @@ class AccountController extends Controller
|
||||||
|
|
||||||
if ($title) {
|
if ($title) {
|
||||||
if (strlen($title) > 64) {
|
if (strlen($title) > 64) {
|
||||||
$message = "This title is too long!";
|
return $this->json(
|
||||||
return view('global/information', compact('redirect', 'message'));
|
['error' => 'This title is too long!']
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($title !== $user->title) {
|
if ($title !== $user->title) {
|
||||||
|
@ -205,15 +210,15 @@ class AccountController extends Controller
|
||||||
if ($password) {
|
if ($password) {
|
||||||
// Check password entropy
|
// Check password entropy
|
||||||
if (password_entropy($password) < config('user.pass_min_entropy')) {
|
if (password_entropy($password) < config('user.pass_min_entropy')) {
|
||||||
$message = "Your password isn't strong enough!";
|
return $this->json(
|
||||||
return view('global/information', compact('redirect', 'message'));
|
['error' => "Your password isn't strong enough!"]
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
$user->setPassword($password);
|
$user->setPassword($password);
|
||||||
}
|
}
|
||||||
|
|
||||||
redirect($redirect);
|
return $this->json(['error' => null]);
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return view('settings/account/details', compact(
|
return view('settings/account/details', compact(
|
||||||
|
|
|
@ -46,6 +46,8 @@ namespace Sakura
|
||||||
DOM.Append(text, DOM.Text(this.Text));
|
DOM.Append(text, DOM.Text(this.Text));
|
||||||
DOM.Append(container, text);
|
DOM.Append(container, text);
|
||||||
|
|
||||||
|
var firstBtn: HTMLButtonElement = null;
|
||||||
|
|
||||||
for (var btnId in buttons) {
|
for (var btnId in buttons) {
|
||||||
var btnType: DialogueButton = buttons[btnId],
|
var btnType: DialogueButton = buttons[btnId],
|
||||||
btnText: string = DialogueButton[btnType],
|
btnText: string = DialogueButton[btnType],
|
||||||
|
@ -58,12 +60,17 @@ namespace Sakura
|
||||||
});
|
});
|
||||||
|
|
||||||
DOM.Append(buttonCont, button);
|
DOM.Append(buttonCont, button);
|
||||||
|
|
||||||
|
if (firstBtn === null) {
|
||||||
|
firstBtn = button;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
DOM.Append(container, buttonCont);
|
DOM.Append(container, buttonCont);
|
||||||
|
|
||||||
DOM.Append(DOM.ID('dialogues'), container);
|
DOM.Append(DOM.ID('dialogues'), container);
|
||||||
this.Reference = container;
|
this.Reference = container;
|
||||||
|
firstBtn.focus();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Close(): void
|
public Close(): void
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block settingsContent %}
|
{% block settingsContent %}
|
||||||
<form enctype="multipart/form-data" method="post" action="{{ route('settings.account.details') }}">
|
<form enctype="multipart/form-data" method="post" action="javascript:;" onsubmit="updateSettings(this, '{{ route('settings.account.details') }}');">
|
||||||
{% if edit_email %}
|
{% if edit_email %}
|
||||||
<div class="profile-field">
|
<div class="profile-field">
|
||||||
<div><h2>E-mail address</h2></div>
|
<div><h2>E-mail address</h2></div>
|
||||||
|
|
|
@ -1,3 +1,33 @@
|
||||||
{% extends 'settings/master.twig' %}
|
{% extends 'settings/master.twig' %}
|
||||||
|
|
||||||
{% set category = 'Account' %}
|
{% set category = 'Account' %}
|
||||||
|
|
||||||
|
{% block js %}
|
||||||
|
<script>
|
||||||
|
function updateSettings(form, action) {
|
||||||
|
var forms = {},
|
||||||
|
dialogue = new Sakura.Dialogue,
|
||||||
|
updater = new Sakura.AJAX;
|
||||||
|
|
||||||
|
dialogue.AddCallback(Sakura.DialogueButton.Ok, function () {
|
||||||
|
this.Close();
|
||||||
|
});
|
||||||
|
|
||||||
|
for (var a = 0; a < form.elements.length; a++) {
|
||||||
|
forms[form.elements.item(a).name] = form.elements.item(a).value;
|
||||||
|
}
|
||||||
|
|
||||||
|
updater.SetUrl(action);
|
||||||
|
updater.Form();
|
||||||
|
updater.SetSend(forms);
|
||||||
|
updater.AddCallback(0, function () {
|
||||||
|
var resp = updater.JSON();
|
||||||
|
dialogue.Text = resp.error || 'Updated!';
|
||||||
|
dialogue.Display();
|
||||||
|
});
|
||||||
|
updater.Start(Sakura.HTTPMethod.POST);
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
{% endblock %}
|
||||||
|
|
|
@ -90,7 +90,7 @@
|
||||||
{% set birthday = user.birthday|split('-') %}
|
{% set birthday = user.birthday|split('-') %}
|
||||||
|
|
||||||
{% block settingsContent %}
|
{% block settingsContent %}
|
||||||
<form enctype="multipart/form-data" method="post" action="{{ route('settings.account.profile') }}">
|
<form enctype="multipart/form-data" method="post" action="javascript:;" onsubmit="updateSettings(this, '{{ route('settings.account.profile') }}');">
|
||||||
{% for id, vars in fields %}
|
{% for id, vars in fields %}
|
||||||
<div class="profile-field {{ id }}">
|
<div class="profile-field {{ id }}">
|
||||||
<div>
|
<div>
|
||||||
|
|
Reference in a new issue