|
|
|
@ -1,7 +1,24 @@
|
|
|
|
|
define(['angular', 'uiRouter', 'uiBootstrap'], function (angular) {
|
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
|
|
function getQueryVariable(variable) {
|
|
|
|
|
var query = window.location.search.substring(1);
|
|
|
|
|
var vars = query.split("&");
|
|
|
|
|
for (var i = 0; i < vars.length; i++) {
|
|
|
|
|
var pair = vars[i].split("=");
|
|
|
|
|
if (pair[0] == variable) {
|
|
|
|
|
return pair[1];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var module = angular.module('shopify.auth', ['ui.router', 'ui.bootstrap', 'ngMessages']);
|
|
|
|
|
module.config(['$stateProvider', function ($stateProvider) {
|
|
|
|
|
module.config(['$stateProvider', '$locationProvider', function ($stateProvider, $locationProvider) {
|
|
|
|
|
$locationProvider.html5Mode({
|
|
|
|
|
enabled: false,
|
|
|
|
|
requireBase: false
|
|
|
|
|
});
|
|
|
|
|
$stateProvider.state('shopify', {
|
|
|
|
|
url: '/shopify',
|
|
|
|
|
templateUrl: '/static/shopify/auth/templates/auth_root.html',
|
|
|
|
@ -13,19 +30,19 @@ define(['angular', 'uiRouter', 'uiBootstrap'], function (angular) {
|
|
|
|
|
}).state('shopify.login', {
|
|
|
|
|
url: '/login',
|
|
|
|
|
templateUrl: '/static/shopify/auth/templates/shopify_login.html',
|
|
|
|
|
params: {'userId': null},
|
|
|
|
|
params: {'shop': null, 'code': null},
|
|
|
|
|
controller: 'ShopifyLoginController'
|
|
|
|
|
}).state('shopify.register', {
|
|
|
|
|
url: '/register',
|
|
|
|
|
templateUrl: '/static/shopify/auth/templates/shopify_register.html',
|
|
|
|
|
params: {'userId': null},
|
|
|
|
|
params: {'shop': null, 'code': null},
|
|
|
|
|
controller: 'ShopifyRegisterController'
|
|
|
|
|
});
|
|
|
|
|
}]);
|
|
|
|
|
|
|
|
|
|
module.controller('ShopifyRootController', ['$scope', '$http', '$state', function ($scope, $http, $state) {
|
|
|
|
|
if ($state.is('shopify')) {
|
|
|
|
|
$state.go('shopify.auth')
|
|
|
|
|
$state.go('shopify.login')
|
|
|
|
|
}
|
|
|
|
|
}])
|
|
|
|
|
|
|
|
|
@ -43,36 +60,37 @@ define(['angular', 'uiRouter', 'uiBootstrap'], function (angular) {
|
|
|
|
|
} else {
|
|
|
|
|
$state.go('shopify.register', {partnerCode: that.store.partnerCode});
|
|
|
|
|
}
|
|
|
|
|
},function (error) {
|
|
|
|
|
}, function (error) {
|
|
|
|
|
that.resError = error.data.message;
|
|
|
|
|
that.authDisable = false
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
that.registerMerchant = function () {
|
|
|
|
|
$state.go('shopify.register');
|
|
|
|
|
}
|
|
|
|
|
}]);
|
|
|
|
|
|
|
|
|
|
module.controller('ShopifyLoginController', ['$scope', '$http', '$stateParams', function ($scope, $http, $stateParams) {
|
|
|
|
|
module.controller('ShopifyLoginController', ['$scope', '$http', '$state', '$stateParams', '$location', function ($scope, $http, $state, $stateParams, $location) {
|
|
|
|
|
var that = $scope;
|
|
|
|
|
that.model = {
|
|
|
|
|
shop: '',
|
|
|
|
|
partnerCode: $stateParams.partnerCode,
|
|
|
|
|
shop: getQueryVariable("shop"),
|
|
|
|
|
loginId: '',
|
|
|
|
|
password: ''
|
|
|
|
|
password: '',
|
|
|
|
|
code: getQueryVariable("code")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
that.loginDisable = false
|
|
|
|
|
that.activeShopifyMerchant = function () {
|
|
|
|
|
that.loginDisable = true
|
|
|
|
|
$http.post("/shopify/auth/permission", that.model).then(function (res) {
|
|
|
|
|
console.log("permissionUrl", res.data.url)
|
|
|
|
|
location.href = res.data.url
|
|
|
|
|
},function (error) {
|
|
|
|
|
$http.post("/shopify/auth/install", that.model).then(function (res) {
|
|
|
|
|
console.log("redirectUrl", res.data.redirectUrl)
|
|
|
|
|
location.href = res.data.redirectUrl
|
|
|
|
|
}, function (error) {
|
|
|
|
|
that.resError = error.data.message;
|
|
|
|
|
that.loginDisable = false
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
that.registerMerchant = function () {
|
|
|
|
|
$state.go('shopify.register', {shop: getQueryVariable("shop"), code: getQueryVariable("code")});
|
|
|
|
|
}
|
|
|
|
|
}]);
|
|
|
|
|
|
|
|
|
|
module.controller('ShopifyRegisterController', ['$scope', '$http', '$stateParams', function ($scope, $http, $stateParams) {
|
|
|
|
@ -223,10 +241,11 @@ define(['angular', 'uiRouter', 'uiBootstrap'], function (angular) {
|
|
|
|
|
const param = {
|
|
|
|
|
paymentMerchant,
|
|
|
|
|
paymentAccount,
|
|
|
|
|
shopifyShop: that.partner.shopifyShop
|
|
|
|
|
shopifyShop: $stateParams.shop,
|
|
|
|
|
code: $stateParams.code
|
|
|
|
|
}
|
|
|
|
|
$http.post('shopify/store/register', param).then(function (resp) {
|
|
|
|
|
location.href = resp.data.url
|
|
|
|
|
location.href = resp.data.redirectUrl
|
|
|
|
|
}, function (error) {
|
|
|
|
|
that.resError = error.data.message;
|
|
|
|
|
that.registerDisable = false
|
|
|
|
|