LPH
Well-known member
I'm running around like a chicken with my head cut off ... or am I a dog chasing my own tail? Regardless, something is very wrong with my attempts to get a user created externally and logged into XenForo without the user intervening (register and login in one form).
The user is created. The var_dump shows the user information, however, they are not logged in. Why can't there be a simple XenForo_Login and bang. Done. LOL.
Any suggestions on where I'm going wrong after creating the $user ?
I've tried many variations of the above but keep going in circles. Thank you for your guidance.
PHP:
<div id="xenregister">
<form action="" method="post" id="pageLogin">
<div class="ctrlWrapper">
<dl class="ctrlUnit">
<label for="RegisterControl">Preferred Username:</label><br />
<input type="text" size="15" name="username" id="RegisterControl" class="textCtrl" tabindex="105" /><br />
<label for="RegisterControl">Your email address:</label><br />
<input type="text" size="15" name="email" id="RegisterControl" class="textCtrl" tabindex="106" /><br />
<label for="ctrl_password">Password:</label><br />
<input type="password" size="15" name="password" id="ctrl_password" class="textCtrl" tabindex="107" /><br />
<input type="submit" name="registerButton" class="button primary" value="Register" tabindex="108" />
<label for="ctrl_remember" class="rememberPassword">
<input type="checkbox" name="remember" value="1" id="ctrl_remember" tabindex="109" /> stay logged in</label>
</dl>
</div>
<input type="hidden" name="cookie_check" value="0" />
<input type="hidden" name="redirect" value="<?php echo $redirect ?>" />
<input type="hidden" name="_xfToken" value="" />
</form>
</div>
<?php
if ( isset( $_POST["registerButton"] ) ) {
// Build array
$data = array( 'login' => $_POST["username"], 'password' => $_POST["password"] );
// Create the XenForo User.
$user_id = XenWord::createUser($_POST["username"], $_POST["email"], $_POST["password"] );
$userModel = new XenForo_Model_User();
$loginModel = new XenForo_Model_Login();
$user = $userModel->getUserById( $user_id );
var_dump($user);
$userid = $userModel->validateAuthentication($data['login'], $data['password'], $error);
if (!$userid)
{
$loginModel->logLoginAttempt($data['login']);
return $error;
}
$loginModel->clearLoginAttempts($data['login']);
if ($data['remember'])
{
$userModel->setUserRememberCookie($userid);
}
XenForo_Model_Ip::log($userid, 'user', $userid, 'login');
// $userModel->deleteSessionActivity(0, $this->request->getClientIp(false));
$session = XenForo_Application::get('session');
$session->changeUserId($userid);
XenForo_Visitor::setup($userid);
}
The user is created. The var_dump shows the user information, however, they are not logged in. Why can't there be a simple XenForo_Login and bang. Done. LOL.
Any suggestions on where I'm going wrong after creating the $user ?
I've tried many variations of the above but keep going in circles. Thank you for your guidance.