Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

User photo controller actions incompatible with front-end forms #3932

Closed
samhernandez opened this issue Feb 28, 2019 · 8 comments
Closed

User photo controller actions incompatible with front-end forms #3932

samhernandez opened this issue Feb 28, 2019 · 8 comments
Assignees
Labels
bug severity:minor Cosmetic issues or bugs with simple workarounds

Comments

@samhernandez
Copy link
Contributor

samhernandez commented Feb 28, 2019

Description

Regarding these controller actions:

  • users/upload-user-photo
  • users/delete-user-photo

You can hit them from front-end (non-CP) forms, but they both fail trying to render CP templates.

See:

This isn't critical because it's possible to save and delete photos with the whole user via the users/save-user controller action.

Additional info

  • Craft version: 3.1.15
@brandonkelly brandonkelly added bug severity:minor Cosmetic issues or bugs with simple workarounds labels Mar 4, 2019
@brandonkelly
Copy link
Member

@andris-sevcenko I’ve added calls to $this->requireCpRequest() for the time being just so it’s clear that the methods are only intended to serve the Control Panel. If you can get those actions to be front-end-friendly, then feel free to remove those lines.

@wouter-vs
Copy link

We use these actions in a front-end form. Now it doesn't work anymore because $this->requireCpRequest() was added.
There are workarounds using other actions but I fail to see what the reason was for adding this call? They seem "front-end-friendly" to me.

@samhernandez
Copy link
Contributor Author

I imagine a front-end-friendly controller would return success or failure in json format. As these controller actions stand at the moment, they throw errors when trying to render a CP template. The image saves before that so it functions, but it's dirty.

@brandonkelly
Copy link
Member

@Moskydesign I suppose for this line, you just created your own front-end users/_photo template?

$html = $this->getView()->renderTemplate('users/_photo', [

@wouter-vs
Copy link

Yes, we do an ajax call and display the returned html after success.

If it would only return success or failure we would have to build the render function our selfs, not that this wouldn't be possible but there happens to be an action specifically for uploading the photo, my understanding was that it was created for this use case.
Other use cases can just use the global 'save' action that doesn't render a template.

@brandonkelly
Copy link
Member

@Moskydesign have you customized your copy of the users/_photo template at all, or is it just a direct copy of the built-in one? Thinking one option is we could just force the controller to render the built-in users/_photo template, and remove the requireCpRequest() call.

@wouter-vs
Copy link

We have modified it a bit.

Apart from the html we also had to change:
{% set volumeUid = craft.app.projectConfig.get('users.photoVolumeUid') %}
to
{% set volumeUid = craft.app.getSystemSettings.getSetting('users', 'photoVolumeUid') %}

It might not be very front-end friendly but it does provide a lot of flexibility on what you want to display.

brandonkelly added a commit that referenced this issue May 14, 2019
@brandonkelly
Copy link
Member

Alright, the users/upload-user-photo and users/delete-user-photo actions will once again be accessible from the front end as of the next release. The actions now check if the users/_photo template exists, and if not, defaults to the built-in one.

(By the way, craft.app.getSystemSettings.getSetting() is just a deprecated wrapper for craft.app.projectConfig.get() so I’m guessing you didn’t change that part, but just wrote your template before Craft 3.1 was released. You should update it to use projectConfig.get().)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug severity:minor Cosmetic issues or bugs with simple workarounds
Projects
None yet
Development

No branches or pull requests

4 participants