Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

General Questions

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Using ss member class to authenticate external php app


Reply

2 Posts   880 Views

Avatar
martbarr

27 October 2010 at 6:41am Community Member, 46 Posts

Can I do this easily?

I have a need to authenticate users in my own app where users must already be logged into ss.
I just need to do something like IsUserLoggedIn($Usr) and get a 0 or 1 returned depending whether SS user is logged in.
I'll maintain my own user table and allowed actions in my app.
Just need a Yes or No from SS

I can see the Member class - how do I call it from a non SS app?
Or do I think again?

Thanks
Martin

Avatar
Willr

27 October 2010 at 5:32pm Forum Moderator, 5511 Posts

I don't believe you can check to see if a member is logged in on the site as it involves cookies / session data on their side. You can implement your own functionality for this however. One way would be to add a field to member IsLoggedIn and a couple of functions as a decorator.

<?php

class TrackedMember extends DataObjectDecorator {

function extraStatics() {
return array('db' => array('IsLoggedIn' => 'Boolean'));
}

function memberLoggedIn() {
$this->owner->IsLoggedIn = true;
$this->owner->write();
}

function memberLoggedOut() {
$this->owner->IsLoggedIn = false;
$this->owner->write();
}

Then you can directly query the Members table in the database for IsLoggedIn. Its not perfect, if the session expires then loggedout will never fire so perhaps a check on the last visited date would work.