Guest User

Untitled

a guest
Dec 16th, 2018
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.94 KB | None | 0 0
  1. // User is signed in.
  2. userId=user.uid;
  3. //alert(userId);
  4. var date = new Date();
  5. var n = date.toDateString();
  6. var time = date.toLocaleTimeString();
  7. datetime=n+" "+time;
  8. snapcity="";
  9. check(userId,snapcity); //data retrieval function
  10. var database = firebase.database();
  11. writeUserData(userId,ajaxData.geoplugin_request,ajaxData.geoplugin_city,datetime);
  12. document.getElementById("user_div").style.display = "block";
  13. document.getElementById("login_div").style.display = "none";
  14.  
  15. var user = firebase.auth().currentUser;
  16.  
  17. if(user != null){
  18.  
  19. var email_id = user.email;
  20. document.getElementById("user_para").innerHTML = "Welcome User : " + email_id;
  21. console.log('data');
  22. console.log(ajaxData);
  23. html="<p>ip: "+ajaxData.geoplugin_request+"</p><p>Country Code: +44</p><p>Country: "+ajaxData.geoplugin_countryName+"</p><p>Country Abbrevation: "+ajaxData.geoplugin_countryCode+"</p><p>Region Code: "+ajaxData.geoplugin_regionCode+"</p><p>Region Name: "+ajaxData.geoplugin_regionName+"</p><p>City: "+ajaxData.geoplugin_city+"</p><p>Time Zone: "+ajaxData.geoplugin_timezone+"</p><p>Latitude: "+ajaxData.geoplugin_latitude+"</p><p>Longitude: "+ajaxData.geoplugin_longitude+"</p><p>Last Login: "+datetime+"</p>";
  24. $('#data').html(html);
  25.  
  26. }
  27.  
  28. } else {
  29. // No user is signed in.
  30.  
  31. document.getElementById("user_div").style.display = "none";
  32. document.getElementById("login_div").style.display = "block";
  33.  
  34. }
  35. });
  36.  
  37. function check(userId,snapcity){
  38. var rootRef=firebase.database().ref().child('users');
  39. rootRef.on('child_added', function(snap){
  40. if(snap.child("userId").val()==userId){
  41.  
  42. snapcity=snap.child("city").val();
  43. }
  44. });
  45. console.log(snapcity);
  46. console.log(ajaxData.geoplugin_city);
  47. if(snapcity){
  48. if(snapcity!=ajaxData.geoplugin_city){
  49. logout();
  50. alert("you can't login because previously you were logged from "+snapcity );
  51.  
  52. }
  53. }
  54. }
Add Comment
Please, Sign In to add comment