HWIOAuthBundle's PathUserResponse errors - symfony

Almost everything's working great in my project, except that when I log in (using facebook) with a user that has no correspondence in my database (FOSUserBundle), I get redirected to /registration/{id} only to get an error:
The form's view data is expected to be an instance of class Naroga\Reader\CommonBundle\Entity\User, but is an instance of class HWI\Bundle\OAuthBundle\OAuth\Response\PathUserResponse. You can avoid this error by setting the "data_class" option to null or by adding a view transformer that transforms an instance of class HWI\Bundle\OAuthBundle\OAuth\Response\PathUserResponse to an instance of Naroga\Reader\CommonBundle\Entity\User.
I also had to overwrite connect.confirm.html.twig to delete the following lines:
{% if userInformation.profilePicture is not empty %}
<img src="{{ userInformation.profilePicture }}" />
{% endif %}
It said PathUserResponse had no profilePicture method. My guess is I should not be using PathUserResponse, but I don't know what I did wrong. Can someone point me in the right direction?

The kind people of HWI/OAuth-Bundle have fixed the issue. I thought I was doing something wrong, but those were actually known bugs.

Related

FOSUserBundle: resetting password page finds user that does not exist

I am using FOSUserBundle with Symfony 3.4
I am trying to reset the user password and this works fine; only problem is that I can put ANY email and the status would be true saying that the email has been sent ??
How is it possible that FOS is finding a user that does not exist ? or did I miss something in my template ?
As far as I understand the status block is what should be displaying the error but it is always a success.
I have not overridden any of the default controller
{% extends 'UserBundle:Resetting:request.html.twig' %}
{% trans_default_domain 'FOSUserBundle' %}
{% block status %}
{{ 'resetting.check_email'|trans({'%tokenLifetime%': tokenLifetime})|nl2br }}
{% endblock %}
I think there is no problem and in addition it is a good behavior. Because otherwise, a person could easily devour a lot of users, which will cause a security problem. So if the user does not exist, not the pain to mention.
Again, if you look closely at this class (in fosuserbundle repository) via the link :
ResettingController, more precisely the method sendEmailAction, at the level of the 2nd control structure if
if (null !== $user && !$user->isPasswordRequestNonExpired($this->retryTtl))
you can notice that if the user does not exist then no mail is sent, the instructions inside the if are not executed and we go directly to a redirection instruction.
return new RedirectResponse($this->generateUrl('fos_user_resetting_check_email', array('username' => $username)));
That's why you see success all the time. Also this redirection above can be executed even in the case the user exists. That's how I tried to have an attempt to understand this process.

Twig how to get html between two tags to a service

I want some simple twig tags that allow me to do the following:
{% customtag 'name' %}
<div> some html </div>
{% endcustomtag %}
And then get that html inside of a service.
I have tried doing this myself but when I finally have al the data that I want inside of my NodeVisitor I can't seem to get it to my service. If I inject it and call a method on it it never gets executed. It only gets called if I try to clear my cache from my command line.
Can somebody please give some insight?
Apparently, you can access your extensions from Twig_Template.
So you can do:
$compiler->write('$this->extensions[')
->string('your_extension')
->write(']->getService()->someFunction();')
->raw(PHP_EOL);
in your twig node. And then in your extension you should just inject the service and return it in the getService method.

Symfony2 app.request.get('_route') is empty when throw new AccessDeniedException

I'm working on implementing a ROLE based admin application. I have a custom voter and at some point I'm doing something like:
if($role && VoterInterface::ACCESS_GRANTED !== $voteResult) {
throw new AccessDeniedException('Unauthorized access!');
}
and the result is that a custom error403.html.twig template is rendered.
So far so good.
The error403 template extends the main template in which at some point I'm building a menu using app.request.get('_route') for generating the links.
The problem is app.request.get('_route') is null.
xDebug-ing the issue I've noticed that somehow the $request->attributes->parameters array does not contain _route or _route_params keys.
Any thoughts?
The problem is Symfony uses sub-request for rendering error pages. It doesn't need a router and you have not exatly the same request object as in master request.
Github issue
https://github.com/symfony/symfony/issues/5804
Same question on SO
app.request.attributes.get('_route') is empty when I override 404 error page
Some theory
https://knpuniversity.com/screencast/symfony-journey/sub-request-internals
You can write your own exception listener and modify this behaviour in some way.

Django messages framework usage

About the messaging framework, in the docs it is written that every message has a message.tag property that can be uses for css. so my code looks like this
try:
models.save()
message.success(request, "Model successfully saved")
except DatabaseManagementTransaction:
message.error(request, "Model could not be saved")
in my html template
{% if messages %}
{% for message in messages %}
<div class="alert alert-{{message.tag}} alert-dissmissable">
{{message}}
</div>
{%endfor%}
{% endif %}
But when the template is rendered i see no message.tag and the div class looks like this
<div class="alert alert- alert-dissmissable">...</div>
So do i have to create MESSAGE_TAGS in settings file for this to work? Why is the message.tag empty? And another question. What happens to messages after they are presented to user? Are they deleted? If i add a new model will the previous messages be shown to me plus the newly appended one?
If should be tags as alert-{{message.tags}} in the template.
What happens to messages after they are presented to user? Are they deleted?
Yes, they are cleared once iterated (or displayed through template) from the storage. Refer message expiry.
If i add a new model will the previous messages be shown to me plus the newly appended one?
The messages list will have all currently active messages. So if previous message is still there it will be shown as well.

render raw HTML in a Symfony controller

I'd like to render a template to a string in a symfony controller and avoid escaping it.
I don't want to disble twig escaping globally.
Kind of applying the |raw filter in the template itself, but from the controller.
I imagine something like
$rendered_unescaped = $this->container->get('templating')
->render($templatehere, $paramshere,
array('autoescape'=>false));
By the way, I have wishfully tried the previous with no luck indeed.
This need apears when I want to add an html chunk to an ajax json response and realize that I am getting htmlentities all around.
Thanks,
javier
You could use the autoescape tag
{
"foo": {
"html": "{% autoescape false %}<p>Yo, <span>{{ name }}</span>, I'm real happy for you, and Imma let you finish...</p>{% endautoescape %}"
}
}
Also, I haven't tested this, but you could change the default strategy of the Twig templating.
$this->container->get('templating')->getExtension('escaper')->setDefaultStrategy(false);

Resources