gebeer

Mask page edit URL to custom profile edit page

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.

Share this post


Link to post
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.

Share this post


Link to post
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 🙄

 

Share this post


Link to post
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

Share this post


Link to post
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.

Share this post


Link to post
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...

Share this post


Link to post
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

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By Thomas Diroll
      Hi guys I'm relatively new to PW and just finished developing a page for a client. I was able to include all necessary functionality using the core fieldtypes but now I it seems that I need to extend them with a custom one. What I need is a simple button, that copies the absolute url (frontend not PW-backend) of the page which is currently edited to the clipboard. As this feature is only needed inside a specific template, I tend to use a custom fieldtype which provides this feature. I've been looking inside the core modules code (eg. FieldtypeCheckbox.module) but I don't really get the structure of it and how its rendered to the admin page. I also didn't find a lot of tutorials covering custom fieldtypes.
      Maybe some of you could give me some tips on how to write a basic custom fieldtype that renders a button which copies the value of
      page->httpUrl() to the clipboard using JS. Thanks!
    • By matsn0w
      Hey all,
      I am working on a website and I want to style the login page, but I'm a bit confused. 
      I want either the existing login page styled in my own way using some CSS (I guess I prefer that) or I want to create a custom page with a form to login. (Which I could style too).
      I used the code from Ryan and Renobird posted here - which works great - but that doesn't replace the original login page. 
      Is there a way to some sort of 'disable' the original login?
      I hope my question is clear and thanks in advance,
      matsn0w
    • By theoretic
      Hi there! And thanks for Processwire!
      Maybe i'm not very attentive but couldn't find any tutorial on creating custom fieldtype with custom inputfield. Would like to make one for selecting color(s) from predefined list of colors. The closest existing match is FieldtypeSelectOptions with InputfieldSelect but i need something different. There's a very good post from @Soma   which is, however, insufficient to begin building my own fieldtype or at least to attach the existing inputfield to an existing field.
      Will appreciate any help. Thanks in advance!
    • By rareyush
      I am trying too create a custom field where when user select to create a category 2 text area shows where one title of the category goes & another for some content.
      Like in a picture I want 2 text areas when I click on create new

    • By Claus
      How do I go about adding custom markup to my Body-fields? I want to add some spans, but they are all removed if I add them in the ‘Source’ window.  I can see that the Body-field is edited by CDEditor, but how do I add a custom ‘mystyles.js’ to it? (If that indeed is what I need to do). The guides I have have found on this seem outdated.