コード例 #1
0
 /**
  * @Route ("/admin/chat/ip")
  * @Secure ({"ADMIN"})
  *
  * @param array $params         
  * @param ViewModel $model          
  * @throws Exception
  * @return string
  */
 public function adminChatIp(array $params, ViewModel $model)
 {
     $model->title = 'Chat';
     FilterParams::required($params, 'ip');
     $userService = UserService::instance();
     $model->usersByIp = $userService->findUsersWithIP($params['ip']);
     $model->searchIp = $params['ip'];
     return 'admin/chat';
 }
コード例 #2
0
 /**
  * @Route ("/gift/check")
  * @Secure ({"USER"})
  *
  * @param array $params
  * @return Response
  */
 public function giftCheckUser(array $params)
 {
     FilterParams::required($params, 's');
     $userService = UserService::instance();
     $subscriptionService = SubscriptionsService::instance();
     $userId = Session::getCredentials()->getUserId();
     $data = array('valid' => false, 'cangift' => false, 'username' => $params['s']);
     $user = $userService->getUserByUsername($params['s']);
     if (!empty($user)) {
         $data['cangift'] = $subscriptionService->getCanUserReceiveGift($userId, $user['userId']);
         $data['valid'] = true;
     }
     $response = new Response(Http::STATUS_OK);
     $response->addHeader(Http::HEADER_CONTENTTYPE, MimeType::JSON);
     $response->setBody(json_encode($data));
     return $response;
 }
コード例 #3
0
 /**
  * @Route ("/admin/user/{id}/subscription/{subscriptionId}/save")
  * @Route ("/admin/user/{id}/subscription/save")
  * @Secure ({"ADMIN"})
  * @HttpMethod ({"POST"})
  *
  * @param array $params         
  * @param ViewModel $model          
  * @throws Exception
  * @return string
  */
 public function subscriptionSave(array $params, ViewModel $model)
 {
     FilterParams::required($params, 'subscriptionType');
     FilterParams::required($params, 'status');
     FilterParams::required($params, 'createdDate');
     FilterParams::required($params, 'endDate');
     $subscriptionsService = SubscriptionsService::instance();
     $subscriptionType = $subscriptionsService->getSubscriptionType($params['subscriptionType']);
     $subscription = array();
     $subscription['subscriptionType'] = $subscriptionType['id'];
     $subscription['subscriptionTier'] = $subscriptionType['tier'];
     $subscription['status'] = $params['status'];
     $subscription['createdDate'] = $params['createdDate'];
     $subscription['endDate'] = $params['endDate'];
     $subscription['userId'] = $params['id'];
     $subscription['subscriptionSource'] = isset($params['subscriptionSource']) && !empty($params['subscriptionSource']) ? $params['subscriptionSource'] : Config::$a['subscriptionType'];
     if (isset($params['subscriptionId']) && !empty($params['subscriptionId'])) {
         $subscription['subscriptionId'] = $params['subscriptionId'];
         $subscriptionId = $subscription['subscriptionId'];
         $subscriptionsService->updateSubscription($subscription);
         Session::set('modelSuccess', 'Subscription updated!');
     } else {
         $subscriptionId = $subscriptionsService->addSubscription($subscription);
         Session::set('modelSuccess', 'Subscription created!');
     }
     $authService = AuthenticationService::instance();
     $authService->flagUserForUpdate($params['id']);
     return 'redirect: /admin/user/' . urlencode($params['id']) . '/subscription/' . urlencode($subscriptionId) . '/edit';
 }
コード例 #4
0
ファイル: ProfileController.php プロジェクト: TonyWoo/website
 /**
  * Update/add a address
  *
  * @Route ("/profile/address/update")
  * @HttpMethod ({"POST"})
  * @Secure ({"USER"})
  *
  * @param array $params
  * @return string
  */
 public function updateAddress(array $params)
 {
     FilterParams::required($params, 'fullName');
     FilterParams::required($params, 'line1');
     FilterParams::declared($params, 'line2');
     FilterParams::required($params, 'city');
     FilterParams::required($params, 'region');
     FilterParams::required($params, 'zip');
     FilterParams::required($params, 'country');
     $userService = UserService::instance();
     $userId = Session::getCredentials()->getUserId();
     $address = $userService->getAddressByUserId($userId);
     if (empty($address)) {
         $address = array();
         $address['userId'] = $userId;
     }
     $address['fullName'] = $params['fullName'];
     $address['line1'] = $params['line1'];
     $address['line2'] = $params['line2'];
     $address['city'] = $params['city'];
     $address['region'] = $params['region'];
     $address['zip'] = $params['zip'];
     $address['country'] = $params['country'];
     if (!isset($address['id']) || empty($address['id'])) {
         $userService->addAddress($address);
     } else {
         $userService->updateAddress($address);
     }
     Session::set('modelSuccess', 'Your address has been updated');
     return 'redirect: /profile';
 }
コード例 #5
0
ファイル: ChatApiController.php プロジェクト: TonyWoo/website
 /**
  * @Route ("/api/addtwitchsubscription")
  * @HttpMethod ({"POST"})
  *
  * Expects the following POST variables:
  *     privatekey=XXXXXXXX
  *
  * @param array $params
  * @return Response
  */
 public function addSubscription(array $params)
 {
     $response = array();
     // TODO GET RID OF THE COPY PASTE
     try {
         FilterParams::required($params, 'privatekey');
         if (!$this->checkPrivateKey($params['privatekey'])) {
             throw new Exception('Invalid shared private key.');
         }
         /*
          * The expected json schema is: {"123": 1, "431": 0}
          * where the key is the twitch user id and the value is whether
          * the user is a subscriber or not
          */
         $data = json_decode(file_get_contents('php://input'), true);
         $userService = UserService::instance();
         $authid = $userService->getTwitchIDFromNick($data['nick']);
         if ($authid) {
             $users = $userService->updateTwitchSubscriptions(array($authid => 1));
             $chatIntegrationService = ChatIntegrationService::instance();
             $authenticationService = AuthenticationService::instance();
             foreach ($users as $user) {
                 $authenticationService->flagUserForUpdate($user['userId']);
                 if (!$user['istwitchsubscriber']) {
                     // do not announce non-subs
                     continue;
                 }
                 $chatIntegrationService->sendBroadcast(sprintf("%s is now a Twitch subscriber!", $user['username']));
             }
         }
         $response = new Response(Http::STATUS_NO_CONTENT);
     } catch (Exception $e) {
         $response['success'] = false;
         $response['error'] = $e->getMessage();
         $response = new Response(Http::STATUS_BAD_REQUEST, json_encode($response));
         $response->addHeader(Http::HEADER_CONTENTTYPE, MimeType::JSON);
     }
     return $response;
 }
コード例 #6
0
ファイル: AdminController.php プロジェクト: 0x9ae76c/website
 /**
  * @Route ("/admin/chart/{type}")
  * @Secure ({"ADMIN"})
  *
  * @param array $params
  * @return Response
  */
 public function chartData(array $params)
 {
     FilterParams::required($params, 'type');
     $statisticsService = StatisticsService::instance();
     $cacheDriver = Application::instance()->getCacheDriver();
     $data = array();
     switch (strtoupper($params['type'])) {
         case 'REVENUELASTXDAYS':
             FilterParams::required($params, 'days');
             $key = 'RevenueLastXDays ' . intval($params['days']);
             if (!$cacheDriver->contains($key)) {
                 $data = $statisticsService->getRevenueLastXDays(intval($params['days']));
                 $cacheDriver->save($key, $data, 30);
             } else {
                 $data = $cacheDriver->fetch($key);
             }
             break;
         case 'REVENUELASTXMONTHS':
             FilterParams::required($params, 'months');
             $key = 'RevenueLastXMonths ' . intval($params['months']);
             if (!$cacheDriver->contains($key)) {
                 $data = $statisticsService->getRevenueLastXMonths(intval($params['months']));
                 $cacheDriver->save($key, $data, 30);
             } else {
                 $data = $cacheDriver->fetch($key);
             }
             break;
         case 'REVENUELASTXYEARS':
             FilterParams::required($params, 'years');
             $key = 'RevenueLastXYears ' . intval($params['years']);
             if (!$cacheDriver->contains($key)) {
                 $data = $statisticsService->getRevenueLastXYears(intval($params['years']));
                 $cacheDriver->save($key, $data, 30);
             } else {
                 $data = $cacheDriver->fetch($key);
             }
             break;
         case 'NEWSUBSCRIBERSLASTXDAYS':
             FilterParams::required($params, 'days');
             $key = 'NewSubscribersLastXDays ' . intval($params['days']);
             if (!$cacheDriver->contains($key)) {
                 $data = $statisticsService->getNewSubscribersLastXDays(intval($params['days']));
                 $cacheDriver->save($key, $data, 30);
             } else {
                 $data = $cacheDriver->fetch($key);
             }
             break;
         case 'NEWSUBSCRIBERSLASTXMONTHS':
             FilterParams::required($params, 'months');
             $key = 'NewSubscribersLastXMonths ' . intval($params['months']);
             if (!$cacheDriver->contains($key)) {
                 $data = $statisticsService->getNewSubscribersLastXMonths(intval($params['months']));
                 $cacheDriver->save($key, $data, 30);
             } else {
                 $data = $cacheDriver->fetch($key);
             }
             break;
         case 'NEWSUBSCRIBERSLASTXYEARS':
             FilterParams::required($params, 'years');
             $key = 'NewSubscribersLastXYears ' . intval($params['years']);
             if (!$cacheDriver->contains($key)) {
                 $data = $statisticsService->getNewSubscribersLastXYears(intval($params['years']));
                 $cacheDriver->save($key, $data, 30);
             } else {
                 $data = $cacheDriver->fetch($key);
             }
             break;
         case 'NEWTIEREDSUBSCRIBERSLASTXDAYS':
             FilterParams::required($params, 'days');
             $key = 'NewTieredSubscribersLastXDays ' . intval($params['days']);
             if (!$cacheDriver->contains($key)) {
                 $data = $statisticsService->getNewTieredSubscribersLastXDays(intval($params['days']));
                 $cacheDriver->save($key, $data, 30);
             } else {
                 $data = $cacheDriver->fetch($key);
             }
             break;
     }
     $response = new Response(Http::STATUS_OK, json_encode($data));
     $response->addHeader(Http::HEADER_CONTENTTYPE, MimeType::JSON);
     return $response;
 }
コード例 #7
0
 /**
  * @Route ("/profile/messages/{targetuserid}")
  * @Secure ({"USER"})
  * @HttpMethod ({"GET"})
  *
  * @param array $params
  * @return Response
  */
 public function message(array $params, ViewModel $viewModel)
 {
     FilterParams::required($params, 'targetuserid');
     $privateMessageService = PrivateMessageService::instance();
     $userService = UserService::instance();
     $userId = Session::getCredentials()->getUserId();
     $username = Session::getCredentials()->getUsername();
     $targetuser = $userService->getUserById($params['targetuserid']);
     if (empty($targetuser)) {
         throw new Exception('Invalid user');
     }
     $messages = $privateMessageService->getMessagesBetweenUserIdAndTargetUserId($userId, $params['targetuserid'], 0, 1000);
     $privateMessageService->markMessagesRead($userId, $params['targetuserid']);
     $viewModel->targetuser = $targetuser;
     $viewModel->messages = $messages;
     $viewModel->username = $username;
     $viewModel->userId = $userId;
     $viewModel->title = 'Message';
     return 'profile/message';
 }
コード例 #8
0
ファイル: AdminController.php プロジェクト: noremac13/website
 /**
  * @Route ("/admin/user/find")
  * @Secure ({"ADMIN"})
  *
  * @param array $params         
  */
 public function adminUserFind(array $params)
 {
     FilterParams::isRequired($params, 's');
     $userService = UserService::instance();
     $users = $userService->findUsers($params['s'], 10);
     $response = new Response(Http::STATUS_OK);
     $response->addHeader(Http::HEADER_CONTENTTYPE, MimeType::JSON);
     $response->setBody(json_encode($users));
     return $response;
 }