Jump to content

Mask page edit URL to custom profile edit page


gebeer
 Share

Recommended Posts

Hello,

I have a user page template with many fields that are organised in tabs. Tabs do not work on the profile edit screen. So I had to find a way how to let users edit their page with tabs in place.

The way I solved this is having users edit their user page in the backend instead of their profile page. So basically they are on a page edit screen and not on their profile edit screen which is a different process. The drawback of this method is that the users edit their profile on a URL like .../youradminurl/access/users/edit/?id=1377. So I needed to make sure that users cannot edit other users' profiles by just switching out the id. I did this through hooks that redirect them to their own profile.
This is far from a perfect solution. Ideally I would like to mask the page edit url to something like /myprofile but haven't found a way on how to do this, yet.

How would you go about this?

  1. redirect rules in .htaccess
  2. hooking into the profile edit process?

Either way I couldn't figure out how to accomplish it. Any pointers towards a solution would be very much appreciated.

Link to comment
Share on other sites

I haven't needed to do anything like this before, but I think it might be better to use a separate template for all these extra profile fields. When a user is added you use a hook to automatically create a profile page for the user. Or potentially vice-versa. The user page and the profile page would be connected via a Page Reference field.

When it comes to editing the profile pages you may want to let users change their password or email address. This could be done by providing a (modal?) link to ProcessProfile within the Page Edit interface (using Runtime Markup or similar) or you could add password and email address fields to the profile template and then update the equivalent fields in the user page in a saveReady hook.

Link to comment
Share on other sites

Thank you @Robin S for looking into this.

My question was: how can I make a user edit screen under a URL like  '/adminurl/access/users/edit/?id=1377' available under a URL like '/adminurl/myprofile/'. So that all user edit URLs with different user ids are routed to that 'myprofile' URL and the users that edit their user pages (which are their profiles in my case) never sees the actual user id and cannot try to mess with it.
Thus I chose the term 'mask' in the thread title. Maybe the way I explained it was confusing or not clear.

16 hours ago, Robin S said:

I haven't needed to do anything like this before, but I think it might be better to use a separate template for all these extra profile fields. When a user is added you use a hook to automatically create a profile page for the user. Or potentially vice-versa. The user page and the profile page would be connected via a Page Reference field.

I am not  using the default user template but my own user template. User pages live under their own parent (https://processwire.com/blog/posts/processwire-core-updates-2.5.14/#multiple-templates-or-parents-for-users)

Users can edit their pages via the page edit process. This is working fine. I just need to change (mask) the URL for that process.

The 2 ways that I can think of for approaching this:

  1. make the user edit process available under a custom process module which resolves to '/adminurl/myprofile/'
  2. have some htaccess rewrite magic in place

I'd prefer number 1, as I cannot easily adjust the htaccess rules so that they only kick in for the custom user type and not for all ''/adminurl/access/users/edit/?id=1377' type of URLs.

Hope this clears things up a bit ?

 

Link to comment
Share on other sites

I think you could just create a new page under /youradmin that has the admin template and the process "ProcessUser" assigned. Then you can hook into executeEdit to always set the userid to the currently logged in user:

$wire->addHookBefore('ProcessUser::executeEdit', function($event) {
  $this->wire->input->get->id = $this->wire->user->id;
});

I'm once more impressed by the flexibility of PW ? 

ldjhiVg.png

My user has id 41 of course, and not 123456789.

  • Like 1
Link to comment
Share on other sites

Great idea, thank you @bernhard

I tried your solution, added a new child page under Admin with name 'my-profile' and assigned the ProcessUser process.

When I go to that URL,

  1. I get a list of users. When I click on one of the users' name,
  2. I get to an URL like .../my-profile/edit/?id=1020 and am on the user edit screen.

I need to avoid the first step and go right to the second while still having only '.../my-profile' in the address bar, without the edit/?id=xxx.

But your hook is a great way of securing my current setup!

Another thing I tried some time ago:
In my custom user dashboard which is a process module, I have a method

	public function ___executeMyprofile() {
	 
	    $processUser = $this->modules->get('ProcessUser');
	    return $processUser->executeEdit();

	}

But this never worked because there are some wired in redirects in place, that always redirect to the .../access/users/edit/?id=xxx URL. At that time I even opened a thread on this topic which was never resolved.

Link to comment
Share on other sites

The easiest solution would be a redirect to the edit screen:

$wire->addHookBefore('ProcessUser::execute', function($event) {
  $this->wire->session->redirect('./edit');
});

You'd still have the /edit in your url, but is that a problem? At least you don't need any additional clicks...

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...