Commit bf74e196a8c1b8a940ab8e3d369f3c0932b1123a

Authored by Leonardo Merlin
1 parent 39198b54

Prepare to oauth

gulp/scripts.js
@@ -9,9 +9,9 @@ var browserSync = require('browser-sync'); @@ -9,9 +9,9 @@ var browserSync = require('browser-sync');
9 var $ = require('gulp-load-plugins')(); 9 var $ = require('gulp-load-plugins')();
10 10
11 gulp.task('scripts', function () { 11 gulp.task('scripts', function () {
12 - return gulp.src(path.join(conf.paths.src, '/app/**/*.js'))  
13 - .pipe($.jshint())  
14 - .pipe($.jshint.reporter('jshint-stylish'))  
15 - .pipe(browserSync.reload({ stream: true }))  
16 - .pipe($.size()); 12 + return gulp.src(path.join(conf.paths.src, '/app/**/*.js'))
  13 + .pipe($.jshint())
  14 + .pipe($.jshint.reporter('jshint-stylish'))
  15 + .pipe(browserSync.reload({ stream: true }))
  16 + .pipe($.size());
17 }); 17 });
src/app/index.run.js
@@ -5,6 +5,7 @@ @@ -5,6 +5,7 @@
5 angular 5 angular
6 .module('dialoga') 6 .module('dialoga')
7 .run(runAuth) 7 .run(runAuth)
  8 + .run(runSocialAuth)
8 .run(runAccessibility) 9 .run(runAccessibility)
9 .run(runHistory) 10 .run(runHistory)
10 .run(runPath) 11 .run(runPath)
@@ -44,6 +45,38 @@ @@ -44,6 +45,38 @@
44 } 45 }
45 46
46 /** @ngInject */ 47 /** @ngInject */
  48 + function runSocialAuth($window, $rootScope, $interval, $log) {
  49 +
  50 + $window.oauthClientAction = function (url){
  51 + var child = $window.open(url, '_blank');
  52 + var interval = $interval(function() {
  53 + try {
  54 + if(!child.closed) {
  55 + child.postMessage({
  56 + message: 'requestOauthClientPluginResult'
  57 + }, '*');
  58 + }
  59 + } catch(e) {
  60 + // we're here when the child window has been navigated away or closed
  61 + if (child.closed) {
  62 + $interval.cancel(interval);
  63 + interval = undefined;
  64 + }
  65 + }
  66 + }, 300);
  67 + };
  68 +
  69 + $window.addEventListener('message', function(eventMessage) {
  70 + $log.debug('eventMessage', eventMessage);
  71 +
  72 + if (eventMessage.data.message === 'oauthClientPluginResult') {
  73 + $rootScope.$broadcast('oauthClientPluginResult', eventMessage);
  74 + // eventMessage.source.close();
  75 + }
  76 + });
  77 + }
  78 +
  79 + /** @ngInject */
47 function runAccessibility($rootScope, $timeout, $cookies, $log) { 80 function runAccessibility($rootScope, $timeout, $cookies, $log) {
48 81
49 var contrast = $cookies.get('dialoga_contraste') === 'true'; 82 var contrast = $cookies.get('dialoga_contraste') === 'true';
src/app/pages/auth/auth.controller.js
@@ -6,11 +6,12 @@ @@ -6,11 +6,12 @@
6 .controller('AuthPageController', AuthPageController); 6 .controller('AuthPageController', AuthPageController);
7 7
8 /** @ngInject */ 8 /** @ngInject */
9 - function AuthPageController($scope, $rootScope, $location, $state, $timeout, AUTH_EVENTS, AuthService, DialogaService, Session, $log) { 9 + function AuthPageController($scope, $rootScope, $window, $location, $state, $timeout, AUTH_EVENTS, AuthService, DialogaService, Session, $log) {
10 var vm = this; 10 var vm = this;
11 11
12 vm.$scope = $scope; 12 vm.$scope = $scope;
13 vm.$rootScope = $rootScope; 13 vm.$rootScope = $rootScope;
  14 + vm.$window = $window;
14 vm.$location = $location; 15 vm.$location = $location;
15 vm.$state = $state; 16 vm.$state = $state;
16 vm.$timeout = $timeout; 17 vm.$timeout = $timeout;
@@ -22,6 +23,7 @@ @@ -22,6 +23,7 @@
22 23
23 vm.init(); 24 vm.init();
24 vm.loadData(); 25 vm.loadData();
  26 + vm.attachListeners();
25 27
26 vm.$log.debug('AuthPageController'); 28 vm.$log.debug('AuthPageController');
27 } 29 }
@@ -73,6 +75,18 @@ @@ -73,6 +75,18 @@
73 }); 75 });
74 }; 76 };
75 77
  78 + AuthPageController.prototype.attachListeners = function () {
  79 + var vm = this;
  80 +
  81 + vm.$scope.$on('oauthClientPluginResult', function(event, response){
  82 + vm.$log.debug('response', response);
  83 +
  84 + // var logged_id = response.data.logged_id;
  85 + // var private_token = response.data.private_token;
  86 + // var user = response.data.user;
  87 +
  88 + });
  89 + };
