Kohana/PHP身份验证在通过AJAX发出请求时失败
我有一个由所有控制器继承的基类。我在基类中有一个函数,它使用Auth确定登录用户角色。一旦用户角色被设置,则确定变量$LoggedIn_角色被设置 这个方法在初始页面加载时被正确调用,但是稍后我会发出ajax调用来检查用户是否仍然登录,此时Auth::logged_in总是返回0 我使用的kohana版本是3.3 请任何人提出回避这一问题的最佳办法。谢谢 登入-Kohana/PHP身份验证在通过AJAX发出请求时失败,php,ajax,kohana,kohana-3.3,Php,Ajax,Kohana,Kohana 3.3,我有一个由所有控制器继承的基类。我在基类中有一个函数,它使用Auth确定登录用户角色。一旦用户角色被设置,则确定变量$LoggedIn_角色被设置 这个方法在初始页面加载时被正确调用,但是稍后我会发出ajax调用来检查用户是否仍然登录,此时Auth::logged_in总是返回0 我使用的kohana版本是3.3 请任何人提出回避这一问题的最佳办法。谢谢 登入- if ($ValidObj->check()) { if (Auth::instanc
if ($ValidObj->check()) {
if (Auth::instance()->login($_POST['email'], $_POST['password'],FALSE)) {
$this->DoPostLoginJobs();
} else {
$this->ManageError(Controller_Application::MsgWrongUserCredentials);
}
} else {
$this->Form_Errors = $ValidObj->errors('');
}
注销-
public function action_logout() {
$loggedout = Auth::instance()->logout();
if ($loggedout)
HTTP::redirect ('/home/'); // redirects to the home page.
}
在控制器应用程序内部。所有控制器的基类
public function DetermineUserRole() {
$this->LoggedIn_Role = Controller_Application::None;
try {
if (Auth::instance()->logged_in('freelancer')) {
$this->LoggedIn_Role = Controller_Application::Freelancer;
$this->LoggedIn_Id = Auth::instance()->get_user()->pk();
} else if (Auth::instance()->logged_in('employer')) {
$this->LoggedIn_Role = Controller_Application::Employer;
$this->LoggedIn_Id = Auth::instance()->get_user()->pk();
}
} catch (Gettrix_Exception $exc) {
$this->ManageError(Controller_Application::RedirectNonRecoverableError);
}
public function before() {
if ($this->request->is_ajax()) {
$this->auto_render = false;
}
$this->DetermineUserRole();
if($this->auto_render==TRUE){
parent::before();
$this->template->content = '';
$this->template->styles = array();
$this->template->scripts = array();
View::set_global('site_name', 'TheWebTeam');
View::bind_global('Form_Errors', $this->Form_Errors);
View::bind_global('LoggedIn_Role', $this->LoggedIn_Role);
View::bind_global('LoggedIn_Id', $this->LoggedIn_Id);
View::bind_global('InvitedEmail', $this->InvitedEmail);
View::bind_global('InvitedUniqueID', $this->InvitedUniqueID);
View::bind_global('scripts', $this->template->scripts);
View::bind_global('styles', $this->template->styles);
}
//它位于主页控制器内,其中列出了登录用户的所有作业
public function action_joblist()
{
echo Auth::instance()->logged_in() . //The state holds to the initial state, doesn't //change when the user is logged out or logged in.
}
请注意,作业列表是通过AJAX/Jquery调用调用的。按照链接中给出的说明解决问题:您能显示一些代码吗?@kingkero很抱歉,我之前没有注意到您的评论。根据你的指示,我添加了一些代码。如果你需要任何其他细节,请告诉我。谢谢