Skip to content
This repository has been archived by the owner on Jul 21, 2020. It is now read-only.

Commit

Permalink
1.0.4
Browse files Browse the repository at this point in the history
  • Loading branch information
Nemanja Popovic committed May 13, 2016
1 parent 6a9a4b0 commit 074c6f5
Show file tree
Hide file tree
Showing 48 changed files with 786 additions and 209 deletions.
1 change: 0 additions & 1 deletion bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
"angular-cookie": "~4.0.2",
"angular-bootstrap": "~0.11.0",
"angular-xeditable": "~0.1.8",
"angular-directive.g-signin": "~0.1.2",
"angular-ui-select": "~0.13.2",
"angular-sanitize": "~1.3.0",
"angular-touch": "~1.3.0",
Expand Down
2 changes: 1 addition & 1 deletion config/karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ module.exports = function(config){
'public/js/vendor/angular-sanitize/angular-sanitize.js',
'public/js/vendor/angular-ui-select/dist/select.min.js',
'public/js/vendor/angular-ui-notification/dist/angular-ui-notification.min.js',
'public/js/vendor/angular-directive.g-signin/google-plus-signin.js',
'public/js/vendor/algoliasearch/dist/algoliasearch.angular.js',

// dummy config/bootstrap for testing
Expand Down Expand Up @@ -146,6 +145,7 @@ module.exports = function(config){
'public/js/app/auth/services/anon-auth-service.js',
'public/js/app/auth/services/auth-dialog-manager.js',
'public/js/app/auth/services/session-service.js',
'public/js/app/auth/services/google-provider.js',

'public/js/app/shared/router.js',
'public/js/app/shared/http-proxy.js',
Expand Down
Binary file modified public/img/g_signInLogo-mobile.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified public/img/g_signInLogo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@
<script src="js/app/products/directives/product-attribute-groups.js"></script>
<script src="js/app/products/directives/product-attribute-group.js"></script>
<script src="js/app/products/directives/product-attribute.js"></script>
<script src="js/app/products/directives/product-img-carousel.js"></script>
<script src="js/app/errors/controllers/errors-ctrl.js"></script>
<script src="js/app/cart/cart-index.js"></script>
<script src="js/app/cart/controllers/cart-ctrl.js"></script>
Expand Down Expand Up @@ -169,6 +170,7 @@
<script src="js/app/auth/controllers/password-reset-update-ctrl.js"></script>
<script src="js/app/auth/directives/confirm-input.js"></script>
<script src="js/app/auth/directives/create-account.js"></script>
<script src="js/app/auth/services/google-provider.js"></script>
<script src="js/app/auth/services/auth-rest.js"></script>
<script src="js/app/auth/services/token-service.js"></script>
<script src="js/app/auth/services/session-service.js"></script>
Expand Down
2 changes: 1 addition & 1 deletion public/js/app/account/controllers/account-ctrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ angular.module('ds.account')

// show more or less addresses.
$scope.showAddressDefault = 6;
$scope.showAddressButtons = ($scope.addresses.length >= $scope.showAddressDefault);
$scope.showAddressButtons = ($scope.addresses.length > $scope.showAddressDefault);
$scope.showAllAddressButton = true;
$scope.showAddressFilter = $scope.showAddressDefault;

Expand Down
10 changes: 10 additions & 0 deletions public/js/app/account/templates/addresses-dialog.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,14 @@ <h4 class="modal-title" id="myModalLabel">{{'ADDRESS_BOOK' | translate}}</h4>
<div class="row">
<div ng-include="'./js/app/account/templates/addresses.html'"></div>
</div>
<div class="text-center row" ng-show="showAllAddressButton">
<button class="btn btn-link" ng-show="!showAllAddresses" ng-click="toggleAddresses()">
{{'SHOW_ALL' | translate}}
<span class="glyphicon glyphicon-chevron-down"/>
</button>
<button class="btn btn-link" ng-show="showAllAddresses" ng-click="toggleAddresses()">
{{'SHOW_LESS' | translate}}
<span class="glyphicon glyphicon-chevron-up"/>
</button>
</div>
</div>
2 changes: 1 addition & 1 deletion public/js/app/auth/auth-index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@

'use strict';

angular.module('ds.auth', ['ipCookie','directive.g+signin']);
angular.module('ds.auth', ['ipCookie', 'ds.ygooglesignin']);
29 changes: 18 additions & 11 deletions public/js/app/auth/controllers/auth-modal-dialog-ctrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ angular.module('ds.auth')
* Controller for handling authentication related modal dialogs (signUp/signIn).
*/
.controller('AuthModalDialogCtrl', ['$rootScope', '$scope', 'AuthSvc',
'settings', 'AuthDialogManager', 'loginOpts', 'showAsGuest', '$state',
function ($rootScope, $scope, AuthSvc, settings, AuthDialogManager, loginOpts, showAsGuest, $state) {
'settings', 'AuthDialogManager', 'loginOpts', 'showAsGuest', '$state', 'YGoogleSignin', '$window',
function ($rootScope, $scope, AuthSvc, settings, AuthDialogManager, loginOpts, showAsGuest, $state, YGoogleSignin, $window) {

$scope.user = {
signup: {},
Expand All @@ -36,15 +36,10 @@ angular.module('ds.auth')
$scope.googleClientId = settings.googleClientId;
// determines "continue as guest" button:
$scope.showAsGuest = showAsGuest;
$scope.cookiesEnabled = $window.navigator.cookieEnabled;

AuthSvc.initFBAPI();

// react to event fired by goole+ signing directive
$scope.$on('event:google-plus-signin-success', function (event, authResult) {
if( authResult.status.method && authResult.status.method !== 'AUTO' ){
AuthSvc.onGoogleLogIn( authResult[settings.configKeys.googleResponseToken]);
}
});
AuthSvc.initGoogleAPI();

$scope.$on('authlogin:error', function(){
var response = { status: 0 };
Expand All @@ -60,8 +55,14 @@ angular.module('ds.auth')
$scope.signup = function (authModel, signUpForm) {
if (signUpForm.$valid) {
AuthSvc.signup(authModel, loginOpts).then(
function () {
$scope.closeDialog();
function (response) {
if (response.cookiesDisabled) {
$scope.showCreateAccountErrMsg = true;
$scope.user.signup.email = '';
$scope.user.signup.password = '';
} else {
$scope.closeDialog();
}
}, function (response) {
$scope.errors.signup = AuthSvc.extractServerSideErrors(response);
}
Expand Down Expand Up @@ -100,6 +101,12 @@ angular.module('ds.auth')
AuthSvc.faceBookLogin();
};

$scope.googleLogin = function () {
YGoogleSignin.login().then(function (user) {
AuthSvc.onGoogleLogIn(user);
});
};

var unbind = $rootScope.$on('user:socialLogIn', function(eve, obj){
if(obj.loggedIn){
$scope.closeDialog();
Expand Down
7 changes: 0 additions & 7 deletions public/js/app/auth/directives/create-account.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,6 @@ angular.module('ds.auth')
AuthSvc.faceBookLogin();
};

// react to event fired by goole+ signing directive
$scope.$on('event:google-plus-signin-success', function (event, authResult) {
if( authResult.status.method && authResult.status.method !== 'AUTO' ){
AuthSvc.onGoogleLogIn( authResult[settings.configKeys.googleResponseToken]);
}
});

}
};
}]);
71 changes: 45 additions & 26 deletions public/js/app/auth/services/auth-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
* Encapsulates access to the "authentication" service.
*/
angular.module('ds.auth')
.factory('AuthSvc', ['AuthREST', '$rootScope', 'settings', 'TokenSvc', 'GlobalData', 'appConfig', '$state', '$q', 'SessionSvc', '$window',
function (AuthREST, $rootScope, settings, TokenSvc, GlobalData, appConfig, $state, $q, SessionSvc, $window) {
.factory('AuthSvc', ['AuthREST', '$rootScope', 'settings', 'TokenSvc', 'GlobalData', 'appConfig', '$state', '$q', 'SessionSvc', '$window', 'YGoogleSignin',
function (AuthREST, $rootScope, settings, TokenSvc, GlobalData, appConfig, $state, $q, SessionSvc, $window, YGoogleSignin) {

function loginAndSetToken(user) {
return AuthREST.Customers.all('login').customPOST(user).then(function (response) {
Expand Down Expand Up @@ -117,34 +117,43 @@ angular.module('ds.auth')
},


onGoogleLogIn: function (gToken) {

AuthenticationService.socialLogin('google', gToken).then(function () {
onGoogleLogIn: function (user) {
AuthenticationService.socialLogin('google', user.token).then(function () {
$rootScope.$emit('user:socialLogIn', {loggedIn: true});
try {
window.gapi.client.load('plus', 'v1').then(function () {
window.gapi.client.plus.people.get({
'userId': 'me'
}).then(function (response) {
if (response.result) {
SessionSvc.afterSocialLogin({
email: response.result.emails[0].value,
firstName: response.result.name.givenName,
lastName: response.result.name.familyName
});
}

});
if (user.image) {
GlobalData.user.image = user.image;
}
SessionSvc.afterSocialLogin({
email: user.email,
firstName: user.firstname,
lastName: user.lastname
});
} catch (error) {
console.error('Unable to load Google+ user profile');
console.error('Unable to load Google user profile');
}
}, function () {
$rootScope.$emit('user:socialLogIn', {loggedIn: false});
});

},

initGoogleAPI: function () {
YGoogleSignin.loadData(settings.googleClientId);
},

isGoogleLoggedIn: function (customer) {
if (customer && customer.accounts) {
for (var i = 0; i < customer.accounts.length; i++) {
if (customer.accounts[i].providerId === 'google') {
return true;
}
return false;
}
}
return false;
},

fbParse: function () {
if (typeof FB !== 'undefined') {
FB.XFBML.parse();
Expand Down Expand Up @@ -183,13 +192,18 @@ angular.module('ds.auth')
signup: function (user, context) {
var def = $q.defer();
AuthREST.Customers.all('signup').customPOST(user).then(function () {
loginAndSetToken(user).then(function () {
settings.hybrisUser = user.email;
def.resolve({});
SessionSvc.afterLoginFromSignUp(context);
}, function (error) {
def.reject(error);
});
if ($window.navigator.cookieEnabled) {
loginAndSetToken(user).then(function () {
settings.hybrisUser = user.email;
def.resolve({});
SessionSvc.afterLoginFromSignUp(context);
}, function (error) {
def.reject(error);
});
} else {
def.resolve({cookiesDisabled: true});
}

}, function (error) {
def.reject(error);
});
Expand All @@ -198,6 +212,11 @@ angular.module('ds.auth')

/** Logs the customer out and removes the token cookie. */
signOut: function () {
if (GlobalData.customerAccount.accounts[0].providerId === 'google') {
YGoogleSignin.logout().then(function () {
GlobalData.user.image = settings.avatarImagePlaceholder;
});
}
AuthREST.Customers.all('logout').customGET('', {accessToken: TokenSvc.getToken().getAccessToken()});
// unset token after logout - new anonymous token will be generated for next request automatically
TokenSvc.unsetToken(settings.accessCookie);
Expand Down
131 changes: 131 additions & 0 deletions public/js/app/auth/services/google-provider.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
/**
* [y] hybris Platform
*
* Copyright (c) 2000-2016 hybris AG
* All rights reserved.
*
* This software is the confidential and proprietary information of hybris
* ("Confidential Information"). You shall not disclose such Confidential
* Information and shall use it only in accordance with the terms of the
* license agreement you entered into with hybris.
*/

'use strict';

angular.module('ds.ygooglesignin', [])
.provider('YGoogleSignin', [ function() {

this.$get = ['$q', function($q) {

var GoogleObject = function() {};
var user;
var url = 'https://apis.google.com/js/client:platform.js?onload=onLoad';

function isScriptExist () {
var scripts = document.getElementsByTagName('script');
for (var i = 0; i < scripts.length; i++) {
if (scripts[i].src === url) {
return true;
}
}
return false;
}

GoogleObject.prototype.loadData = function (googleClientId) {
var deferred = $q.defer();
if (!isScriptExist()) {
var meta = document.createElement('meta');
meta.name = 'google-signin-scope';
meta.content = 'profile email';
document.getElementsByTagName('head')[0].appendChild(meta);

meta.name = 'google-signin-client_id';
meta.content = googleClientId;
document.getElementsByTagName('head')[0].appendChild(meta);

var params = {
/* jshint ignore:start */
client_id: googleClientId,
cookie_policy: 'single_host_origin'
/* jshint ignore:end */
};

var s, r, t;
r = false;
s = document.createElement('script');
s.type = 'text/javascript';
s.src = url;
t = document.getElementsByTagName('script')[0];
t.parentNode.insertBefore(s, t);
s.onload = s.onreadystatechange = function() {
if (!r && (!this.readyState || this.readyState === 'complete')) {
r = true;
window.gapi.load('auth2', function() {
window.gapi.auth2.init(params).then(function () {
deferred.resolve();
});
});
}
};
}

return deferred.promise;
};

GoogleObject.prototype.getUser = function (googleClientId) {
var deferred = $q.defer();
this.loadData(googleClientId).then(function () {
var auth2 = window.gapi.auth2.getAuthInstance();
if (auth2.isSignedIn.get()) {
var profile = auth2.currentUser.get().getBasicProfile();
user = {
firstName: profile.Za,
lastName: profile.Na,
email: profile.hg,
image: profile.Ph,
};
} else {
user = {};
}
deferred.resolve(user);
});
return deferred.promise;
};

GoogleObject.prototype.login = function () {
var params = {
scope: 'profile email'
};
var deferred = $q.defer();
window.gapi.load('auth2', function() {
var auth2 = window.gapi.auth2.getAuthInstance();
auth2.signIn(params).then(function (response) {
user = {
firstname: response.wc.Za,
lastname: response.wc.Na,
email: response.wc.hg,
image: response.wc.Ph,
/* jshint ignore:start */
token: response.hg.access_token
/* jshint ignore:end */
};
deferred.resolve(user);
});
});
return deferred.promise;
};

GoogleObject.prototype.logout = function () {
var deferred = $q.defer();
var auth2 = window.gapi.auth2.getAuthInstance();
auth2.signOut().then(function () {
deferred.resolve();
});
return deferred.promise;
};

return new GoogleObject();

} ];

}]);
Loading

0 comments on commit 074c6f5

Please sign in to comment.