Jump to content

User login and redirect


Peter Knight
 Share

Recommended Posts

I've been using PW for about 2 or 3 years but have never really done anything with users (until now) apart from setting up users and roles for the background.

I now have a project that requires following and am looking for some high level advice and an audit of my thinking.

  • Client needs to set up users in the Admin and associate a private page with each user.
  • Each user will have a different private page which we'll create.
  • Users need to login via a form and be automatically directed to a private page
  • Each user will only access a single private page BUT a private page may be associated with serveral users

Requirements (for Client)

A: Client needs to setup a user(s) in the admin.
- No problems there and I'll just use the Access pages etc and create usergroups, roles and users.

B: Client needs to associate a private page with a user
- I'm thinking a user is just a page so I can add a field to a user admin template and let Client select the private page

Requirements (for front end user)

C: User needs to login via a web form
- I'm pretty sure I can do this via the API and some sample code around the forums

D: User should them be automatically redirected to a private page client setup in step A. Note: Each user has a different (and only 1) private page
- I'm thinking that my login code has a reference to a variable ($privateURL) and once they're logged in, they get directed to that

My biggest unknown is what might be best....

Should I create a PageSelect field within each private page which allows client to cherry pick which users can access this page

OR

Should I add a field called PrivateURL to the user templates and associate pages to users that way?

Thanks for any advice.

Link to comment
Share on other sites

Hi, from technical point I don't see much of a problem for both solutions, however the UserSelect within the pages might need some additional logic to make sure, a user is not selected in multiple pages.

I think this question should rather go to the Client to confirm which way they intent to work. (Do they rather want to manage the users per page or do they want to manage page per user?)

In extend, with some hooks and some magic it should also be not too hard to implement a combination of both, make it possible to manage it in both, the pages and the user.

Link to comment
Share on other sites

My biggest unknown is what might be best....

Should I create a PageSelect field within each private page which allows client to cherry pick which users can access this page

OR

Should I add a field called PrivateURL to the user templates and associate pages to users that way?

You even have the option to store this relationship explicitly by using separate pages with pagefields for both user and private page :D

But in the end: Try to look for what's most natural in the workflow. Your clients will most likely create the user before the private page, which would conclude that the page field should rather be stored on the private page as the user is already created by then. 

  • Like 1
Link to comment
Share on other sites

our clients will most likely create the user before the private page, which would conclude that the page field should rather be stored on the private page as the user is already created by then. 

Yep - that's what I was leaning towards. And I think I'd prefer the client to work mainly with private pages as opposed to editing fields etc in the User template.

You even have the option to store this relationship explicitly by using separate pages with pagefields for both user and private page :D

So true. So much flexibility !

Link to comment
Share on other sites

I'm currently working on an app with something similar, but with potential for a user to have multiple profiles (only one active at a given time). This is how I do it:

  1. A user "profile" page is automatically created when users are created.
  2. The built-in "created user" field of the profile page is set to the User page - this creates the link. (Needs to have "Allow the 'created user' to be changed on pages?" at template level)
  3. A single-choice Page field called "profile" is added to the User template which points to the "current" profile.

All of the above things can be done with appropriate hooks.

The profile Page field has this custom PHP code for selectable pages:

return $pages->find("template=profile, created_users_id={$page->id}");

This allows code like this:

echo "You are registered with {$user->profile->organisation}";
  • Like 1
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...