From 10026ec8074cb0f295fdbb8638ed9aceb0ddfd3d Mon Sep 17 00:00:00 2001 From: Daniel Camargo Date: Tue, 1 Oct 2013 10:45:58 -0300 Subject: [PATCH] partial #1835 --- .../default/crunchbutton/api/referral/index.php | 2 +- www/assets/js/app.js | 4 +++- www/assets/js/services.referral.js | 11 ++++++++++- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/include/controllers/default/crunchbutton/api/referral/index.php b/include/controllers/default/crunchbutton/api/referral/index.php index 301223fd0..c16a49861 100644 --- a/include/controllers/default/crunchbutton/api/referral/index.php +++ b/include/controllers/default/crunchbutton/api/referral/index.php @@ -43,7 +43,7 @@ class Controller_api_referral extends Crunchbutton_Controller_Rest { $invites = Crunchbutton_Referral::getInvitesPerCode( $invite_code ); $limit = Crunchbutton_Referral::getInvitesLimit(); $enabled = Crunchbutton_Referral::isReferralEnable(); - $url = 'http://' . $_SERVER['HTTP_HOST'] . '/invite/' . $invite_code; + $url = 'http://' . $_SERVER['HTTP_HOST'] . '?invite=' . $invite_code; $value = Crunchbutton_Referral::getInviterCreditValue(); echo json_encode(['invites' => intval( $invites ), 'limit' => intval( $limit ), 'invite_url' => $url, 'value' => intval( $value ), 'enabled' => $enabled ]); } else { diff --git a/www/assets/js/app.js b/www/assets/js/app.js index fa750f460..9cedd75ca 100644 --- a/www/assets/js/app.js +++ b/www/assets/js/app.js @@ -181,7 +181,7 @@ NGApp.config(['$routeProvider', '$locationProvider', function($routeProvider, $l }]); // global route change items -NGApp.controller('AppController', function ($scope, $route, $routeParams, $rootScope, $location, $window, AccountService, MainNavigationService, AccountSignOut, CartService) { +NGApp.controller('AppController', function ($scope, $route, $routeParams, $rootScope, $location, $window, AccountService, MainNavigationService, AccountSignOut, CartService, ReferralService) { // define external pointers App.rootScope = $rootScope; @@ -327,6 +327,8 @@ NGApp.controller('AppController', function ($scope, $route, $routeParams, $rootS AccountService.checkUser(); + ReferralService.check(); + }); App.alert = function(txt, title) { diff --git a/www/assets/js/services.referral.js b/www/assets/js/services.referral.js index bd6bdf17d..a357ca73e 100644 --- a/www/assets/js/services.referral.js +++ b/www/assets/js/services.referral.js @@ -1,8 +1,17 @@ // ReferralService service -NGApp.factory( 'ReferralService', function( $http, $rootScope ){ +NGApp.factory( 'ReferralService', function( $http, $rootScope, $location ){ var service = { invite_url : null, value : 0, invites : 0, limit : 0 }; + service.check = function(){ + var param = $location.search(); + if( param.invite ){ + $.cookie( 'referral', param.invite ); + // Remove the invite from url + $location.url( $location.path() ); + } + } + service.getInviteCode = function(){ var url = App.service + 'referral/code'; $http( {