Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <script>
- let user_logged = {};
- function onSuccess(googleUser) {
- console.log('Logged in as: ' + googleUser.getBasicProfile().getName());
- }
- function onFailure(error) {
- console.log(error);
- }
- function signOut() {
- if(auth2.signOut){
- auth2.signOut();
- }
- if(auth2.disconnect){
- auth2.disconnect();
- }
- }
- function userChanged(user){
- user_logged = user;
- // ak je prihlaseny user
- if(auth2.isSignedIn.get()){
- $('.loggin_header').text(`Aktuálne je prihlásený používateľ : ${auth2.currentUser.get().getBasicProfile().getName()}`);
- // auth2.isSignedIn.get()
- $("#my-signin2").hide();
- $(".logout_button").show();
- $(".login_button").hide();
- $(".user_info").text(auth2.currentUser.get().getBasicProfile().getName());
- } else {
- $('.loggin_header').text("Prosím prihláste sa!");
- $("#my-signin2").show();
- $(".logout_button").hide();
- $(".login_button").show();
- $(".user_info").text("");
- }
- }
- let auth2 = {};
- function renderButton() {
- gapi.load('auth2', function() {
- gapi.signin2.render('my-signin2', {
- 'scope': 'profile email',
- 'width': 240,
- 'height': 50,
- 'longtitle': true,
- 'theme': 'dark',
- 'onsuccess': onSuccess,
- 'onfailure': onFailure
- });
- gapi.auth2.init().then( //zavolat po inicializácii OAuth 2.0 (called after OAuth 2.0 initialisation)
- function (){
- auth2 = gapi.auth2.getAuthInstance();
- auth2.currentUser.listen(userChanged);
- auth2.isSignedIn.listen(userChanged);
- auth2.then(userChanged); //tiez po inicializacii (later after initialisation)
- });
- });
- }
- let logout = () => {
- };
- </script>
- <script src="https://apis.google.com/js/platform.js?onload=renderButton" async defer></script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement