1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Registering and Signing in to XF from a php program

Discussion in 'XenForo Development Discussions' started by Dan Allen, Nov 23, 2015.

Tags:
  1. Dan Allen

    Dan Allen Active Member

    Our site is a membership site, everyone has to sign in. The forum is critical to site but it is not the central feature. The requirement is that when someone signs in to our site with our custom login system, we need to log them into XF at the same time.

    Related requirement: when someone joins our site, they can join by buying into any one of 40 products we have. Each product has its own private forum, with a user group that has access. We need to be able to add people to user groups when they buy products and remove them if they cancel or fall behind on payments.

    I looked for information on how to do this, but am not finding what I need. is there any direction or guide for this?

    Any information on this would be extremely much appreciated.
     
  2. Brogan

    Brogan XenForo Moderator Staff Member

    Are you proficient with PHP?

    It will require custom development.
     
  3. Dan Allen

    Dan Allen Active Member

    Well, I have spent as much as just about anyone can spend making things with php over the last 5 years, but I wouldn't say proficient. I'd say it is enough that I am relieved hear mention of php instead of templates. It always cracks me up when people say templates give non programmers a way to edit without programming. Templates look like programs to me. Enough that I am hoping you tell me more.

    I know how to do this kind of thing with a system I don't like mentioning, WordPress. Found a way to do what I am talking about with another British forum software, phpbb3. I used some of their recommended solution then found some ways to improve performance of password handling from my point of view. We get people into groups when they register check their status whenever they load a page.

    That said, xf code is not what I am used to. Here is our custom version of xf/index.php and it still works
    Code:
    $startTime = microtime(true);
    $fileDir = dirname(__FILE__);
    require 'hookups/000_common/000-dansoft-core.php';
    require 'css/randomized-gradients.php';
    require($fileDir . '/library/XenForo/Autoloader.php');
    XenForo_Autoloader::getInstance()->setupAutoloader($fileDir . '/library');
    
    XenForo_Application::initialize($fileDir . '/library', $fileDir);
    XenForo_Application::set('page_start_time', $startTime);
    
    $fc = new XenForo_FrontController(new XenForo_Dependencies_Public());
    require 'hookups/000_common/022-pageTimerRecordsFloatingMT.php';
    
    $fc->run();
    
     
  4. Dan Allen

    Dan Allen Active Member

    and I am over 30, so programming is not possible for me anymore, but I don't let that stop me from trying.

    I am over 40, so I might as well be dead when it comes to programming.
    I am over 50, so I was raised in a world before computers were discovered.
     
  5. Brogan

    Brogan XenForo Moderator Staff Member

    My question was primarily to determine whether it was something you would do yourself or whether you would need a developer.
    As it's the former, I have moved the thread to the development forum.
     
  6. Dan Allen

    Dan Allen Active Member

    ok thank you.

    Now wait for some suggestions? Is there a document that explains it?
     
  7. Dan Allen

    Dan Allen Active Member

    For what it is worth, it looks like getting in to XF from another app can be done by putting the xf_user cookie onto the browser.

    So when people login to our site, we will put a cookie named xf_user, with the user's unique cookie value, onto their browsers and that will have the effect of logging them in to xf. I don't know where those cookie values come from yet. They must be in the database/programs somewhere.

    Now, I need to figure out how to get people registered in XF when they register at our site through our custom security gateway. Then this job will be a wrap.
     
  8. Dan Allen

    Dan Allen Active Member

    It's possible that the xf_user cookie works in conjunction with ip or other checks. I need to find that out.
     
  9. Liam W

    Liam W Well-Known Member

    The easiest way to do it would be to just include the XenForo autoloader in your external system, and use the normal (default) system for logging people in (check the XenForo_ControllerPublic_Login file).

    Liam
     
  10. Dan Allen

    Dan Allen Active Member

    Liam, that is the type of information I was looking for. I'll get started on that direction.

    Thank you
     
  11. Dan Allen

    Dan Allen Active Member

    To include the autoloader in the external app, is that done by these lines of code?

    Code:
    require($fileDir . 'path-to/library/XenForo/Autoloader.php');
    XenForo_Autoloader::getInstance()->setupAutoloader($fileDir . '/library');
    
    My app has xf in subdirectory, called forum. So I am wanting to verify, that in my app I am going to have this:
    Code:
    require($fileDir . 'forum/XenForo/Autoloader.php');
    XenForo_Autoloader::getInstance()->setupAutoloader($fileDir . '/library');
    
    Then once that is done, I am sorry, but I do not understand how I get from there to logging into XF through XenForo_ControllerPublic_Login file. I found documentation it here http:// v x f.vn/docs/classes/XenForo_ControllerPublic_Login.html

    My problem is I really don't have a clear idea of how this process is going to work. I have done a lot of programming over the years, including php, but I am not familiar enough with the general scheme of these programs to understand what I am looking at. I don't think I will need a long lesson, but if there are any details you can add to what I need to do, I am sure it would help a lot.
     
  12. Dan Allen

    Dan Allen Active Member

    Liam, I read that you asked for your name to be mentioned when wanting you to respond to a post so I am mentioning your name now. I am hoping you can respond to the post above this one. Cheers.
     
  13. The Forum Heroes

    The Forum Heroes Well-Known Member

    You would want to use @Liam W
     
  14. Dan Allen

    Dan Allen Active Member

    [QUOTE="Mike Edge, post: 1015922, member: 8963"yo]u would want to use @Liam W[/QUOTE]thank you
     
    The Forum Heroes likes this.
  15. Liam W

    Liam W Well-Known Member

    You're on the right track.

    To login, you'll want to see how XenForo logs people in. That's in the Login controller.

    Basically, you get a user array from the model with the username, and then use the XenForo_Authentication classes to confirm the password.

    To register a user, you would use the registration datawriter (check the register controller).

    Liam
     
  16. Dan Allen

    Dan Allen Active Member

    @Liam W, Thank you for helping me out with this, I appreciate it a lot.

    I found something called the xenforo sdk. It has nearly all the functions I need easily accessible and understandable. You just put one file, called XenForoSDK.php into the root of the xenforo installation, then include that file where ever it's needed on the server and all those functions work.

    If I understand it right, XenForoSDK.php contains in it the code I would had to have made more or less for myself, being on the path I had started. I think this is saving me a ton of time, because I really was not understanding now to put these functions together, but using them is easy.

    For example, I have no clue about what would make me need this
    Code:
    class XenForoSDK
    {
       public function __construct() {
         $startTime = microtime(true);
         $fileDir = XF_ROOT;
    
         require($fileDir . '/library/XenForo/Autoloader.php');
         XenForo_Autoloader::getInstance()->setupAutoloader($fileDir . '/library');
    
         XenForo_Application::initialize($fileDir . '/library', $fileDir);
         XenForo_Application::set('page_start_time', $startTime);
         XenForo_Session::startPublicSession();
       }
    
    
    But I can see that is needed for this, which is something else I have no clue about, even given the constructor above
    Code:
      public function validateLogin($email, $password, $remember=false, $doLogin=false) {
         // Init
         $loginModel = XenForo_Model::create('XenForo_Model_Login');
         $userModel = XenForo_Model::create('XenForo_Model_User');
         $hasError = null;
    
         // Validate user info
         $user = $userModel->validateAuthentication($email, $password, $hasError);
         if(!$user) {
           $loginModel->logLoginAttempt($email);
           return new XenForo_Phrase($hasError);
         }
    
         // Clear login attempts
         $loginModel->clearLoginAttempts($email);
    
         // Login
         if($doLogin) {
           return $this->login($user, $remember);
         }
         
         // This just validates the login info
         // so a bool is a good idea to return here
         return true;
       }
    
    So, @Liam W, my question is this: is XenForoSDK something like the road I was on, or is this a different thing?

    Do you have any other thoughts or comments about XenForoSDK?
     
  17. Dan Allen

    Dan Allen Active Member

    And @Liam W, of course, take your time to respond, but you should know, the world awaits your response.

    .
    .
    .
    .
    .
    .
    .
    .
    .
    Well, maybe the whole world is not awaiting, but it should be.
     
  18. Dan Allen

    Dan Allen Active Member

    Deleted

    TFA = two factor authentication
     

    Attached Files:

    Last edited: Dec 13, 2015

Share This Page