mirror of
https://github.com/jbcr/core.git
synced 2026-04-27 10:45:54 +02:00
csfix
This commit is contained in:
@@ -88,14 +88,13 @@ class ProfileController extends TwigAwareController implements BackendZoneInterf
|
||||
$newPassword = $request->get('password');
|
||||
|
||||
// Set the plain password to check for validation
|
||||
if(! empty($newPassword))
|
||||
{
|
||||
if (! empty($newPassword)) {
|
||||
$user->setPassword($newPassword);
|
||||
}
|
||||
|
||||
$validator = new UserValidator($user);
|
||||
|
||||
if(! $validator->validate()) {
|
||||
if (! $validator->validate()) {
|
||||
$this->userValidationHandler->handle($validator);
|
||||
|
||||
$suggestedPassword = $validator->hasPasswordError() ? Str::generatePassword() : null;
|
||||
@@ -103,13 +102,12 @@ class ProfileController extends TwigAwareController implements BackendZoneInterf
|
||||
return $this->renderTemplate('@bolt/users/edit.html.twig', [
|
||||
'display_name' => $displayName,
|
||||
'userEdit' => $user,
|
||||
'suggestedPassword' => $suggestedPassword
|
||||
'suggestedPassword' => $suggestedPassword,
|
||||
]);
|
||||
}
|
||||
|
||||
// Once validated, encode the password
|
||||
if(! empty($newPassword))
|
||||
{
|
||||
if (! empty($newPassword)) {
|
||||
$user->setPassword($this->passwordEncoder->encodePassword($user, $newPassword));
|
||||
}
|
||||
|
||||
|
||||
@@ -149,14 +149,13 @@ class UserEditController extends TwigAwareController implements BackendZoneInter
|
||||
$user->setbackendTheme($request->get('backendTheme'));
|
||||
$newPassword = $request->get('password');
|
||||
// Set the plain password to check for validation
|
||||
if(! empty($newPassword))
|
||||
{
|
||||
if (! empty($newPassword)) {
|
||||
$user->setPassword($newPassword);
|
||||
}
|
||||
|
||||
$validator = new UserValidator($user);
|
||||
|
||||
if(! $validator->validate()) {
|
||||
if (! $validator->validate()) {
|
||||
$this->userValidationHandler->handle($validator);
|
||||
|
||||
$suggestedPassword = $validator->hasPasswordError() ? Str::generatePassword() : null;
|
||||
@@ -164,13 +163,12 @@ class UserEditController extends TwigAwareController implements BackendZoneInter
|
||||
return $this->renderTemplate('@bolt/users/edit.html.twig', [
|
||||
'display_name' => $displayName,
|
||||
'userEdit' => $user,
|
||||
'suggestedPassword' => $suggestedPassword
|
||||
'suggestedPassword' => $suggestedPassword,
|
||||
]);
|
||||
}
|
||||
|
||||
// Once validated, encode the password
|
||||
if(! empty($newPassword))
|
||||
{
|
||||
if (! empty($newPassword)) {
|
||||
$user->setPassword($this->passwordEncoder->encodePassword($user, $newPassword));
|
||||
}
|
||||
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Bolt\Utils;
|
||||
|
||||
use Symfony\Component\HttpFoundation\RequestStack;
|
||||
use Symfony\Component\HttpFoundation\Session\Session;
|
||||
|
||||
class UserValidationHandler
|
||||
{
|
||||
@@ -14,29 +17,28 @@ class UserValidationHandler
|
||||
$this->requestStack = $requestStack;
|
||||
}
|
||||
|
||||
public function handle(UserValidator $validator)
|
||||
public function handle(UserValidator $validator): void
|
||||
{
|
||||
foreach($validator->getValidationErrors() as $error)
|
||||
{
|
||||
if($error === UserValidator::DISPLAY_NAME_ERROR)
|
||||
{
|
||||
foreach ($validator->getValidationErrors() as $error) {
|
||||
if ($error === UserValidator::DISPLAY_NAME_ERROR) {
|
||||
$this->addFlash('danger', 'user.not_valid_display_name');
|
||||
}
|
||||
|
||||
if ($error === UserValidator::PASSWORD_ERROR)
|
||||
{
|
||||
if ($error === UserValidator::PASSWORD_ERROR) {
|
||||
$this->addFlash('danger', 'user.not_valid_password');
|
||||
}
|
||||
|
||||
if ($error === UserValidator::EMAIL_ERROR)
|
||||
{
|
||||
if ($error === UserValidator::EMAIL_ERROR) {
|
||||
$this->addFlash('danger', 'user.not_valid_email');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function addFlash(string $type, string $message)
|
||||
private function addFlash(string $type, string $message): void
|
||||
{
|
||||
$this->requestStack->getCurrentRequest()->getSession()->getFlashBag()->add($type, $message);
|
||||
/** @var Session $session */
|
||||
$session = $this->requestStack->getCurrentRequest()->getSession();
|
||||
|
||||
$session->getFlashBag()->add($type, $message);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Bolt\Utils;
|
||||
|
||||
use Bolt\Entity\User;
|
||||
@@ -11,9 +13,9 @@ use Bolt\Entity\User;
|
||||
*/
|
||||
class UserValidator
|
||||
{
|
||||
const DISPLAY_NAME_ERROR = 1;
|
||||
const PASSWORD_ERROR = 2;
|
||||
const EMAIL_ERROR = 3;
|
||||
public const DISPLAY_NAME_ERROR = 1;
|
||||
public const PASSWORD_ERROR = 2;
|
||||
public const EMAIL_ERROR = 3;
|
||||
|
||||
/** @var string */
|
||||
private $password;
|
||||
@@ -25,7 +27,7 @@ class UserValidator
|
||||
private $email;
|
||||
|
||||
/** @var array */
|
||||
private $validationErrors;
|
||||
private $validationErrors = [];
|
||||
|
||||
public function __construct(User $user)
|
||||
{
|
||||
@@ -35,25 +37,16 @@ class UserValidator
|
||||
$this->validationErrors = [];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $password
|
||||
*/
|
||||
public function setPassword(string $password): void
|
||||
{
|
||||
$this->password = $password;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $displayName
|
||||
*/
|
||||
public function setDisplayName(string $displayName): void
|
||||
{
|
||||
$this->displayName = $displayName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $email
|
||||
*/
|
||||
public function setEmail(string $email): void
|
||||
{
|
||||
$this->email = $email;
|
||||
@@ -71,7 +64,6 @@ class UserValidator
|
||||
|
||||
// Validate username
|
||||
if ($this->displayName !== null && ! filter_var(mb_strlen(trim($this->displayName)), FILTER_VALIDATE_INT, $usernameValidateOptions)) {
|
||||
dump("here");
|
||||
$this->validationErrors[] = self::DISPLAY_NAME_ERROR;
|
||||
$valid = false;
|
||||
}
|
||||
@@ -98,7 +90,6 @@ class UserValidator
|
||||
|
||||
public function hasPasswordError(): bool
|
||||
{
|
||||
return in_array(UserValidator::PASSWORD_ERROR, $this->validationErrors);
|
||||
return in_array(self::PASSWORD_ERROR, $this->validationErrors, true);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user