Jump to content

Individual User Logins


nickmccomb
 Share

Recommended Posts

Hey guys,

I'm new to PW.  I'm trying to make a website where my clients can signup/login and set up their profile.

Also, their customers have to be able to signup/login and view their profile.

Basically, i have clients that will login and set up their own information in the website.

Details included will be something like

  • company name
  • address
  • contact info 
  • product image
  • product description
  • price

Once my clients log in and input this information their customers can go to the client's web page and view the information and purchase items.

So i basically need to know how to set up the users so that:

  • clients can sign up and input their information which will output to a web page
  • customers can log in and see the clients information where they can purchase items

is there a module that caters for this already?  Does the PW database cater for this?  

Any information on how to do this would be greatly appreciated!

Regards,

Nick.

Link to comment
Share on other sites

Hi there, Nick, and welcome to the forum!
 
PW can handle this, but this isn't something any single module alone will do for you. It'll require custom code work, the amount of which depends a lot on how many users you'll have, whether you're prepared to create user accounts and connect them to editable pages manually or if you need to automate registration, how customised you want edit views for these clients to be etc.

Below I'll try to describe three possible approaches you might use to make this work:
 
1. Keep client's user profiles (i.e. user accounts, which in ProcessWire are also pages) and publicly viewable product/info pages separated. Each user would have an account to your site but also separate, publicly viewable page he/she can edit. For this approach, I'd start with Page Edit Per User module, which allows you to define pages that specific user (one with no access to edit any pages by default) can edit:

/clients/                  # public part of your page
    /client-x/             
    /client-y/
    /client-z/             # page for client z: publicly viewable info, products etc.;
                           # after logging in, client z can edit this page

/processwire/              # ProcessWire admin area
    /access/
        /users/ 
            /client-x/         
            /client-y/
            /client-z/     # user account for client z: not publicly viewable; after
                           # logging in, this client can edit page /clients/client-x/

 
2. Add product information etc. custom fields directly to user's profile pages and then render those publicly. The problem with this approach is that all your users, including superusers, will have these custom fields, which might not make sense in your case (if you need other type of users later, it's going to be very confusing).
 
Also, you'll still need public URLs for the profiles -- not much of a problem though, as you can always create a template that fetches user (like Pete descried in the thread linked to above), either based on a GET param or URL segment. If you go with this, be very strict with validation, i.e. before rendering user page make sure it's one that should be rendered, i.e. one of your clients and not, say, superuser account.
 
3. If you're confident in your skills with code, you could also create a Process module (a new view/tool for Admin area) that your clients use to handle their products. This would, essentially, be a custom-built CRUD tool for managing user-specific pages. This thread provides some useful pointers for this. Using this approach it would actually make sense to include basic info as custom fields on user profiles as explained above and creating separate pages only for products these clients sell (assuming that there's more than one product per each client).

Hope I didn't confuse you too much with this -- please don't hesitate to post any questions this raises and/or you still have. Would be happy to clarify. I'd strongly suggest that you start building this thing and then ask once you face any specific issues.. the more you can limit the scope of your question, more likely you are to get a swift and precise answer :)

  • Like 11
Link to comment
Share on other sites

Hi teppo,

I was thinking more along the lines of adding a new column to the user database table that distinguishes what type of user they are, e.g if they are a client or a customer.  

This field in the database table will get set depending on whether they sign up from the client form or the customer form.  Once they sign in, if they are a client they get taken to a page which populates all their details from a table i have created for clients, if they are a customer they get taken to a different page which populates all their details from a customer table.

I'm thinking i need to create two types of users (Client and Customer) in ProcessWire and only give them rights to see the page they are meant to see.  Although, i'm not sure if there's an easy way to set up this scenario in ProcessWire or if i have to do it with a fair bit of PHP and mySQL code instead.  

I'm fine with doing the code, i just thought there would be a module or an easier way to do this in ProcessWire.

Thanks for the info :)

Nick.

Link to comment
Share on other sites

I'm thinking i need to create two types of users (Client and Customer) in ProcessWire and only give them rights to see the page they are meant to see.  Although, i'm not sure if there's an easy way to set up this scenario in ProcessWire or if i have to do it with a fair bit of PHP and mySQL code instead.  

There are many different ways to do many things in ProcessWire.

You could have to 2 roles (Client and Customer) and do the things you listed with no problem.  As I said, there are many other ways to do the exact same thing in ProcessWire.  If you do a Google search of the forum, I believe you will find a lot of technical information that will help you achieve what you desire.

  • Like 1
Link to comment
Share on other sites

Hey guys,

Yeah it looks like it will require just two different roles, which i've figured out how to do.

What do you guys do to communicate with the database?  

For example if you wanted to add a new column to a table, or a new table to the database, would you do that in phpMyAdmin, or is there a module to do this in ProcessWire?

Also, what's the best way to create a user login / sign up form?  Any modules out, or templates that we can import? 

Sorry for all the questions, i'm still a noob with ProcessWire.  I have come from hand-coding PHP... It's a big change conceptually for me!  One day, when i've figured it all out, i'll give back and answer noob questions! :)

Cheers!

Nick.

Link to comment
Share on other sites

@Nick: I'd like to point out that the approach you're taking is not what I'd advice on doing. It's very important to understand that ProcessWire is, first and foremost, a CMF. What this means is that it's very good at dealing with various content items (which it calls "pages"), describing the schema of those items, allowing you to manage them via API calls, define relations between them etc.

Without going into too much detail about this, I'll just say that by using ProcessWire's own tools you are not just getting more benefit out of the system, but also more likely to build a solution that's manageable in the long run, easy to extend and update via built-in tools.. and, perhaps most importantly, as safe as possible (as long as you prefer API calls over SQL there's literally no way for SQL injection issues to creep into your code).

What you are doing here sounds essentially like taking ProcessWire as a starting point but then coding an application that does effectively the same thing over and around it. This approach fits better one of the more bare-bones application frameworks (Zend Framework, Laravel etc.) It may seem like the obvious choice before you get to know ProcessWire's capacity and set of features (and there are valid use cases for it even then), but I hope you see why I don't think it's the best option in this case :)

Anyway, since ultimately you should do what you see as the best option here:

With ProcessWire you don't typically add columns to database tables or new tables to the database, so there's no UI for this (apart from PHPMyAdmin, of course, if you prefer something like that). You can communicate with the database using API variable $database, which is just a fancy way to use PDO style queries directly from your own code. You can see some examples of that in the source of my Version Control module.

It's a bit old topic (there's probably newer material available too if you try searching the forum), but here's some discussion about custom login forms. Personally I tend to avoid custom login forms and rather allow users to login via native login page. This is connected to the fact that I don't like creating new custom Admin tools for them either and would much rather either let them use built-in tools or create a new Process module for them to use (method no. 3 in my earlier post).

Hope this helps a bit.

  • Like 4
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...