Please upgrade here. These earlier versions are no longer being updated and have security issues.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.
Options

how to catch login session

jackmaessenjackmaessen ✭✭✭
edited December 2014 in Vanilla 2.0 - 2.8

I want to make a normal website on the main domain, seperated from the forum, and the forum on a subdomain, lets say: www.mywebsite.com/forum

I also want users give the oppertunity to login on the main page and i want to do that with the login session of the forum.
So when they already have logged in on the main page and go to the forum n the subdomain, they see that they are already logged in. What is the most easy way to make this possible?
I used to do this before with Custom pages or Extra page addon, but it is very devious. You are still captured in the frame of the forum and you do not have really a free hand to make your own page.

Tagged:

Comments

  • Options
    R_JR_J Ex-Fanboy Munich Admin

    Create an application called "nano" and create those two subfolders/files:

    /applications/nano/settings/about.php

    <?php
    $ApplicationInfo['Nano'] = array(
        'Name' => 'Nano',
        'Description' => 'Lite, custom page',
        'Version' => APPLICATION_VERSION,
        'Author' => 'R_J',
        'License' => 'MIT'
    );
    

    /applications/nano/controllers/class.nanocontroller.php

    <?php defined('APPLICATION') or die;
    class NanoController extends Gdn_Controller {
        public function index ($Sender) {
           $Session = Gdn::Session();
           $UserID = $Session->UserID;
           echo "UserID = $UserID";
       }
    }
    

    After activating your application, looking at yourpage.com/nano will give you one single line of output: "UserID = whatever".

    Maybe you can achieve the same with a plugin, but since you want to create a custom page that should not be a simple addition to your forum, it feels more logical to me to set it up as an application

  • Options
    hgtonighthgtonight ∞ · New Moderator

    Just fetch the profile or memodule via ajax. That gives you the exact data you want without writing any custom code.

    E.g. http://vanillaforums.org/profile.json will give you the profile object of the logged in user. If no user is logged in, the json object returns a 404.

    E.g. http://vanillaforums.org/module/memodule will return the html markup of the me module for the logged in user. If no user is logged in, it will give you sign in and register links.

    I guess I am just lazy.

    Search first

    Check out the Documentation! We are always looking for new content and pull requests.

    Click on insightful, awesome, and funny reactions to thank community volunteers for their valuable posts.

  • Options
    jackmaessenjackmaessen ✭✭✭
    edited December 2014

    Thank you @R_J and @hgtonight.
    I will look at these options.

    I guess I am just lazy.

    That is a good feature of a programmer. It means you work efficiently without unnecessary operations.

  • Options
    jackmaessenjackmaessen ✭✭✭
    edited December 2014

    i tried to fetch the html hgtonight supoorted above.
    I did it this way: in the custom page in a testdirectory i put this line in the index.php:

     $url = 'http://forum.webprofis.nl/module/memodule';
      echo file_get_contents($url);
    

    On the forum (forum.webprofis.nl) i am logged in.
    But in the custom page (forum.webprofis.nl/testdirectory/index.php) i see the options "Login" and "Register".
    But these should not appear because i am already logged in on the forum

  • Options
    hgtonighthgtonight ∞ · New Moderator

    @jackmaessen said:
    i tried to fetch the html hgtonight supoorted above.
    I did it this way: in the custom page in a testdirectory i put this line in the index.php:

     $url = 'http://forum.webprofis.nl/module/memodule';
      echo file_get_contents($url);
    

    On the forum (forum.webprofis.nl) i am logged in.
    But in the custom page (forum.webprofis.nl/testdirectory/index.php) i see the options "Login" and "Register".
    But these should not appear because i am already logged in on the forum

    That will not work because the server is requesting the page, not the client. If you request the page via JavaScript the client's "session" is continued and you will get the expected outcome.

    You can do it server side, just not the way I was suggesting it. You either have to load the framework's session object or parse the Vanilla cookie yourself.

    Search first

    Check out the Documentation! We are always looking for new content and pull requests.

    Click on insightful, awesome, and funny reactions to thank community volunteers for their valuable posts.

Sign In or Register to comment.