Registering and Signing in to XF from a php program

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.
 
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();
 
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.
 
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.
 
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.
 
It's possible that the xf_user cookie works in conjunction with ip or other checks. I need to find that out.
 
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
 
It's possible that the xf_user cookie works in conjunction with ip or other checks. I need to find that out.

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
Liam, that is the type of information I was looking for. I'll get started on that direction.

Thank you
 
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.
 
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.
 
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.

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
 
@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?
 
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.
 
Deleted

TFA = two factor authentication
 

Attachments

  • upload_2015-12-13_1-13-29.webp
    upload_2015-12-13_1-13-29.webp
    96.2 KB · Views: 12
  • upload_2015-12-13_1-30-53.webp
    upload_2015-12-13_1-30-53.webp
    26.8 KB · Views: 14
Last edited:
Back
Top Bottom