Jump to:

23479 Posts in 18951 Topics by 2878 members

General Questions

SilverStripe Forums » General Questions » Integrate SilverStripe User Classes into Existing App

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

Page: 1
Go to End
Author Topic: 354 Views
  • Lazarus404
    Avatar
    Community Member
    71 Posts

    Integrate SilverStripe User Classes into Existing App Link to this post

    Hey guys,

    I posted this question to the migration forum, but I think that might have been the wrong place.

    I have a SilverStripe app and, alongside it, a different non-SilverStripe PHP app. I'd like to update parts of the non-SilverStripe app to check whether a user is logged in to the SilverStripe app and have it query for user information. How do I go about doing this?

    Thanks,
    Lee

  • Lazarus404
    Avatar
    Community Member
    71 Posts
  • Lazarus404
    Avatar
    Community Member
    71 Posts

    Re: Integrate SilverStripe User Classes into Existing App Link to this post

    Surely someone's had to do this? Essentially, I'm simply using Sapphire classes in existing PHP classes. What do I need to include to make this work? Do I need to make the existing PHP classes extend anything?

    Thanks,
    Lee

  • Willr
    Avatar
    Forum Moderator
    5502 Posts

    Re: Integrate SilverStripe User Classes into Existing App Link to this post

    You could try a couple ways of doing this, require the code directly. If you do a require for sapphire/main.php that should load in quite a few classes on your behalf but this could fail as it expects to be passed a direct web request. Otherwise you could make your custom code check for the session values SS sets. I assume your PHP is running on the same PHPSESSION so you should be able to use $_SESSION directly in your code to see if the user is logged in.

    You could create a basic API for sending information to your application i.e a custom controller which returns the user information in JSON. You could then load the controller via CURL.

    <?php

    class Public extends Controller {

    function member() {
    return json_encode(Member::currentUser());
    }
    }

    Hitting yoursite.com/Public/member with a curl request will then return the JSON object for the currently logged in member. Of course this will only work if you share the same session ID as the app itself.

  • Lazarus404
    Avatar
    Community Member
    71 Posts

    Re: Integrate SilverStripe User Classes into Existing App Link to this post

    I thought of the latter, and tried it, but they didn't play ball. The newer app simply created a new session. Thhe first idea was getting frustrating as I needed a lot of SS features. In the end, I had the client side pull data via Ajax and then validated it server side in both locations. It's fiddly and not ideal, but secure.

    Thanks for the advice, tho.

    Lee

    354 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.