76 90
77 AuthPageController.prototype.onClickLogout = function (){ 91 AuthPageController.prototype.onClickLogout = function (){
78 var vm = this; 92 var vm = this;
@@ -154,4 +168,17 @@ @@ -154,4 +168,17 @@
154 } 168 }
155 }, vm.delay * 1000); 169 }, vm.delay * 1000);
156 }; 170 };
  171 +
  172 + AuthPageController.prototype.authWithFacebook = function(){
  173 + var vm = this;
  174 + var url = 'http://login.dialoga.gov.br/plugin/oauth_client/facebook?oauth_client_popup=true&id=1';
  175 + vm.$window.oauthClientAction(url);
  176 + };
  177 +
  178 + AuthPageController.prototype.authWithGooglePlus = function(){
  179 + var vm = this;
  180 +
  181 + var url = 'http://login.dialoga.gov.br/plugin/oauth_client/google_oauth2?oauth_client_popup=true&id=4';
  182 + vm.$window.oauthClientAction(url);
  183 + };
157 })(); 184 })();
src/app/pages/auth/signin.html
@@ -54,7 +54,7 @@ @@ -54,7 +54,7 @@
54 </div> 54 </div>
55 <div class="row"> 55 <div class="row">
56 <div class="col-xs-6"> 56 <div class="col-xs-6">
57 - <button type="button" class="btn btn-lg btn-block btn-social btn-facebook"> 57 + <button type="button" ng-click="pageSignin.authWithFacebook()" class="btn btn-lg btn-block btn-social btn-facebook">
58 <span aria-hidden="true" class="icon-circle icon-small icon-circle-social-facebook"> 58 <span aria-hidden="true" class="icon-circle icon-small icon-circle-social-facebook">
59 <span class="icon icon-social-facebook"></span> 59 <span class="icon icon-social-facebook"></span>
60 </span> 60 </span>
@@ -62,7 +62,7 @@ @@ -62,7 +62,7 @@
62 </button> 62 </button>
63 </div> 63 </div>
64 <div class="col-xs-6"> 64 <div class="col-xs-6">
65 - <button type="button" class="btn btn-lg btn-block btn-social btn-google-plus"> 65 + <button type="button" ng-click="pageSignin.authWithGooglePlus()" class="btn btn-lg btn-block btn-social btn-google-plus">
66 <span aria-hidden="true" class="icon-circle icon-small icon-circle-social-googleplus"> 66 <span aria-hidden="true" class="icon-circle icon-small icon-circle-social-googleplus">
67 <span class="icon icon-social-googleplus"></span> 67 <span class="icon icon-social-googleplus"></span>
68 </span> 68 </span>
@@ -84,7 +84,7 @@ @@ -84,7 +84,7 @@
84 </div> 84 </div>
85 <div class="row"> 85 <div class="row">
86 <div class="col-xs-6"> 86 <div class="col-xs-6">
87 - <button type="button" class="btn btn-lg btn-block btn-social btn-facebook"> 87 + <button type="button" ng-click="pageSignin.authWithFacebook()" class="btn btn-lg btn-block btn-social btn-facebook">
88 <span aria-hidden="true" class="icon-circle icon-small icon-circle-social-facebook"> 88 <span aria-hidden="true" class="icon-circle icon-small icon-circle-social-facebook">
89 <span class="icon icon-social-facebook"></span> 89 <span class="icon icon-social-facebook"></span>
90 </span> 90 </span>
@@ -92,7 +92,7 @@ @@ -92,7 +92,7 @@
92 </button> 92 </button>
93 </div> 93 </div>
94 <div class="col-xs-6"> 94 <div class="col-xs-6">
95 - <button type="button" class="btn btn-lg btn-block btn-social btn-google-plus"> 95 + <button type="button" ng-click="pageSignin.authWithGooglePlus()" class="btn btn-lg btn-block btn-social btn-google-plus">
96 <span aria-hidden="true" class="icon-circle icon-small icon-circle-social-googleplus"> 96 <span aria-hidden="true" class="icon-circle icon-small icon-circle-social-googleplus">
97 <span class="icon icon-social-googleplus"></span> 97 <span class="icon icon-social-googleplus"></span>
98 </span> 98 </span>