Translate FOSOAuthServerBundle errors - symfony

Is there any way to translate FOSOAuthServerBundle error messages, such as "Invalid username and password combination"?
I've tried to create messages.de.yml file under app/Resources/translations directory and put this lines:
Invalid username and password combination: "Falsche E-Mail / Passwort Kombination"
and set locale: de in app/config/parameters.yml, but nothing changes.

I think the message you are tring to translate is hard coded ( see this ) You need to override this methods to add translations

Related

How to delete wordpress user using json API

I am using josn api plugin for deleting users. This is my URL: "https://example.com/?json=users/delete_user&nonce=3c3baa1b11&id=9", but I am getting error: {"status":"error","error":"You must either provide the 'u' and 'p' parameters or log in as an administrator."}. I had also tried wp-json/wp/v2/users/ but only showing admin user(id=1) data with this URL. Any suggestion?
As mentioned in the error that you would have to provide the 'u' and 'p' parameters so that means you would need to send the admin username and password along the URL. So, the full URL should be -
https://example.com/?json=users/delete_user&nonce=3c3baa1b11&id=9&u=admin_username&p=admin_password
Replace admin_username and admin_password with the actual username and password of the admin.

Symfony 5.3 Mailer setup env vars not reading correctly

In a Symfony 5.3 project I am using the Mailer (..\Symfony\Component\Mailer\MailerInterface) to send mails.
For devolopment I required "symfony/google-mailer" with composer and set it up in .env.local.
Say username is "example#gmail.com" and password is "0000".
In .env.local I specified
MAILER_USER='example#gmail.com'
MAILER_PASSWORD='0000'
MAILER_DSN=gmail://MAILER_USER:MAILER_PASSWORD#default
which results in error
Failed to authenticate on SMTP server with username "MAILER_USER" using the following authenticators: "LOGIN", "PLAIN", "XOAUTH2". Authenticator "LOGIN" returned "Symfony\Component\Mailer\Exception\TransportException: Expected response code "235" but got code "535", with message "535-5.7.8 Username and Password not accepted.
As stated in the docs I changed the one special character in user name ("#") to it's URL-encoded form like
MAILER_USER='example%40gmail.com'
which then results in the error
Email "example%40gmail.com" does not comply with addr-spec of RFC 2822.
(Obviously the URL-encoding didn't work like expected (because it wasn't reversed?))
I tried to load the env vars in paramaters in services.yaml and use the parameters instead - but that lead to the first error too.
If I write the auth infos into the MAILER_DSN env var directly it just works fine without problems, like
MAILER_DSN=gmail://example#gmail.com:0000#default
So this seems to be a syntax problem which I can't figure out from the docs.
Any hints?
You should remove the single quotes and you need to wrap the env variables used in other env variables with ${} sic
MAILER_USER=example#gmail.com
MAILER_PASSWORD=0000
MAILER_DSN=gmail://${MAILER_USER}:${MAILER_PASSWORD}#default
Result:
$_SERVER['MAILER_DSN'] = "gmail://example#gmail.com:0000#default"
.env :
MAILER_DSN=smtp://username:password#smtp.gmail.com
You have to enable access to applications in google parameters (security).

FOSUserBundle missing parameter token for password reset issue

I have a Symfony 3 CRM, but there seems to be an issue with the password resetting (for which I am using FOS User Bundle). A user can enter their email, they get the email with a link, but when they reach the page to change their password, the following error is logged:
An exception has been thrown during the rendering of a template ("Some
mandatory parameters are missing ("token") to generate a URL for route
"fos_user_resetting_reset".") in FOSUserBundle::layout.html.twig at
line 54.
So, I checked the route in the FOSUserBundle config (bearing in mind, I have not altered this file or anything within the friendsofsymfony directory):
<route id="fos_user_resetting_reset" path="/reset/{token}" methods="GET POST">
<default key="_controller">FOSUserBundle:Resetting:reset</default>
</route>
And the URL being visited:
https://crm.mysite.co.uk/resetting/reset/sAt7xPNzW4AempvzK6m2xRRN7jI058xAQjbct7GgyqI
which as you can see clearly passes a token. I've had strange issues like this before, if for example I don't pass a default value in my route (even if there's clearly a token or some other required parameter passed) but since this is a separate bundle and is in XML rather than YML I don't know how to fix this. I'm not entirely sure why it's even throwing an error?
Any help with this appreciated.
try to view inside your console the route inside your app by doing:
bin/console debug:route
In this list you can get all available url
A possibility is that you need to call only:
https://crm.mysite.co.uk/reset/sAt7xPNzW4AempvzK6m2xRRN7jI058xAQjbct7GgyqI

How to translate SecurityContext:AUTHENTICATION_ERROR?

I'm using FosUserBundle with Symfony2.1 and when I try to connect a user that is not enabled, the following error is displayed on my form : User account is disabled, which is great but it is a French website and I would like to translate this message in french.
I've already translated session messages and validators in translations folder : messages.fr.yml and validators.fr.yml and MyUserBundle.fr.yml but I can't get the ones created by the SecurityContext.
All messages from FOSUserBundle are using "FOSUserBundle" as the message domain. So you have to put your translation into ./app/Resources/translations/FOSUserBundle.fr.yml.
If you've derived your own bundle based on FOSUserBundle the file goes into ./src/YourUserBundle/Resources/translations/FOSUserBundle.fr.yml.

symfony2 get login username while encoding password

Hi i am gooling but without result.
I am trying to check one field in DB while encoding password to user. How?
The service
services:
my_password_encoder:
class: TB\WelcomePageBundle\Security\Encoder\MyPasswordEncoder
<?php
namespace TB\WelcomePageBundle\Security\Encoder;
use Symfony\Component\Security\Core\Encoder\BasePasswordEncoder;
use TB\UserBundle\Entity\User;
class MyPasswordEncoder extends BasePasswordEncoder
{
public function encodePassword($raw, $salt)
{
$user = new User;
$old_or_new=$user->getOldNew();
print_r($user);
print_r($old_or_new);die();
The point:
1. withdrawn one field from DB from current logging user.
2. Depend on the value i need: encode his password MY WAY and log in + CHANGE THE PASSWORD THE SYMFONY WAY and update DB.
3. Depend on the value just use the symfony way.
There is easy condition. The problem is just how i can withdrawn this field + encode password symfony way. (how encode password my way i know). + encode the password not more via my way but symfony and update DB.
My points is to migrate low secure passwords to symfony2. Why? Because i have existing DB where the passwords are encoded my way. So i need to "update" them.
THE MAIN PART OF QUESTION:
HOW CAN I GET THE USERNAME OF USER WHO TRY LOG IN IN ENCODE PASSWORD FUNCTION??? THX!!!

Resources