0878 56 87 83 - ЦВС ЕООД Обратно в магазина

Вход за клиенти

', pluginRoot: '/plugins/GoogleLogin', afterLoginUrl: '/welcome.html', lang: { or: 'Или', loginWithG: 'Вход с Google', registerError: 'Грешка при регистрацията' }, init: function () { this.addOrSignature(); this.addButton(); }, mapData: function (data) { return { gId: data.accountId, gEmail: data.email, gLastName: data.nameLast, gName: data.name }; }, addOrSignature: function () { let or_marker = $('#loginFrm .btn-holder'), or_sign = $('#gs-or-sign'), or_root = '
' + googleLogin.lang.or + '
'; if (!or_sign.length){ or_marker.append(or_root); } }, addButton: function () { $('#loginFrm .btn-holder').after(`
`) }, parseJwt: function (token) { let base64Url = token.split('.')[1], base64 = base64Url.replace(/-/g, '+').replace(/_/g, '/'), jsonPayload = decodeURIComponent(atob(base64).split('').map(function(c) { return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2); }).join('')); return JSON.parse(jsonPayload); }, create: function (data) { let promise = new $.Deferred(); $.ajax({ url: googleLogin.pluginRoot + '/axCreate', method: 'post', data: data, headers: { "x-csrf-token": '00iO4LH3egycNsUuJaBcuPn2AKATsceEeHHaloLO6Lo' }, dataType: 'json' }).then(function(resp) { if(resp.Errors) { promise.reject(resp.Errors); } else { promise.resolve(); } }).fail(function(xhr, resp) { promise.reject([googleLogin.lang.registerError]); }); return promise.promise(); }, saveData: function(user) { let profile = googleLogin.parseJwt(user.credential); if(profile.email) { googleLogin.data.accountId = profile.sub; googleLogin.data.name = profile.given_name; googleLogin.data.nameLast = profile.family_name; googleLogin.data.email = profile.email; googleLogin.connect(); } }, createAccount: function () { googleLogin.create(googleLogin.mapData(googleLogin.data)).then(googleLogin.reload).fail(googleLogin.showErrors); }, connect: function(e) { if(e) e.preventDefault(); googleLogin.createAccount(); }, reload: function() { location.href = googleLogin.afterLoginUrl; }, showErrors: function (errors) { console.log(errors) }, } googleLogin.init(); function getData(user){ googleLogin.saveData(user); }