我是Icenium Everlive的新用户,我试图阻止未经验证的用户登录。我的登录和注册目前使用如下代码:
function login() {
var user = {
"username": username.value,
"password": password.value,
"grant_type": "password"
};
$.ajax({
type: "POST",
url: 'https://api.everlive.com/v1/apikey/oauth/token',
contentType: "application/json",
data: JSON.stringify(user),
success: function(data) {
console.log(JSON.stringify(data));
verifyUser()
},
error: function(error) {
console.log(JSON.stringify(error));
alert('Invalid Username or Password');
}
})
}
然而,当试图确定用户是否被验证时,我有点失败。当我向用户询问使用API建议:
时,我不断收到来自服务器的404请求 $.ajax({
url: 'https://api.everlive.com/v1/APIKEY/Users/me',
type: "GET",
headers: {"Authorization" : "Bearer ${AccessToken}"},
success: function(data) {
alert(JSON.stringify(data));
},
error: function(error) {
alert(JSON.stringify(error));
}
})
任何建议都将不胜感激。
答案 0 :(得分:2)
(1)下载并使用Everlive Javascript SDK:
https://www.everlive.com/AllApps/ManageApp/DownloadSDK
这个包装器可以通过形成和处理你的AJAX请求来简化操作。
(2)然后你可以做这样的事情登录用户,然后检查是否验证:
function login(){
var applicationSettings =
{emptyGuid: '00000000-0000-0000-0000-000000000000',
apiKey: 'xxxxxxxxxxxxxxxxxxxxx'};
//initialize everlive
var _everlive = new Everlive({apiKey: applicationSettings.apiKey});
var currentUser = kendo.observable({ data: null });
//once instantiated, you can also use "Everlive.$" which
//refs 1st created Everlive instance i.e.: Everlive.$.Users.login(...)
_everlive.Users.login(username.value,password.value).then(function(){
return _everlive.Users.currentUser();
})
.then(function(data){
var currentUserData = data.result;
currentUser.set('data', currentUserData);
})
.then(function(){
alert(currentUser.get("data.IsVerified"));
},function(err){
//handle error....
});
}