I am new to Icenium Everlive and I am attempting to block logins by users who are not verified. My login and registration currently works using code like this:
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');
}
})
}
However when attempting to determine if a user is verified I am kind of failing. I keep getting a 404 request from the server when I ask it for the user using the API suggestion of:
$.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));
}
})
Any suggestions would be greatly appreciated.
(1) Download and use the Everlive Javascript SDK:
https://www.everlive.com/AllApps/ManageApp/DownloadSDK
This wrapper will make things easier by forming and handling your AJAX requests.
(2) Then you can do something like this to login user and then check if verified:
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....
});
}