Jump to content

Custom User Registration?


Lars282
 Share

Recommended Posts

Hey!

I am not sure, probably this has been discussed somewhere already, but I could not find anything.

I have a website where users once registered and logged in should be able to view and post content (in the form of a PW page with a certain template, like adding a page in the admin). I have two questions concerning this.

Firstly, how can I add a page using a form on a website to add pages to the page tree?

Secondly, I am not sure whether I can use the PW users for this. I need visitors to be able to register themselves, maybe with approval needed from an admin before they can login (already found how to have a custom login page). I might need to store more information than possible in the current user page, i.e. more than the name/pw/email - would that work? If so, how?

Many thanks,

Lars

Link to comment
Share on other sites

Hello there!

I'd consider adding a role with very few privileges (basically only page view access), name it "unapproved" or something like that. The register form could create new users via the API and assign that non-privileged role to them. After that an admin could check their info and assign whatever role they actually need.

You can find many posts about creating forms from the forum and creating new users is instructed in the API documentation: http://processwire.c...variables/user/.

Also, here's some discussion about adding extra information for users: http://processwire.c...extending +user. You could also edit the user template like @Soma suggested above -- not really sure which is the "correct way" here.. :)

  • Like 1
Link to comment
Share on other sites

Thanks!

Didn't even notice the template filter until now!

Ok - I will have a look and decide which method to use, but seems both straight forward.

Is there a brief example on how to use $page->save()? Does it work similar as for user, just using $page?

<?php
$u = new User();
$u->name = "gonzo";
$u->pass = "BamBam!";
$u->addRole("guest");
$u->save();

Thanks,

Lars

Link to comment
Share on other sites

Hello there!

I'd consider adding a role with very few privileges (basically only page view access), name it "unapproved" or something like that. The register form could create new users via the API and assign that non-privileged role to them. After that an admin could check their info and assign whatever role they actually need.

The prefered, simpler way is to make the user when created via API unpublished:

$user->addStatus(Page::statusUnpublished);

See cheatsheet addStatus

Then the user can't login yet. And the admin can just go and publish the user (same as with pages) in the admin.

Users are pages so the page API applies here same way as it is for pages.

Or using API to publish

$user->removeStatus(Page::statusUnpublished);

See cheatsheet removeStatus

The different system flags are also on the cheatsheet. :)

  • Like 6
Link to comment
Share on other sites

If the content you want to add consists of fields that would be applicable all users, then it's preferable to add them directly to the user template. But if it's content that is only going to be applicable to some users, then may be better to make them child pages.

  • Like 2
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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...