【发布时间】:2012-12-05 07:26:16
【问题描述】:
我有一个为游戏启动第三方脚本的用户注册页面,我只希望该页面在用户接受许可时完成加载(它将设置一个 HTTP 变量)。我目前有它提示权限,但正在后台加载页面,我将如何“等待”或“重新加载”页面以重新检查此变量是否已设置?
添加控制器功能
public function add() {
if ($this->User->IGBRequireTrust()) {
if ($this->request->is('post')) {
$this->User->create();
if ($this->User->save($this->request->data)) {
$this->Session->setFlash(__('The user has been saved'));
$this->redirect(array('action' => 'index'));
} else {
$this->Session->setFlash(__('The user could not be saved. Please, try again.'));
}
}
}
}
上面调用的模型中的公共函数
// Returns TRUE if the user trusts the site, FALSE otherwise.
public function IGBRequireTrust()
{
if($_SERVER['HTTP_EVE_TRUSTED'] != 'yes')
{
echo "<script>CCPEVE.requestTrust('http://*.".$_SERVER['HTTP_HOST']."');</script>";
}
return true;
}
如果页面不接受该权限,则需要重定向回索引功能并设置会话闪存消息。我尝试在调用 IGBRequireTrust 函数的地方添加一个 else,但它似乎总是两者兼而有之。
更新:
AppController函数
公共函数 beforeFilter() { $this->Auth->allow('index', 'view');
if($this->name == 'Users' && $this->action == 'add'){
//die('correct controller and action');
if(isset($_SERVER['HTTP_EVE_TRUSTED'])){
if($_SERVER['HTTP_EVE_TRUSTED'] != 'yes' && $this->action != 'promptEveTrusted'){
$this->redirect(array('controller'=>'Users', 'action'=>'promptEveTrusted'));
}
} else {
$this->Session->setFlash(__('Registration is only allowed through the EVE in game browser.'));
$this->redirect(array('controller'=>'Users', 'action'=>'index'));
}
//} else {
// die('wrong controller and action');
}
}
【问题讨论】: