快速回答--是的!
我们刚刚完成了将一个能够实现这一功能的Android应用程序推向市场。以下是我们的操作步骤:
1)在Eclipse中下载并学习使用Cordova PhoneGap(2.2.0是最新版本)。这样,只需要一些HTML和大量的Javascript就可以轻松完成整个过程。
2)在您的JS中,创建推送登录信息的方法,使用AJAX参数。例如:
document.addEventListener('deviceready', onDeviceReady, false);
function onDeviceReady() {
$("#login").click(function() {
$email = $("#UserEmail").val();
$pass = $("#UserPassword").val();
$.ajax({
url : yourURL + 'api/users/login',
async : false,
data : {
'email' : $email,
'password' : $pass
},
dataType : 'json',
type : 'post',
success : function(result) {
window.location.href = "yourUrl.html";
return;
},
error : function(xhr, status, err) {
}
});
}
}
3) 在Cake/PHP中,你的用户控制器将接受AJAX调用中的用户名和密码数据,并将其用于认证。
<?php
class UsersController extends AppController {
public $name = 'Users';
public function beforeFilter() {
parent::beforeFilter();
$this->Auth->allow('api_login');
}
public function api_login() {
$this->autoRender = false;
if ($this->request->data && isset($this->request->data['email']) && isset($this->request->data['password'])) {
$arrUser = $this->User->find('all',array(
'conditions'=>array(
'email'=> $this->request->data['email'],
'password' => $this->Auth->password($this->request->data['password']),
)
)
);
if (count($arrUser) > 0) {
$this->Session->write('Auth.User',$arrUser[0]['User']);
$arrReturn['status'] = 'SUCCESS';
$arrReturn['data'] = array( 'loginSuccess' => 1,'user_id' => $arrUser[0]['User']['id'] );
} else {
$arrReturn['status'] = 'NOTLOGGEDIN';
$arrReturn['data'] = array( 'loginSuccess' => 0 );
}
} else {
$arrReturn['status'] = 'NOTLOGGEDIN';
$arrReturn['data'] = array( 'loginSuccess' => 0 );
}
echo json_encode($arrReturn);
}
}
?>
就是这些了。您现在已经通过CakePHP进行了身份验证。
您不需要使用“api_”,可以使用任何函数名称,但这有助于我们掌握允许移动用户执行的操作与 Web 用户的区别。
现在,这些只是基础构件。您基本上必须使用 HTML 和 Javascript 在手机上创建整个站点版本,因此,根据您的应用程序,更容易的方法可能只是创建响应式设计来允许移动浏览。
希望对您有所帮助!