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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

General Questions /

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

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

Using ss member class to authenticate external php app


Go to End


2 Posts   1214 Views

Avatar
martbarr

Community Member, 59 Posts

27 October 2010 at 6:41am

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

Forum Moderator, 5523 Posts

27 October 2010 at 5:32pm

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.