L
L
lsa4132015-11-09 12:25:47
PHP
lsa413, 2015-11-09 12:25:47

The general principle (algorithm) of authorization through social networks and sending comments, like hypercomments and cackle?

Hello!
I've been struggling for some time to figure out how best to implement a social media comment system. Unfortunately, having picked up a mess of knowledge in PHP and JavaScript, I have serious suspicions that the algorithm I have chosen leads nowhere :)
Therefore, I would like to ask an authoritative opinion on some specific points.
I'll make a reservation right away that I'm trying to implement JavaScript authorization and sending comments without reloading the page.
For now, I will limit myself to one question. For clarity, I will give an example using the Vkontakte JavaScript API:
1. When a user enters the site, the algorithm should check if he is already authorized through my Vkontakte application ( VK.Auth.getLoginStatus)? The problem is that before we have the opportunity to do such a check, the Vkontakte API must be initialized on the site, and asynchronously, so as not to interfere with the work of other scripts and the formation of the DOM tree. The only thing I've come up with so far is to put VK.Auth.getLoginStatus into this construct:

var intervalVKId = setInterval(
        function () {
            var vk_counter = $('#vk_counter').text();
            vk_counter++;
            $('#vk_counter').text(vk_counter);

            if (typeof VK === 'object') {
                VK.Auth.getLoginStatus(function(response) {
                    if (response.session) {
                        getVKUser(response.session.mid);
                        $('#vk').attr('status','login');
                    } else {
                        $('#vk').attr('status','logoff');
                    }
                    clearInterval(intervalVKId);
                });
            }

            if ($('#vk').attr('status') == 'logoff'
                || $('#vk').attr('status') == 'login'
                || $('#vk_counter').text() > 50) {
                setTimeout(function() {
                    clearInterval(intervalVKId);
                }, 100);
            }
        }, 100);

In short, I wait until VK becomes an object, and this will happen after asynchronous initialization of the Vkontakte API, after which I call the status check function VK.Auth.getLoginStatus . Well, then, depending on the response , either I mark the authorization button as logoff , or I pull out the user data through my getVKUser function, pulling the data through VK.Api.call . Moreover, if VK initialization fails, then after some time setInterval will be cut. This is implemented through a clumsy hidden div counter, which also annoys me.
There is a suspicion that in this case I hammer nails with a microscope and there are simpler and more elegant solutions. I would be grateful for advice and comments :)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
Puma Thailand, 2015-11-09
@opium

Do as in kakle, all the code is open in the same place

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question