Sending a User to Edit their own Page on Manager Login

Using a plugin to let users *edit* their own page on login


In the last article, we saw how to forward a use to their own page in the front end after they successfully log in. In this one, we'll look at how to send the user to *Edit* their own page after successfully logging in to the MODX Manager.


MODX logo


It Takes a Plugin

At the end of the last article, we discussed a very insecure method to forward the user to the Create/Edit Resource panel for their own page. We also mentioned an impractical method involving modifying the Manager's Login template. In this article, we'll see a fairly simple method that will do it when the user logs in to the Manager.

The secret is the OnManagerLogin event, which fires after the user has successfully logged in to the Manager.

Create the user_page User Setting as described in the previous article. Set the user's page as the value of the setting.

Then create a plugin called ForwardUser with this code:

<?php
$pageId = $modx->getOption('user_page', null, '', true);
if (! empty($pageId)) {
    $url = MODX_MANAGER_URL . '?a=resource/update&id=' . $pageId;
    $modx->sendRedirect($url);
}
return '';

Now any user who has the setting set will be directed to the Create/Edit Resource panel for their resource. If there's no setting, the plugin does nothing and the user will end up at that Manager Dashboard as usual.

If you want to direct all users to edit the same page, just set the $pageId variable to the page's resource ID.


Possible Improvement

You could create the user's page, and the User Setting (and its value) with a postHook on the Register snippet.


Coming Up

In the next article, we'll look at preserving formatting when pasting text in PhpStorm.



Looking for high-quality, MODX-friendly hosting? As of May 2016, Bob's Guides is hosted at A2 hosting. (More information in the box below.)



Comments (0)


Please login to comment.

  (Login)