Jump to content
Larry Ullman's Book Forums

Managing 2 Different Users


Jonathon
 Share

Recommended Posts

Hi Larry,

 

I have 2 different users as in they have there own login pages/authentication and DB tables. How do I specify a certain action relates to 1 particular user type and therefore when i'm not logged in and I try to access it, it redirects me to their login page rather than the default login page?

 

For instance:

 

item/create may be for "lister" user, except if directs me to my default login (which isn't for "listers").

 

Thanks

 

Jonathon 

Link to comment
Share on other sites

Hi Larry / Antonio

 

There are 2 user groups. 

 

An example would be a "list item" link on a home page. It's visible to all users logged in or not. However if your not logged in and click the link it takes me to my default login page. Which is for "buyer" users. What I need is for it to take them to the "lister" login.

 

Hope that makes sense.

 

Jonathon

Link to comment
Share on other sites

I'm not really sure what you are asking here. You want the link to change depending on the user group? If so, render different views according to the groups, or add logic directly into the view itself.

 

This is how I did rendering of navigation in CodeIgniter:

// Core controller class

protected function render_navigation() {
   if ( $user->isAdmin() ) {
      $this->load->view('nav/admin', $data); // Admin
   }
   else if ( $user->isUser() ) {
      $this->load->view('nav/user', $data); // User
   }
   else {
      $this->load->view('nav/guest', $data); // Guest
   }
}

Another example would be to pass the whole user object to the view and add some logical statements there.

 

This should be pretty transferable to YII. I placed the method in my core controller, and render the navigation by calling it.

  • Upvote 1
Link to comment
Share on other sites

Hi Thomas,

 

Not really, I will have links on several pages that will require a particular type of user to access them. Think of it like this. If eBay had separate logins depending on if you were a buyer or seller and sellers could only list items and buyers could only buy things. Then certain controller actions would only be relevant to certain user types.

 

For instance item/create could be a controller/action for only the listers as they create the listings.

 

So on ebay.com. If you click "sell item" at the top and you're not logged in it takes you to login page. 

 

In my situation it takes me to the default login page. Which in my case was a buyers login.

 

What I need to do is get yii to recognise that the controller/action item/create would be relevant to the "lister" users and instead when a non-logged in person clicks "sell item" it takes them to the lister login.

Link to comment
Share on other sites

Are you storing admin and regular members in the same user table? Is admin the only seller, I mean is this a shopping cart website built to sell an individual product? This should be very easy to solve with yii.

 

One last thing, if you have users and admin in two separate tables how can you stop convergences and separate their id's. I thought it would be better keeping things simple and using one table for users, then Thomas's solution would be ideal.

 

I will work out this for my own site in the next few days so if there isn't a solution here already I'll give you a hand.

  • Upvote 1
Link to comment
Share on other sites

Long time, no see Edward. Things good?

 

I'm not really understanding what you are trying to do here, Jonathon. Do you have any logical way of dividing your groups? If not, develop methods in your model(s) related to the groups. Use that logic to do one of the following:

 

a. ) Add a filter to your routing. Allow group x, redirect group y.

b. )Add logic to your controllers. Allow group x, redirect group y.

c. ) Add logic to your views. Post to loginModel 1 for group x, loginModel 2 for group y.

 

No matter what you do, you need the kind of logic I'm talking about here. We have to little data to help you creating it if that's your problem, but I know it should work... Theoretically... If I've not misunderstood.

 

Regarding to redirect to correct login on specific actions, add logic for that to.

public method getUserLoginUrl()
{
   if ( userIsMemberOfGroupX )
   {
      return self::URL_TO_GROUP_X_LOGIN;
   }

   return self::URL TO_GROUP_Y_LOGIN;
}

Hope that helps a little bit at least. Get back to us man.

  • Upvote 1
Link to comment
Share on other sites

I am good Antonio taken a while off to watch Wimbledon and let all the new coding knowledge i have learned sink in. I'll be starting back once Wimbledon is done. But my project is probably going to take the same time it took my brother to finish his PHD. I am hoping to get it online by 2015. Also ZenDesk is quite a good ticking system to add to your website.

 

Okay back to the thread. Sorry

  • Upvote 1
Link to comment
Share on other sites

 Share

×
×
  • Create New...