Example #1
0
 public static function generate(array $params)
 {
     $action = Lib\Url::Get('action', null);
     $out = new stdClass();
     $out->success = false;
     $user = Api\User::getCurrentUser();
     if ($user) {
         if (self::_isFlooding($user)) {
             $out->message = 'You\'re doing that too fast!';
         } else {
             switch ($action) {
                 case 'nominate':
                     $out = self::_nominate($user);
                     break;
                 case 'vote':
                     $out = self::_vote($user);
                     break;
                 default:
                     $out->message = 'No action specified';
                     break;
             }
             if ($out->success) {
                 self::_setFloodMarker($user);
             }
         }
     } else {
         $out->message = 'You must be logged in';
     }
     Lib\Display::renderJson($out);
 }
Example #2
0
 public static function generate(array $params)
 {
     $code = Lib\Url::Get('code', null);
     $action = array_shift($params);
     if ($action === 'logout') {
         $user = Api\User::getCurrentUser();
         if ($user) {
             $user->logout();
             header('Location: /brackets/');
         }
     }
     if ($code) {
         $success = Api\User::authenticateUser($code);
         if ($success) {
             $redirect = Lib\Url::Get('state', '/');
             header('Location: ' . $redirect);
             exit;
         } else {
             Lib\Display::addKey('content', 'We were unable to verify your account at this time or your account age does not meet the requirements.');
         }
     } else {
         $obj = new stdClass();
         $obj->loginUrl = Api\User::getLoginUrl(Lib\Url::Get('redirect'));
         // Do a mobile check
         if (preg_match('/iphone|android|windows phone/i', $_SERVER['HTTP_USER_AGENT'])) {
             $obj->loginUrl = str_replace('authorize', 'authorize.compact', $obj->loginUrl);
         }
         $obj->originalUrl = Lib\Url::Get('redirect');
         Lib\Display::addKey('page', 'login');
         Lib\Display::addKey('title', 'Login' . DEFAULT_TITLE_SUFFIX);
         Lib\Display::renderAndAddKey('content', 'login', $obj);
     }
 }
Example #3
0
 public static function start()
 {
     self::$_id = Url::Get(SESSION_NAME, null, $_COOKIE);
     if (!self::$_id) {
         self::$_id = bin2hex(openssl_random_pseudo_bytes(32));
         setcookie(SESSION_NAME, self::$_id, time() + SESSION_EXPIRE, '/', SESSION_DOMAIN);
     }
     self::$_sess = Cache::Get(SESSION_NAME . '_' . self::$_id, true);
 }
Example #4
0
 /**
  * Creates a cache key using selected values from an array of values (usually _GET)
  */
 public static function createCacheKey($prefix, $params, $values)
 {
     $retVal = [$prefix];
     foreach ($params as $param) {
         $value = Url::Get($param, 'null', $values);
         if (is_array($value)) {
             $value = implode(',', $value);
         }
         $retVal[] = $value;
     }
     return implode('_', $retVal);
 }
Example #5
0
 public static function render()
 {
     $query = Lib\Url::Get('q');
     $bracketId = Lib\Url::GetInt('bracketId');
     $out = Api\MalItem::getNameTypeahead($query, 'character');
     if ($bracketId) {
         $out = array_merge($out, self::_getSimilarCharacters($bracketId, $query));
     }
     // Standardize the output
     $out = self::_standardizeData($out);
     Lib\Display::renderJson($out);
 }