Vanilla 1 is no longer supported or maintained. If you need a copy, you can get it here.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.
Options

How to use People

edited July 2006 in Vanilla 1.0 Help
I've just installed the latest version off SVN because I'm interested in using the new "People" framework to handle authentication in another application I'm developing for my site that uses a Vanilla forum. I don't know OO PHP too well, so I'm pretty confused about how it works. The basic tasks I'll need to carry out: * Login user, starting session and setting cookies * Retrieve user info (userid, and name) * logout user I'd greatly appreciate it if someone could provide brief samples of how to do those things or explain what some of the People classes do. Thanks!
«1

Comments

  • Options
    I found the following in another thread from SirNot:

    <?php include('appg/settings.php'); include('appg/init_ajax.php'); $Errors = array( -2 => 'Fatal database error', -1 => 'Insufficient permissions', 0 => 'Username/password combination not found', ); $Ret = $Context->Authenticator->Authenticate($Username, $Password, $Persistant); if($Ret <= 0) echo($Errors[$Ret]); ?>
    Will $Context->Authenticator->Authenticate($Username, $Password, $Persistant); do all the work of creating the session and cookies?

    How do I check if the user is logged in and access user information such as username?
  • Options
    edited May 2006
    $Context->Session->UserID is the userID of the logged in user; it will be '0' if nobody is logged in:

    if ($Context->Session->UserID) { //User Logged In! Echo their User Name. echo $Context->Session->User->Name; }
  • Options
    Thanks, Bergamot!

    I've also read here somewhere that I can just include appg/init_people.php rather than the two files (settings.php and init_ajax.php) above. Is this correct?
  • Options
    the two lines I include wherever i use people are:

    include_once("./appg/settings.php"); include_once("./appg/init_people.php");

    No idea why you'd need the ajax one for session management.
  • Options
    edited May 2006
    Yeah, I was wondering the same thing about the ajax one. It also looks like init_people.php includes settings.php

    Edit: Looks like settings has to be included first, so I try including settings and then init_people and I get the following error:

    Fatal error: Cannot redeclare class mysql in /home/path/to/site/forum/library/Framework/Framework.Class.MySQL.php on line 139
  • Options
    I noticed there were issues with a redeclared class over in the other thread too, but a solution was never given. I'm curious if this is a known bug or if it's just a matter of me incorrectly including the classes?
  • Options
    3stripe3stripe ✭✭
    Hmm, from the subject, I was hoping this thread was going to be alltogether more machevelian.
  • Options
    Has anyone managed to successfully use "People" outside of Vanilla? I thought this is what it was created for, but I've really hit a wall here. I don't want to start messing around with core files either. I'm at a point where I need to decide to use "People" or build my own separate login system and require 2 usernames and passwords.
  • Options
    edited May 2006
    The application I'm trying to integrate this into also uses a class called mysql, which I'm now guessing is the problem? Does anyone know of a workaround other than renaming the class in one of the two apps?

    Looks like "StringFormatter" is also duplicated in both....what a nightmare this little project has turned out to be.
  • Options
    MarkMark Vanilla Staff
    You can make a copy of Vanilla's MySQL object and name the file Framework.Class.VanillaMySQL.php. Then open up the file and change the class name to VanillaMySQL.

    Then open up your conf/settings.php file and add this:

    $Configuration['DATABASE_SERVER'] = 'VanillaMySQL';


    For the StringFormatter you're probably going to have to rename it in one of the two apps.
  • Options
    What app are you trying to combine it with?
  • Options
    MarkMark Vanilla Staff
    If all you're worried about is integrating the login, I think you're overthinking it a bit too much. Use your other application's login screen, and then alter Vanilla to use the same user table and handle sessions the same way. Read this and see what you think: http://lussumo.com/swell/42/Data-Objects-External-Application-Integration/
  • Options
    edited May 2006
    I'm trying to combine it with Symphony. There is no pre-existing login system that I'm using. I was hoping to use Vanilla's and then just create my own interface for it.

    Mark, I did try to rename the conflicting classes and it seemed to work witht the MySQL class, but not so well with the StringFormatter. Maybe I'll give it a closer look. The link you provided sounds interesting, though I don't understand the "Then you will go into your conf/settings.php file and change the Database structure to reflect your new CatUser table and the fields inside it." I'm looking at the settings file and I'm not seeing how it relates to the database structure.

    Edit: Nevermind, I found the correct file, appg/database.php
  • Options
    It's nice to be able to go both ways with logins, though, in case I have a large number of Vanilla users that I'd like to let login to app 'x'.
  • Options
    how can i find out the FirstName from the User:

    echo $Context->Session->User->FirstName;
    doesn't work
  • Options
    That's weird, because that's how to do it.

    Are you sure the currently logged in user has a firstname?
  • Options
    Yes the currently logged in user has a firstname. Now I looked into the database and the user has a firstname. When I use:
    echo $Context->Session->User->Name; i get the Username but the FirstName doesn't work. LastName doesn't work at all.
    When I mistype it, like Firstname or firstname i get an error, but with FirstName i only get an empty string
  • Options
    What about FullName or LastName?
  • Options
    ithcyithcy New
    edited May 2006
    you can do it like this:
    if (!@$UserManager) $UserManager = $Context->ObjectFactory->NewContextObject($Context, "UserManager"); $AccountUserID = ForceIncomingInt("u", $Context->Session->UserID); if (!@$AccountUser) $AccountUser = $UserManager->GetUserById($AccountUserID);
    and then print $AccountUser->FirstName or FullName or whatever.
  • Options
    Thanks a lot, that works.
This discussion has been closed.