Created
December 25, 2016 23:57
-
-
Save taufiksu/9c28d23f068206e1c5c6530e9e7874c8 to your computer and use it in GitHub Desktop.
Javascript helper for web development
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Get Browser Info | |
function browserId() { | |
var navigator_info = window.navigator; | |
var screen_info = window.screen; | |
var uid = navigator_info.mimeTypes.length; | |
uid += navigator_info.userAgent.replace(/\D+/g, ''); | |
uid += navigator_info.plugins.length; | |
uid += screen_info.height || ''; | |
uid += screen_info.width || ''; | |
uid += screen_info.pixelDepth || ''; | |
return uid; | |
} | |
// Get Login Status Using IP and Browser ID | |
function loginCheck() { | |
$.ajax({ | |
url: 'https://api.ipify.org?format=json', | |
dataType: 'json', | |
success: function (data) { | |
var user_login = { | |
"async": true, | |
"crossDomain": true, | |
"url": "http://io.nowdb.net/v2/select_where" + | |
"/token/" + token + | |
"/project/" + project + | |
"/collection/user_login" + | |
"/appid/" + appid + | |
"/where_field/device_idANDip" + | |
"/where_value/" + browserId() + "AND" + data.ip, | |
"method": "GET", | |
"headers": { | |
"cache-control": "no-cache" | |
} | |
} | |
$.ajax(user_login).done(function (response) { | |
if (response.length == 0) { | |
$(location).attr('href', 'home_login.html'); | |
} | |
}); | |
} | |
}); | |
} | |
// Get User Info | |
function getUserInfo() { | |
var datas; | |
$.ajax({ | |
"async": false, | |
url: 'https://api.ipify.org?format=json', | |
dataType: 'json', | |
success: function (data) { | |
var user_info = { | |
"async": false, | |
"crossDomain": true, | |
"url": "http://io.nowdb.net/v2/select_where" + | |
"/token/" + token + | |
"/project/" + project + | |
"/collection/user_login" + | |
"/appid/" + appid + | |
"/where_field/device_idANDip" + | |
"/where_value/" + browserId() + "AND" + data.ip, | |
"method": "GET", | |
"headers": { | |
"cache-control": "no-cache" | |
} | |
} | |
datas = $.ajax(user_info); | |
} | |
}); | |
return datas.responseJSON[0]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment