I first require_once a file with this code to set up the XF2 environment:
Then I use the finder as follows:
Then I get some data from that user object, and that all works fine.
Then if the data meets certain conditions, I try to authenticate the user as follows:
If I don't do the finder code first, then the authenticate code works. But if I do the finder code first, then the authenticate code block throws an error after the first line:
It throws this error:
I also tried unsetting $finder and $xfuser before executing the second block of code, but still get the same error.
Anyone know how to get around this?
Thanks!
PHP:
$dir = __DIR__;
require($dir . '/src/XF.php');
XF::start($dir);
Then I use the finder as follows:
PHP:
$finder = \XF::finder('XF:User');
$xfuser = $finder->where('username', $username)->fetchOne();
Then I get some data from that user object, and that all works fine.
Then if the data meets certain conditions, I try to authenticate the user as follows:
PHP:
$xfapp = \XF::setupApp('XF\App');
$xfip = $xfapp->request->getIp();
$loginService = $xfapp->service('XF:User\Login', $username, $xfip);
If I don't do the finder code first, then the authenticate code works. But if I do the finder code first, then the authenticate code block throws an error after the first line:
PHP:
$xfapp = \XF::setupApp('XF\App');
It throws this error:
Code:
An exception occurred: [LogicException] A second app cannot be setup. Tried to set XF\App after setting XF\App in src/XF.php on line 285
XF::setApp() in src/XF.php at line 311
XF::setupApp() in [**my file**] at line 230
I also tried unsetting $finder and $xfuser before executing the second block of code, but still get the same error.
Anyone know how to get around this?
Thanks!