Compare commits
1 Commits
6fa1996f39
...
7812ea97dc
Author | SHA1 | Date | |
---|---|---|---|
7812ea97dc |
@ -158,17 +158,12 @@ var RVR = {
|
||||
document.getElementById('cover').style.visibility = 'hidden';
|
||||
},
|
||||
|
||||
observeInput: function (form, observedInputs) {
|
||||
var anyChanged = false;
|
||||
|
||||
for (var i = 0; i < observedInputs.length; i++) {
|
||||
var input = form.elements[observedInputs[i]];
|
||||
if (input.defaultValue !== input.value) {
|
||||
anyChanged = true;
|
||||
}
|
||||
observeInput: function (input, buttonToToggle) {
|
||||
if (input.defaultValue !== input.value) {
|
||||
buttonToToggle.disabled = false;
|
||||
} else {
|
||||
buttonToToggle.disabled = true;
|
||||
}
|
||||
|
||||
form.elements.submit.disabled = !anyChanged;
|
||||
},
|
||||
|
||||
observeInputsInForm: function (form, observedInputs) {
|
||||
@ -179,12 +174,12 @@ var RVR = {
|
||||
case 'INPUT':
|
||||
case 'TEXTAREA':
|
||||
input.oninput = function () {
|
||||
RVR.observeInput(form, observedInputs);
|
||||
RVR.observeInput(this, form.elements.submit);
|
||||
};
|
||||
break;
|
||||
case 'SELECT':
|
||||
input.onchange = function () {
|
||||
RVR.observeInput(form, observedInputs);
|
||||
RVR.observeInput(this, form.elements.submit);
|
||||
};
|
||||
break;
|
||||
}
|
||||
|
@ -21,11 +21,6 @@ class AddUserCommand extends Command
|
||||
|
||||
public function execute(InputInterface $input, OutputInterface $output): int
|
||||
{
|
||||
if (!filter_var($input->getArgument('email'), FILTER_VALIDATE_EMAIL)) {
|
||||
$output->writeln('<error>Please provide a valid email address.</error>');
|
||||
return 1;
|
||||
}
|
||||
|
||||
$user = new User();
|
||||
$user->setEmail($input->getArgument('email'));
|
||||
$user->setPlainPassword($input->getArgument('password'));
|
||||
|
@ -13,7 +13,6 @@ use SokoWeb\Response\HtmlContent;
|
||||
use SokoWeb\Response\JsonContent;
|
||||
use SokoWeb\Response\Redirect;
|
||||
use SokoWeb\Util\JwtParser;
|
||||
use RVR\Repository\UserRepository;
|
||||
|
||||
class UserController implements ISecured
|
||||
{
|
||||
@ -21,13 +20,10 @@ class UserController implements ISecured
|
||||
|
||||
private PersistentDataManager $pdm;
|
||||
|
||||
private UserRepository $userRepository;
|
||||
|
||||
public function __construct(IRequest $request)
|
||||
{
|
||||
$this->request = $request;
|
||||
$this->pdm = new PersistentDataManager();
|
||||
$this->userRepository = new UserRepository();
|
||||
}
|
||||
|
||||
public function authorize(): bool
|
||||
@ -130,39 +126,8 @@ class UserController implements ISecured
|
||||
return new JsonContent(['error' => ['errorText' => $error]]);
|
||||
}
|
||||
|
||||
$newEmail = $this->request->post('email');
|
||||
if ($newEmail !== $user->getEmail()) {
|
||||
if (!filter_var($newEmail, FILTER_VALIDATE_EMAIL)) {
|
||||
return new JsonContent(['error' => ['errorText' => 'Please provide a valid email address.']]);
|
||||
}
|
||||
|
||||
if ($this->userRepository->getByEmail($newEmail) !== null) {
|
||||
return new JsonContent(['error' => ['errorText' => 'The given email address belongs to another account.']]);
|
||||
}
|
||||
|
||||
$user->setEmail($newEmail);
|
||||
}
|
||||
|
||||
$newUsername = $this->request->post('username');
|
||||
if ($newUsername !== $user->getUsername()) {
|
||||
if (strlen($newUsername) > 0) {
|
||||
if (filter_var($newUsername, FILTER_VALIDATE_EMAIL)) {
|
||||
return new JsonContent(['error' => ['errorText' => 'Please select a username that is not a valid email address.']]);
|
||||
}
|
||||
|
||||
if ($this->userRepository->getByUsername($newUsername) !== null) {
|
||||
return new JsonContent(['error' => ['errorText' => 'The given username is already taken.']]);
|
||||
}
|
||||
|
||||
$user->setUsername($newUsername);
|
||||
} else {
|
||||
$user->setUsername(null);
|
||||
}
|
||||
}
|
||||
|
||||
$newPassword = $this->request->post('password_new');
|
||||
if (strlen($newPassword) > 0) {
|
||||
if (strlen($newPassword) < 6) {
|
||||
if (strlen($this->request->post('password_new')) > 0) {
|
||||
if (strlen($this->request->post('password_new')) < 6) {
|
||||
return new JsonContent([
|
||||
'error' => [
|
||||
'errorText' => 'The given new password is too short. Please choose a password that is at least 6 characters long!'
|
||||
@ -170,7 +135,7 @@ class UserController implements ISecured
|
||||
]);
|
||||
}
|
||||
|
||||
if ($newPassword !== $this->request->post('password_new_confirm')) {
|
||||
if ($this->request->post('password_new') !== $this->request->post('password_new_confirm')) {
|
||||
return new JsonContent([
|
||||
'error' => [
|
||||
'errorText' => 'The given new passwords do not match.'
|
||||
@ -178,7 +143,7 @@ class UserController implements ISecured
|
||||
]);
|
||||
}
|
||||
|
||||
$user->setPlainPassword($newPassword);
|
||||
$user->setPlainPassword($this->request->post('password_new'));
|
||||
}
|
||||
|
||||
$this->pdm->saveToDb($user);
|
||||
|
@ -29,7 +29,7 @@ class User extends Model implements IUser
|
||||
$this->email = $email;
|
||||
}
|
||||
|
||||
public function setUsername(?string $username): void
|
||||
public function setUsername(string $username): void
|
||||
{
|
||||
$this->username = $username;
|
||||
}
|
||||
|
@ -37,8 +37,9 @@ class UserRepository implements IUserRepository
|
||||
|
||||
public function getByEmailOrUsername(string $emailOrUsername): ?User
|
||||
{
|
||||
if (filter_var($emailOrUsername, FILTER_VALIDATE_EMAIL)) {
|
||||
return $this->getByEmail($emailOrUsername);
|
||||
$user = $this->getByEmail($emailOrUsername);
|
||||
if ($user !== null) {
|
||||
return $user;
|
||||
}
|
||||
|
||||
return $this->getByUsername($emailOrUsername);
|
||||
|
@ -5,11 +5,11 @@
|
||||
@section(main)
|
||||
<h2>Account</h2>
|
||||
<div class="box">
|
||||
<form id="accountForm" action="/account" method="post" data-observe-inputs="email,username,password_new,password_new_confirm">
|
||||
<form id="accountForm" action="/account" method="post" data-observe-inputs="password_new,password_new_confirm">
|
||||
<?php if ($user['password'] !== null && $user['google_sub'] !== null): ?>
|
||||
<p class="justify small">Please confirm your identity with your password or with Google to modify your account.</p>
|
||||
<div class="inputWithButton">
|
||||
<input type="password" class="text" name="password" placeholder="Current password" required minlength="6" autofocus><!--
|
||||
<input type="password" class="text name="password" placeholder="Current password" required minlength="6" autofocus><!--
|
||||
--><button id="authenticateWithGoogleButton" class="yellow" type="button">Google</button>
|
||||
</div>
|
||||
<?php elseif ($user['password'] !== null): ?>
|
||||
@ -23,8 +23,9 @@
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
<hr>
|
||||
<input type="email" class="text big fullWidth" name="email" placeholder="Email address" value="<?= $user['email'] ?>">
|
||||
<input type="text" class="text big fullWidth marginTop" name="username" placeholder="Username" value="<?= $user['username'] ?>">
|
||||
<?php /* TODO: disabled for the time being, email modification should be implemented */ ?>
|
||||
<input type="email" class="text big fullWidth" name="email" placeholder="Email address" value="<?= $user['email'] ?>" disabled>
|
||||
<input type="text" class="text big fullWidth marginTop" name="username" placeholder="Username" value="<?= $user['username'] ?>" disabled>
|
||||
<input type="password" class="text big fullWidth marginTop" name="password_new" placeholder="New password" minlength="6">
|
||||
<input type="password" class="text big fullWidth marginTop" name="password_new_confirm" placeholder="New password confirmation" minlength="6">
|
||||
<p id="accountFormError" class="formError justify marginTop"></p>
|
||||
|
Loading…
Reference in New Issue
Block a user