A
A
Alexey Yarkov2016-04-16 22:55:11
Angular
Alexey Yarkov, 2016-04-16 22:55:11

How does uLogin callback use angular controller?

In my personal account, I make the function of linking a social account through uLogin. How to call a controller method in a callback? The design of the widget is custom.

<div id="uLogin" data-ulogin="display=buttons;callback=User.getTokenFromULogin">
    <img data-uloginbutton="vkontakte" class="social-account-icon" src="img/icons/vkontakte.png">
    <!-- Ещё иконки... -->
</div>

Here in the User controller there is a getTokenFromULogin method. If you specify any non-angular function, then data is transferred to it, but this does not work.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexey Yarkov, 2016-05-12
@yarkov

In general, somehow solved the problem like this:

/**
 * Принимаем токен авторизации Ulogin
 */
function getTokenFromULogin(token) {
  $.getJSON("//ulogin.ru/token.php?host=" + encodeURIComponent(window.location.toString()) + "&token=" + token + "&callback=?", function (data) {
    data = $.parseJSON(data.toString());
    if (!data.error) {
      // В <div ui-view="UserPage"></div> у меня загружается стэйт личного кабинета, поэтому получаем его scope
      var UserCtrl = angular.element('[ui-view="UserPage"]').scope();
      // UserCtrl.User - контроллер пользователя
      // AddSocialAccount - метод, который дергает метод фабрики, в котором на сервер уходят данные пользователя от uLogin
      UserCtrl.User.AddSocialAccount(data);
    }
  });
}

A
Alexander Taratin, 2016-04-16
@Taraflex

DO NOT USE ULOGIN OR ITS ANALOGUES!!!
https://habrahabr.ru/post/238117/
How do you think such services are monetized?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question