Advertisement
kknndd_

Untitled

May 8th, 2021
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.65 KB | None | 0 0
  1. <script>
  2.  
  3. let user_logged = {};
  4.  
  5. function onSuccess(googleUser) {
  6. console.log('Logged in as: ' + googleUser.getBasicProfile().getName());
  7. }
  8. function onFailure(error) {
  9. console.log(error);
  10. }
  11.  
  12. function signOut() {
  13. if(auth2.signOut){
  14. auth2.signOut();
  15. }
  16. if(auth2.disconnect){
  17. auth2.disconnect();
  18. }
  19. }
  20.  
  21. function userChanged(user){
  22.  
  23. user_logged = user;
  24.  
  25. // ak je prihlaseny user
  26. if(auth2.isSignedIn.get()){
  27. $('.loggin_header').text(`Aktuálne je prihlásený používateľ : ${auth2.currentUser.get().getBasicProfile().getName()}`);
  28. // auth2.isSignedIn.get()
  29. $("#my-signin2").hide();
  30. $(".logout_button").show();
  31. $(".login_button").hide();
  32. $(".user_info").text(auth2.currentUser.get().getBasicProfile().getName());
  33. } else {
  34. $('.loggin_header').text("Prosím prihláste sa!");
  35. $("#my-signin2").show();
  36. $(".logout_button").hide();
  37. $(".login_button").show();
  38. $(".user_info").text("");
  39. }
  40.  
  41.  
  42. }
  43.  
  44. let auth2 = {};
  45.  
  46. function renderButton() {
  47. gapi.load('auth2', function() {
  48. gapi.signin2.render('my-signin2', {
  49. 'scope': 'profile email',
  50. 'width': 240,
  51. 'height': 50,
  52. 'longtitle': true,
  53. 'theme': 'dark',
  54. 'onsuccess': onSuccess,
  55. 'onfailure': onFailure
  56. });
  57. gapi.auth2.init().then( //zavolat po inicializácii OAuth 2.0 (called after OAuth 2.0 initialisation)
  58. function (){
  59. auth2 = gapi.auth2.getAuthInstance();
  60. auth2.currentUser.listen(userChanged);
  61. auth2.isSignedIn.listen(userChanged);
  62. auth2.then(userChanged); //tiez po inicializacii (later after initialisation)
  63. });
  64. });
  65. }
  66.  
  67. let logout = () => {
  68.  
  69.  
  70.  
  71. };
  72. </script>
  73.  
  74. <script src="https://apis.google.com/js/platform.js?onload=renderButton" async defer></script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement