Invision Community 4: SEO, prepare for v5 and dormant account notifications Matt November 11, 2024Nov 11
Posted June 19, 20177 yr I used this example below to allow users who have logged in to a third party application to be automatically logged in to the community. I created the hook, but specifically this part I can't seem to get working: /* If our check was successful, we create the member if he does not exist, otherwise we load the member. We then set $this->member to the member object we've loaded */ I coded this and confirmed $username and $email are collected: try { $member = \IPS\Member::load( $username ); } catch ( \OutOfRangeException $e ) { $member = new \IPS\Member; $member->member_group_id = \IPS\Settings::i()->member_group; $member->name = $username; $member->email = $email; // You'll need to get the email from your login handler's database // You may want to set additional properties here $member->save(); } $this->member = $member; But it doesn't seem to log the user in. Any guidance would be appreciated.
June 19, 20177 yr $username = 'someusername'; $member = \IPS\Member::load($username, 'name'); if ($member->member_id) { // Existing user } else { // Non existing user } if you want to check by email $member = \IPS\Member::load($email, 'email');
June 19, 20177 yr Yes, loading a member that does not exist does not throw an OutOfRangeException (I'll take a look at the documentation, maybe it is out of date). Instead, a guest object is returned. Additionally, the ActiveRecord class is expecting an id - if you want to load by username, you have to set the second parameter to indicate that.
June 19, 20177 yr Author Thank you! this did the trick!! I was now assigning the correct member, but it wasn't logging them in. Adding this line and it did the trick: \IPS\Session::i()->setMember( $member ); @bfarber - the documentation was good... it just lacked all of my code, I had to scrounge around the net to get what I put together above. The only documentation was the comments: /* Check the remote application here - this may involve looking for custom cookies your application sets and then passing them to a callback script on the remote server, or including a custom PHP script you have written */ /* If our check was successful, we create the member if he does not exist, otherwise we load the member. We then set $this->member to the member object we've loaded */
Archived
This topic is now archived and is closed to further replies.