2016-02-11 6 views
0

У меня возникли проблемы с попыткой получить внешний логин для работы PHPBB с AJAX. Я не совсем уверен, что я здесь отсутствует, так вот что я получил:PHPBB Ajax External Login

HTML:

<div id="dialogin" class="dialoghide" title="Loading..."> 
    <form id="loginformadj" name="loginformadj" action="forum/ucp.php?mode=login" method="post" data-ajax="true" data-refresh="false"> 
     <h3><a id="dialoglogin" href="forum/ucp.php?mode=login" data-ajax="true">Login</a>&nbsp; &bull; &nbsp; 
     <a id="dialogregister" href="forum/ucp.php?mode=register" data-ajax="true">Register</a></h3> 
     <fieldset id="userinfo"> 
      <label for="username">Username:</label>&nbsp; 
      <input type="text" name="username" id="username" size="10" title="Username" /> 
      <label for="password">Password:</label>&nbsp; 
      <input type="password" name="password" id="password" size="10" title="Password" /> 
      <label for="autologin">Log me on automatically<input type="checkbox" name="autologin" id="autologin" /></label> 
     </fieldset> 
     <fieldset class="submit-buttons"> 
      <input type="submit" name="login" value="Login" /> 
      <input type="hidden" name="redirect" value="./index.php" /> 
     </fieldset> 
    </form> 
</div> 

JS включен на странице:

$(document).ready(function() { 
    // handle the login form through ajax for phpbb 
    $('#loginformadj').on('submit', 'form', function(event) { 
     event.preventDefault(); 

     var url= $(this).attr('action'); 
     alert(url); 
     $.ajax({ 
      url: url, 
      type: 'POST', 
      dataType: 'HTML', 
      data: new FormData(this), 
      processData: false, 
      contentType: false, 
      success: function (data, status) { 
       alert(data); 
      }, 
      error: function (xhr, desc, err) { 
       console.log('error'); 
      } 
     }); 
    }); 
}); 

И это требуется на верх страницы из другого файла, в котором я использую PhpBB сессии и другие функции:

<?php 
/* 
* BEGIN PHPBB STANDARD PAGE SETUP 
*/ 
define('IN_PHPBB', true); 
$phpbb_root_path = './forum/'; 
$website_root_path = './'; 
$phpEx = substr(strrchr(__FILE__, '.'), 1); 

include($phpbb_root_path . 'common.' . $phpEx); 
//include($phpbb_root_path . 'includes/functions.' . $phpEx); 
include($phpbb_root_path . 'includes/functions_module.' . $phpEx); 
include($phpbb_root_path . 'includes/functions_user.' . $phpEx); 

// Start session management 
$user->session_begin(); 
$auth->acl($user->data); 
$user->setup(); 
/* 
* END PHPBB STANDARD PAGE SETUP 
*/ 
?> 

форма вытягивается в Jquery ди алог. Он фактически регистрирует меня, а затем сразу перенаправляет меня на индекс форума в ./forum вместо использования ajax и отправки предупреждений. Я не получаю никаких предупреждений, которые я установил или что-то еще. Я пробовал все, что мог придумать. :/

Чтобы добавить, у меня есть имя пользователя, аватара пользователя, а также выйдите из системы на моей внешней странице. Просто не могу заставить логин работать вообще.

+0

Кто-нибудь? Я здесь серьезно теряю идеи ... – Grant

ответ

0

Проблема, по крайней мере на начальном этапе, я вызывал проверку отправки в форум для jquery неправильно.

$(document).ready(function() { 
// handle the login form through ajax for phpbb 
$(document).on('submit', '#login', function(event) { 
    event.preventDefault(); 

    var url= $(this).attr('action'); 
    alert(url); 
    $.ajax({ 
     url: url, 
     type: 'POST', 
     dataType: 'HTML', 
     data: new FormData(this), 
     processData: false, 
     contentType: false, 
     success: function (data, status) { 
      alert(data); 
     }, 
     error: function (xhr, desc, err) { 
      console.log('error'); 
     } 
    }); 
}); 
}); 

Я также прочитал, что вам нужно получить sid с $ user-> данными в скрытом поле. Я включил это в форму и не проверял, имеет ли это значение или нет.