News:

Wondering if this will always be free?  See why free is better.

Main Menu

Dual Login Cookies

Started by crackatown, May 01, 2011, 04:17:21 AM

Previous topic - Next topic

Arantor

If you've already included SSI.php, all manner of things is trivially possible.

$context['user']['name'] should contain their username. As for access level, you can check group access or individual permissions. Depends what you want to do, really, and exactly how you want things set up, but either is trivially possible.

texasman1979

What you can do is mod the login function with a function of your own, the db connection will be active as long as ssi.php is included, the uname is a var in that function, shouldnt be too hard to pinpoint.
SMF 2.0.4
SimplePortal 2.3.5

LOGIC is a FOUR letter word! :)


Arantor

Why the hell are you insisting on making everything so much more complicated than it actually needs to be? You don't even need to change the login function one bit.

texasman1979

Global $user_info after the login, use $user_info['id] to reference the specific users data in the users table in the new feild you made.
SMF 2.0.4
SimplePortal 2.3.5

LOGIC is a FOUR letter word! :)


Arantor

Or... use the existing information like membergroups and permissions which requires precisely zero edits?

crackatown

My mistake I wasn't clear. I meant the username or the member_name as it is stored in the database, like crackatown.

Arantor

And after you include SSI.php, that is already loaded for you and stored in $context['user']['name'], you don't even have to query for it.

crackatown

I added a column to the members table that is my own personal access level for the rest of the site. I can't use the membergroups as they overlap and stuff. So I am quickly accessing the database to retrieve my access level.

Arantor

In which case you don't want the user name, you want the user id, which is in $context['user']['id'], so you can query the smf_members table with it.

Though without knowing the intricacies of your system, there are almost certainly better ways of doing it (like when I wrote my own permissions system from scratch for the helpdesk system that I use)

crackatown

This seems the simplest, unless I make like 15 membergroups lol.

crackatown

ID gives me the number. When I use name it gives real_name. I want the login name (finally realized that was the best way to describe it lol). :)

Thanks.

crackatown

Where is the documentation for that stuff? So that way I don't have to keep asking you. lol.

Arantor

This is why I said about knowing the intricacies of your system. I can't tell you how to improve it without understanding what it is you actually hope to do by it.

Personally, for example, I'd tend to just create new permissions for users and check whether they have that permission rather than creating hybrid groups and so on. And the fact that I'd delineate permissions into roles by nature anyway, even if I display a different group to the outside world. (On several sites, for example, I have regular users, then a 'team' group, and a 'leadership/admin' group. These drive permissions. Then I have different groups for presentational purposes: but they have no permissions in themselves.)

Then I can check based on either permission or group id without any extra queries of any kind.


Why do you want the login name? If you're storing it in the members table, use the id because that's MUCH faster to query than the name. (Searching a fixed size, primary-indexed field is faster than any other kind of field)



Documentation? There's the wiki at wiki.simplemachines.org and the function DB somewhere but mostly it's not documented. Mostly I just read the source, when I haven't rewritten parts of it to work how I want.

crackatown

Ok, I will consider just creating a bunch of membergroups in that sense. Can two membergroups have the same name, but different ids?

Arantor

Sure they can! Though, honestly, I'd have to ask why you're making it so complicated on yourself... you know you can create groups that handle permissions and groups just for display?

Take SimpleDesk.net - every person on the team has a different badge to reflect what team they're in, such as my account (Gruffen) has a Developer badge, the QA team have their badge. They also have a 'team' group attached to their account, which allows them to comment on the bug tracker and see certain boards. We don't apply permissions to each of the team groups, we create and manage a single group that has permissions, and use a display group to display what's desired.

This is why, for the third time, I've been hinting that I need to know what you're trying to achieve rather than what you think you need.

crackatown

I sell an online guide. My website has access to the guide in a pure online format. Each page will perform a check to make sure they have permission. People can choose to have a premium membership where they gain access to an entirely different part of the forum.

How would I create show groups and permissions groups?

What would be the $context for permission group?

Arantor

You just create them in Admin > Membergroups

There's no difference between a permission group and a show group, only in how you organise it. Show groups just don't have any permissions attached. Permission groups do - because you give them permissions in Admin > Permissions. Then it's up to you to assign them to users in a way that makes sense: the show groups have the different group icon (like the team here uses) and you make that the user's primary group.

As for checking, you can check that in PHP by examining $user_info['groups'] with in_array.

For example, if you create a group that is used to control access to something and that particular group is group 15 (for example), you can use:
if (in_array(15, $user_info['groups']))
{
  // do something!
}

texasman1979

What he is saying, there is already an estavloshed mechanism for a user rank, membergroup. You can piggy back you authentication in top of the system that smf uses either passively or openly. Which it would make since that you do what he says, make the actual membergroup, "access" group, and then a cosmetic group, "Paid" group. But during your logging and authentication of the rest of your site, you check to see if they are in the access group. And in this same way, you can have multuple levels of access.
SMF 2.0.4
SimplePortal 2.3.5

LOGIC is a FOUR letter word! :)


crackatown

#58
I am going to use that and just require SSI.php on each page. Going to use a basic if (membergroup == blah || membergroup == blah2) then {load page} else {redirect}.

What would be the $context for membergroup? --> EDIT: I figured this out. I realized you told me in your last post. Thanks.

And should I use require or require_once? I read on other posts it was causing a ram issue.

Arantor

Use require_once everywhere.

Advertisement: