Exemplo n.º 1
0
 /**
  * @method POST
  */
 function post()
 {
     // parse request
     parse_str($this->request->data, $request);
     $plan = $request['plan'];
     // get an authuser
     $authUser = new AuthUser();
     if (isset($authUser->UserUniqId)) {
         // check if authorized
         try {
             $site = Site::GetBySiteUniqId($authUser->SiteUniqId);
             Stripe::setApiKey(STRIPE_API_KEY);
             $customer = Stripe_Customer::retrieve($site['CustomerId']);
             // retrieve default subscription
             if (isset($customer->subscriptions->data[0])) {
                 $subscription = $customer->subscriptions->data[0];
                 // updates the subscription
                 if ($subscription != NULL) {
                     $subscription->plan = $plan;
                     $subscription->save();
                 }
                 // update the session
                 AuthUser::UpdateSubscription();
             }
             // return a json response
             return new Tonic\Response(Tonic\Response::OK);
         } catch (Exception $e) {
             $response = new Tonic\Response(Tonic\Response::BADREQUEST);
             $response->body = $e->getMessage();
             return $response;
         }
     } else {
         return new Tonic\Response(Tonic\Response::UNAUTHORIZED);
     }
 }
Exemplo n.º 2
0
 public static function Create($user, $canEdit, $canPublish, $canRemove, $canCreate)
 {
     session_start();
     $site = Site::GetBySiteId($user['SiteId']);
     $isSuperAdmin = false;
     if ($user['Email'] == SITE_ADMIN) {
         // set is superman
         $isSuperAdmin = true;
     }
     $isFirstLogin = 0;
     if ($site['LastLogin'] == null || $site['LastLogin'] == '') {
         $isFirstLogin = 1;
     }
     // determine whether user has a photo
     $hasPhotoUrl = true;
     if ($user['PhotoUrl'] == null || $user['PhotoUrl'] == '') {
         $hasPhotoUrl = false;
     }
     Site::SetLastLogin($site['SiteUniqId']);
     $directory = 'sites/' . $site['FriendlyId'] . '/';
     $_SESSION['UserId'] = $user['UserId'];
     $_SESSION['UserUniqId'] = $user['UserUniqId'];
     $_SESSION['Role'] = $user['Role'];
     $_SESSION['Language'] = $user['Language'];
     $_SESSION['IsSuperAdmin'] = $isSuperAdmin;
     $_SESSION['IsFirstLogin'] = $isFirstLogin;
     $_SESSION['Email'] = $user['Email'];
     $_SESSION['Name'] = $user['FirstName'] . ' ' . $user['LastName'];
     $_SESSION['FirstName'] = $user['FirstName'];
     $_SESSION['LastName'] = $user['LastName'];
     $_SESSION['HasPhotoUrl'] = $hasPhotoUrl;
     $_SESSION['PhotoUrl'] = $user['PhotoUrl'];
     $_SESSION['SiteId'] = $user['SiteId'];
     $_SESSION['SiteUniqId'] = $site['SiteUniqId'];
     $_SESSION['SiteFriendlyId'] = $site['FriendlyId'];
     $_SESSION['Domain'] = $site['Domain'];
     $_SESSION['Currency'] = $site['Currency'];
     $_SESSION['WeightUnit'] = $site['WeightUnit'];
     $_SESSION['Directory'] = $directory;
     $_SESSION['LogoUrl'] = $site['LogoUrl'];
     $_SESSION['sid'] = session_id();
     $_SESSION['ip'] = $_SERVER['REMOTE_ADDR'];
     $_SESSION['SiteName'] = $site['Name'];
     $_SESSION['FileUrl'] = 'sites/' . $site['FriendlyId'] . '/files/';
     $_SESSION['TimeZone'] = $site['TimeZone'];
     $_SESSION['Type'] = $site['Type'];
     $_SESSION['CustomerId'] = $site['CustomerId'];
     // what can be edited and published
     if ($canEdit == 'All' || $canPublish == 'All' || $canRemove == 'All' || $canCreate == 'All') {
         $_SESSION['Access'] = 'All';
     } else {
         $_SESSION['Access'] = $canEdit . ',' . $canPublish . ',' . $canRemove . ',' . $canCreate;
     }
     $_SESSION['CanEdit'] = $canEdit;
     $_SESSION['CanPublish'] = $canPublish;
     $_SESSION['CanRemove'] = $canRemove;
     $_SESSION['CanCreate'] = $canCreate;
     if (strtoupper($site['Type']) == 'SUBSCRIPTION' && $site['CustomerId'] != NULL) {
         AuthUser::UpdateSubscription();
     } else {
         $_SESSION['Status'] = 'N/A';
         $_SESSION['Plan'] = 'N/A';
         $_SESSION['RenewalDate'] = NULL;
     }
 }