Jump to content
cjx2240

Populating a site with user pages

Recommended Posts

I'm capturing the main content for a site using a registration/profile process. The end product will be a categorised showcase of their submissions. They're selecting the page that would be the parent category as part of the profile process.

The easiest way to do this would probably be to copy the user pages to be "normal" pages when sign-up is closed. But I would like to avoid this as it would fracture the content if we needed to reopen registrations. So instead I would like to try leaving the users alone, and looping them simply by grabbing all users with the current page as their selected parent.

It won't be as simple as browsing to /users/user-name, I need to put them in categories based on regular pages like /category/child-category/user-name

I think this is easy enough, I know how to select the users and loop through them, load a template based on their page (I think) - but can you think of any reasons why I should or shouldn't do this, any complications I'm not considering? I'm going to try and store a nice unique name for them from their real name, when they sign up that can serve as the URL. Is there anything useful in the API that can make sure a name is unique and add a number if it's not?

I know this is a bit vague, but anyone done anything like this before?

 

Share this post


Link to post
Share on other sites

Two things came into my mind, if I get it right what you are after. (not totally sure):

You may create a "custom user page" as regular page after each successful registration. You only need one extra field in native user pages that stores the page id of the bundled custom user page. This way you can use the built in users and roles system for all login and access related and have all other stuff in a regular page with templates & fields of your choice including all regular api related stuff.
(For accessing pages that should not be public, you also may hook into viewable etc. and check if the $user->isLoggedin() and if the $user->custom_field_id matches the id of the custom-user-page that is tried to be accessed.)

-------

Regarding unique URLs I used a lot something like the following:

$loginToken = bin2hex(random_bytes(30)) . md5(time());  // store this once into a dedicated field of the custom user page on registration

https://www.php.net/manual/en/function.random-bytes.php

I think the random_bytes already should be enough, adding a timestamp may be a bit superstitious or overanxious. 🙂

  • Like 4

Share this post


Link to post
Share on other sites

That’s such an incredibly good idea I’m mad I didn’t think of it myself. Thank you! And well done understanding my requirements so well!

Share this post


Link to post
Share on other sites

Can anyone tell why I can't seem to save this page from ready.php?

The $user->course->id  returns the correct ID, and $user->course is a page, but as soon as I set $userPortfolioPage->parent it's null

<?php

$this->addHookBefore('LoginRegisterProProfile::saveReady', function(HookEvent $event) {

    $users = $event->object;
    $user = $event->arguments(0);

	if($user->course) {
      
        $userPortfolioPage = wire('pages')->get("template=portfolio-detail,user_id={$user->id}");

        if (!$userPortfolioPage) {
            $userPortfolioPage = $this->wire(new Page());
        }

        $userPortfolioPage->template = 'portfolio-detail';
        $userPortfolioPage->parent = wire('pages')->get($user->course->id); // why isnt this working??
        $userPortfolioPage->user_id = $user->id;

        $userPortfolioPage->title = "foo bar";
        $userPortfolioPage->name = wire('sanitizer')->pageName("foo bar");

        $userPortfolioPage->save(['adjustName'=>true]);

    }


    // save the user field too
    $user->not_first_load = 1;
    $event->arguments(0, $user);

});


?>

 

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.

×
×
  • Create New...