[WEB] Fix translations and small inconsistency when opening on web

This commit is contained in:
Hugo Sales 2021-04-10 22:32:47 +00:00
parent 8b5bd40421
commit 78548365da
Signed by untrusted user: someonewithpc
GPG Key ID: 7D0C7EAFC9D835A0
6 changed files with 26 additions and 31 deletions

View File

@ -6,6 +6,7 @@ use App\Core\Controller;
use App\Core\DB\DB;
use App\Core\Form;
use function App\Core\I18n\_m;
use App\Core\NoteScope;
use App\Entity\Follow;
use App\Entity\GSActor;
use App\Entity\LocalUser;
@ -40,7 +41,7 @@ class Security extends Controller
// last username entered by the user
$last_username = $authenticationUtils->getLastUsername();
return ['_template' => 'security/login.html.twig', 'last_username' => $last_username, 'error' => $error, 'notes' => Note::getAllNotes($this->instance_scope), ];
return ['_template' => 'security/login.html.twig', 'last_username' => $last_username, 'error' => $error, 'notes' => Note::getAllNotes(NoteScope::$instance_scope)];
}
public function logout()
@ -61,10 +62,10 @@ class Security extends Controller
['nickname', TextType::class, [
'label' => _m('Nickname'),
'constraints' => [new Length([
'min' => 1,
'minMessage' => _m('Your password should be at least {{ limit }} characters long'),
'max' => 64,
'maxMessage' => _m('Your password should be at most {{ limit }} characters long'), ]),
'min' => Common::config('nickname', 'min_length'),
'minMessage' => _m(['Your nickname must be at least # characters long'], ['count' => Common::config('nickname', 'min_length')]),
'max' => Nickname::MAX_LEN,
'maxMessage' => _m(['Your nickname must be at most # characters long'], ['count' => Nickname::MAX_LEN]), ]),
],
]],
['email', EmailType::class, ['label' => _m('Email')]],
@ -73,7 +74,8 @@ class Security extends Controller
'mapped' => false,
'constraints' => [
new NotBlank(['message' => _m('Please enter a password')]),
new Length(['min' => 6, 'minMessage' => _m('Your password should be at least {{ limit }} characters'), 'max' => 60]),
new Length(['min' => 6, 'minMessage' => _m(['Your password should be at least # characters'], ['count' => 6]),
'max' => 60, 'maxMessage' => _m(['Your password should be at most # characters'], ['count' => 60]), ]),
],
]],
['register', SubmitType::class, ['label' => _m('Register')]],
@ -85,10 +87,7 @@ class Security extends Controller
$data = $form->getData();
$data['password'] = $form->get('password')->getData();
$valid_nickname = Nickname::isValid($data['nickname'], Nickname::CHECK_USED);
if (!$valid_nickname) {
throw new \Exception(_m('Invalid nickname'));
}
$valid_nickname = Nickname::normalize($data['nickname'], check_already_used: true);
$actor = GSActor::create(['nickname' => $data['nickname']]);
DB::persist($actor);
@ -134,7 +133,7 @@ class Security extends Controller
return [
'_template' => 'security/register.html.twig',
'registration_form' => $form->createView(),
'notes' => Note::getAllNotes($this->instance_scope),
'notes' => Note::getAllNotes(NoteScope::$instance_scope),
];
}
}

View File

@ -29,4 +29,6 @@ class NoteScope extends Bitmap
public const GROUP = 8;
public const FOLLOWER = 16;
public const MESSAGE = 32;
public static int $instance_scope = self::PUBLIC | self::SITE;
}

View File

@ -41,6 +41,7 @@ use DateTimeInterface;
class Note extends Entity
{
// {{{ Autocode
private int $id;
private int $gsactor_id;
private ?string $content;
@ -199,7 +200,7 @@ class Note extends Entity
Event::handle('GetAvatarUrl', [$this->getActorNickname(), &$url]);
return $url;
}
public function getAllNotes(int $noteScope): array
public static function getAllNotes(int $noteScope): array
{
return DB::sql('select * from note n ' .
'where n.reply_to is null and (n.scope & :notescope) <> 0 ' .

View File

@ -94,14 +94,6 @@ abstract class Common
self::ensureLoggedIn()->getNickname();
}
public function getAllNotes(int $noteScope): array
{
return DB::sql('select * from note n ' .
"where n.reply_to is null and (n.scope & {$noteScope}) <> 0 " .
'order by n.created DESC',
['n' => 'App\Entity\Note']);
}
public static function ensureLoggedIn(): LocalUser
{
if (($user = self::user()) == null) {

View File

@ -42,13 +42,13 @@
namespace App\Util\Exception;
use function App\Core\I18n\_m;
use App\Util\Nickname;
use App\Util\Common;
class NicknameTooShortException extends NicknameInvalidException
{
protected function defaultMessage(): string
{
// TRANS: Validation error in form for registration, profile and group settings, etc.
return _m('Nickname cannot be more than # character long.', ['count' => Nickname::MAX_LEN]);
return _m(['Nickname cannot be less than # character long.'], ['count' => Common::config('nickname', 'min_length')]);
}
}

View File

@ -145,21 +145,22 @@ class Nickname
throw new NicknameTooLongException();
}
$nickname = trim($nickname);
$nickname = str_replace('_', '', $nickname);
$nickname = mb_strtolower($nickname);
$nickname = Normalizer::normalize($nickname, Normalizer::FORM_C);
$original_nickname = $nickname;
$nickname = trim($nickname);
$nickname = str_replace('_', '', $nickname);
$nickname = mb_strtolower($nickname);
$nickname = Normalizer::normalize($nickname, Normalizer::FORM_C);
if (mb_strlen($nickname) < 1) {
if (mb_strlen($original_nickname) < 1) {
throw new NicknameEmptyException();
} elseif (mb_strlen($nickname) < Common::config('nickname', 'min_length')) {
} elseif (mb_strlen($original_nickname) < Common::config('nickname', 'min_length')) {
throw new NicknameTooShortException();
} elseif (!self::isCanonical($nickname) && !filter_var($nickname, FILTER_VALIDATE_EMAIL)) {
} elseif (!self::isCanonical($original_nickname) && !filter_var($original_nickname, FILTER_VALIDATE_EMAIL)) {
throw new NicknameInvalidException();
} elseif ($check_reserved && self::isReserved($nickname) || Common::isSystemPath($nickname)) {
} elseif ($check_reserved && self::isReserved($original_nickname) || Common::isSystemPath($original_nickname)) {
throw new NicknameReservedException();
} elseif ($check_already_used) {
$actor = self::isTaken($nickname);
$actor = self::isTaken($original_nickname);
if ($actor instanceof GSActor) {
throw new NicknameTakenException($actor);
}