我有一个使用 jQuery Mobile 和 PHP(CodeIgniter 框架)构建的 Web 应用程序。现在我正在尝试制作它的 PhoneGap 版本,以使其可以作为独立应用程序进行分发。但是,PHP Web 应用程序。版本使用 Ion Auth,一个 CodeIgniter 插件进行身份验证。因此,当您转到需要身份验证的页面时,应用程序会将您重定向到身份验证控制器登录方法。身份验证后,它会将您重定向回主页(本例中为 jQuery Mobile 页面)。这在网络应用程序中工作得很好,因为主页首先是由家庭控制器打开的。
但关键在于:在PhoneGap版本中,“主页”页面需要是PhoneGap中的index.html文件。显然,您可以通过在 PhoneGap.plist 中添加值来在启动时加载另一个 url,但这对于提交到应用程序商店来说是苹果不可接受的。如果我在身份验证中进行重定向,则身份验证后我无法返回到 index.html 文件...
那么,应该如何在 PhoneGap/jQuery Mobile 应用程序中进行身份验证呢?
UPDATE:
我已经根据答案之一尝试过此操作,但当我只想通过帖子登录并从方法返回一个值时,应用程序仍然尝试导航到帐户/登录页面(该页面不存在):
$('#login_form').bind('submit', function () {
event.preventDefault();
//send a post request to your web-service
$.post('http://localhost/app_xcode/account/login', $(this).serialize(), function (response) {
//parse the response string into an object
var response = response;
//check if the authorization was successful or not
if (response == true) {
$.mobile.changePage('#toc', "slide");
} else {
alert('login failed');
$.mobile.changePage('#toc', "slide");
}
});
});
这是控制器方法:
function login()
{
//validate form input
$this->form_validation->set_rules('identity', 'Identity', 'required');
$this->form_validation->set_rules('password', 'Password', 'required');
$base_url = $this->config->item('base_url');
$mobile = $this->detect_mobile();
if ($mobile === false && $base_url != 'http://localhost/app_xcode/') //Only restrict if not developing
redirect('account/notAMobile');
else if ($this->form_validation->run() == true) { //check to see if the user is logging in
//check for "remember me"
$remember = (bool)$this->input->post('remember');
if ($this->ion_auth->login($this->input->post('identity'), $this->input->post('password'), $remember)) { //if the login is successful
//redirect them back to the home page
$this->session->set_flashdata('message', $this->ion_auth->messages());
echo true;
/*redirect($this->config->item('base_url'), 'refresh');*/
}
else
{ //if the login was un-successful
//redirect them back to the login page
$this->session->set_flashdata('message', $this->ion_auth->errors());
/*redirect('account/login', 'refresh');*/ //use redirects instead of loading views for compatibility with MY_Controller libraries
}
}
else
{ //the user is not logging in so display the login page
//set the flash data error message if there is one
$this->data['message'] = (validation_errors()) ? validation_errors()
: $this->session->flashdata('message');
$this->data['identity'] = array('name' => 'identity',
'id' => 'identity',
'type' => 'text',
'value' => $this->form_validation->set_value('identity'),
);
$this->data['password'] = array('name' => 'password',
'id' => 'password',
'type' => 'password',
);
}
}
我想我已经删除或注释掉了那里的任何重定向。所以我不知道为什么它仍然尝试加载视图?这是否与 jQuery Mobile 尝试导航到那里有关,因为我发布到该 URL?