Large Scale Planes Posted June 17, 2018 Posted June 17, 2018 Some years ago, I built a bespoke CMS for the website associated with our community that authenticated its logins against the v3 IPB member database. This enabled me to leverage IPB's user management features, which were applicable to the CMS too (user roles and permissions, etc). This broke completely with the introduction of v4, and I've been holding off upgrading until I can figure out how to make it work again in a dev environment. Sadly, I'm having no luck whatsoever! I've been trying to grok the information provided in the Developer Documentation, but my PHP skills are rusty, and none too advanced these days, so I thought I'd ask for some guidance here. Also, most of the approaches in the docs are about providing alternative login methods for the forums themselves, which is not what I'm trying to do. I merely need to authenticate a user's credentials against those stored in the database, and then let the CMS do the rest. I thought I might have hit upon a usable solution with the SSO approach detailed in the documentation: However, upon successfully acquiring the logged-in user's details, I attempt to store them in the session that gets created for the CMS, but it doesn't persist, and it seems that I end up with two different session IDs. I'm assuming that the following code intialises an IPB session that subsequently clashes with my own session: /* Initiate the session to verify who this user is */ \IPS\Session\Front::i(); Any idea how to get past this issue? I'm really stuck right now. Kev
bfarber Posted June 25, 2018 Posted June 25, 2018 So you have the user's authentication details (username/email and password) and want to validate them against an Invision Community database? Assuming you are using 4.3.x and you are using the Standard/Internal login handler, you should be able to do the following: require '/path/to/forums/init.php'; $username = ''; $password = ''; $login = new \IPS\Login( \IPS\Http\Url::external( "http://yoururl.com" ), \IPS\Login::LOGIN_FRONT ); $member = \IPS\Login\Handler::findMethod( 'IPS\Login\Handler\Standard' )->authenticateUsernamePassword( $login, $username, $password ); This is a crude mockup and I haven't tested it, but hopefully it points you in the right direction.
Large Scale Planes Posted June 30, 2018 Author Posted June 30, 2018 Thanks! I didn't see your post until now as I didn't receive the expected email notification. I'll give your suggestion a whirl and get back to you. Kev
Large Scale Planes Posted July 1, 2018 Author Posted July 1, 2018 OK, so that code works straight out of the box in terms of validating the login credentials and returning a valid member object. But this bumps me to my next problem! I need to access the member's group (member_group_id) to determine what happens next, as only certain member groups are allowed to log in to the CMS. However, I can't seem to access this property, presumably because it's marked protected (my knowledge of PHP OOP is very slight indeed). Executing print_r on the member object shows me all the data, but I can't seem to access it programmatically. Is there any easy way around this? Kev
Adriano Faria Posted July 1, 2018 Posted July 1, 2018 If you have the member object, you can use $member->group[‘column’] or you can load the group by using: $group = \IPS\Member\Group::load( $member->member_group_id );
Large Scale Planes Posted July 1, 2018 Author Posted July 1, 2018 Thanks, Adriano! This works a treat, and will hopefully save the day. Kev
bfarber Posted July 2, 2018 Posted July 2, 2018 $member->member_group_id will give you the group. All of the columns are available via a magic __get() method, so you can do $member->{$column_name}.
Recommended Posts
Archived
This topic is now archived and is closed to further replies.