diff --git a/src/Controller/Security.php b/src/Controller/Security.php index f2e130497e..092f062138 100644 --- a/src/Controller/Security.php +++ b/src/Controller/Security.php @@ -5,6 +5,13 @@ namespace App\Controller; use App\Core\Controller; use App\Core\DB\DB; use App\Core\Form; +use App\Util\Exception\DuplicateFoundException; +use App\Util\Exception\NicknameEmptyException; +use App\Util\Exception\NicknameReservedException; +use App\Util\Exception\NicknameTooLongException; +use App\Util\Exception\NicknameTooShortException; +use App\Util\Exception\NotImplementedException; +use Symfony\Component\HttpFoundation\Response; use function App\Core\I18n\_m; use App\Core\Log; use App\Core\VisibilityScope; @@ -62,13 +69,29 @@ class Security extends Controller throw new \LogicException('This method can be blank - it will be intercepted by the logout key on your firewall.'); } + /** + * * Register a user, making sure the nickname is not reserved and * possibly sending a confirmation email + * + * @param Request $request + * @param GuardAuthenticatorHandler $guard_handler + * @param Authenticator $authenticator + * @return array|Response|null + * @throws EmailTakenException + * @throws NicknameTakenException + * @throws ServerException + * @throws DuplicateFoundException + * @throws NicknameEmptyException + * @throws NicknameReservedException + * @throws NicknameTooLongException + * @throws NicknameTooShortException + * @throws NotImplementedException */ - public function register(Request $request, + public function register(Request $request, GuardAuthenticatorHandler $guard_handler, - Authenticator $authenticator) + Authenticator $authenticator) { $form = Form::create([ ['nickname', TextType::class, [ @@ -84,6 +107,7 @@ class Security extends Controller ], 'block_name' => 'nickname', 'label_attr' => ['class' => 'section-form-label'], + 'invalid_message' => _m('Nickname not valid. Please provide a valid nickname.'), ]], ['email', EmailType::class, [ 'label' => _m('Email'), @@ -91,6 +115,7 @@ class Security extends Controller 'constraints' => [ new NotBlank(['message' => _m('Please enter an email') ])], 'block_name' => 'email', 'label_attr' => ['class' => 'section-form-label'], + 'invalid_message' => _m('Email not valid. Please provide a valid email.'), ]], FormFields::repeated_password(), ['register', SubmitType::class, ['label' => _m('Register')]], @@ -105,10 +130,15 @@ class Security extends Controller // This will throw the appropriate errors, result ignored $user = LocalUser::findByNicknameOrEmail($data['nickname'], $data['email']); if ($user !== null) { + // If we do find something, there's a duplicate - if ($user->getNickname() == $data['nickname']) { + if ($user->getNickname() === $data['nickname']) { + // Register page feedback on nickname already in use + $this->addFlash("verify_nickname_error", _m('Nickname is already in use on this server.')); throw new NicknameTakenException; } else { + // Register page feedback on email already in use + $this->addFlash("verify_email_error", _m('Email is already taken.')); throw new EmailTakenException; } } diff --git a/templates/security/login.html.twig b/templates/security/login.html.twig index 9279630823..d5091dc0c3 100644 --- a/templates/security/login.html.twig +++ b/templates/security/login.html.twig @@ -8,54 +8,58 @@ {% block title %}{{ "Log in!" | trans }}{% endblock %} {% block body %} -
-
-
-
-

{{ "Login" | trans }}

+
+ +
+ {{ "Login" | trans }} - {% if error %} -
    - {% for flashError in app.flashes('verify_email_error') %} -
  • {{ error.messageKey | trans(error.messageData, 'security') }}
  • - {% endfor %} -
- {% endif %} + {% if error %} - {% if app.user %} -

- {{ "You are logged in as" | trans }} {{ app.user.username }}. - -

- {% else %} - {# TODO: Login can be done with email, so the id's and stuff should reflect that, along with using the translation facilities #} -
- - -

{{ "Your nickname." | trans }}

-
-
- - -

{{ "Your account's password." | trans }}

-
+
    + {% for flashError in app.flashes('verify_email_error') %} +
  • {{ error.messageKey | trans(error.messageData, 'security') }}
  • + {% endfor %} +
- - - - + {% endif %} -
- -
- - {% endif %} -
- -
-
+ {% if app.user %} + +

+ {{ "You are logged in as" | trans }} {{ app.user.username }}. + +

+ + {% else %} + + {# TODO: Login can be done with email, so the id's and stuff should reflect that, along with using the translation facilities #} +
+ + +

{{ "Your nickname." | trans }}

+
+
+ + +

{{ "Your account's password." | trans }}

+
+ + + + + + +
+ +
+ + + {% endif %} + + + {% endblock body %} {% block javascripts %}{% endblock %} diff --git a/templates/security/register.html.twig b/templates/security/register.html.twig index d820971492..c81c9951cd 100644 --- a/templates/security/register.html.twig +++ b/templates/security/register.html.twig @@ -8,29 +8,31 @@ {% block title %}Register{% endblock %} {% block body %} -
-
-
- {{ form_start(registration_form) }} -
- -

{{ "Register a new account" | trans }}

-
-
    - {% for flashError in app.flashes('verify_email_error') %} - - {% endfor %} -
- {{ form_row(registration_form.nickname) }} - {{ form_row(registration_form.email) }} - {{ form_row(registration_form.password) }} - {{ form_row(registration_form.register) }} -
- {{ form_end(registration_form) }} -
-
+
-
+
+ {{ form_start(registration_form) }} +
+ {{ "Register" | trans }} + + + + {{ form_row(registration_form.nickname) }} + {{ form_row(registration_form.email) }} + {{ form_row(registration_form.password) }} + {{ form_row(registration_form.register) }} +
+ {{ form_end(registration_form) }} +
+ + {% endblock body %} {% block javascripts %}{% endblock %} diff --git a/templates/sidepanel/right/right.html.twig b/templates/sidepanel/right/right.html.twig index e564cf2b07..a050a01705 100644 --- a/templates/sidepanel/right/right.html.twig +++ b/templates/sidepanel/right/right.html.twig @@ -18,21 +18,23 @@
- {{ form_start(post_form) }} +
+ {{ form_start(post_form) }} - {{ form_row(post_form.to, {'attr': {'class': 'section-form-scope'}}) }} + {{ form_row(post_form.to, {'attr': {'class': 'section-form-scope'}}) }} - {{ form_row(post_form.visibility, {'attr': {'class': 'section-form-scope'}}) }} + {{ form_row(post_form.visibility, {'attr': {'class': 'section-form-scope'}}) }} - {{ form_row(post_form.content, {'attr': {'class': 'section-form-textarea'}}) }} + {{ form_row(post_form.content, {'attr': {'class': 'section-form-textarea'}}) }} - + - {{ form_row(post_form.post_note, {'attr': {'class': 'section-form-send'}}) }} + {{ form_row(post_form.post_note, {'attr': {'class': 'section-form-send'}}) }} - {{ form_end(post_form) }} + {{ form_end(post_form) }} +
{% endif %}