/** * @param string $ip * @param callable $cb */ public function query($ip, $cb) { if (is_string($ip)) { $ip = ip2long($ip); } $this->blocks->findOne(function ($blk) use($cb) { if (!$blk) { call_user_func($cb, false); return; } $this->locations->findOne(function ($loc) use($cb) { if ($loc) { $loc['country'] = $this->countries[$loc['cc']]; $loc['text'] = $loc['country']; if (isset($loc['r']) && !ctype_digit($loc['r'])) { $loc['text'] = $loc['r'] . ', ' . $loc['text']; } if (isset($loc['c'])) { $loc['text'] = $loc['c'] . ', ' . $loc['text']; } } call_user_func($cb, $loc); }, ['where' => ['_id' => $blk['l']]]); }, ['where' => ['s' => ['$lte' => $ip]], 'sort' => ['s' => -1]]); }
/** * @param array $find * @param callable $cb */ public function getBlock($find, $cb) { if (isset($find['_id']) && is_string($find['_id'])) { $find['_id'] = new \MongoId($find['_id']); } $this->blocks->findOne($cb, array('where' => $find)); }
/** * @param $names * @param callable $cb */ public function get($agent, $cb) { $this->browsers->findOne(function ($item) use($cb, $agent) { if ($item) { call_user_func($cb, $item); return; } $browser = \get_browser($agent, true); $browser['name'] = $browser['browser']; unset($browser['browser_name_regex'], $browser['browser']); $this->browsers->insert(['_id' => $agent] + $browser); call_user_func($cb, $browser); }, ['where' => ['_id' => $agent]]); }
/** * @param $names * @param callable $cb */ public function check($token, $text, $invalidate = true, $cb) { $e = static::decodeToken($token); if ($e === false) { call_user_func($cb, 'badToken'); return; } list($id, $rnd) = $e; $this->captcha->findOne(function ($t) use($cb, $id, $text, $invalidate) { if (!$t) { call_user_func($cb, 'expired'); return; } Daemon::log(Debug::dump([$invalidate])); if (!$invalidate) { if (strtolower($t['text']) === strtolower($text)) { call_user_func($cb, 'ok'); return; } } $this->captcha->remove(['_id' => new \MongoId($id)], function ($lastError) use($t, $text, $cb) { if ($lastError['n'] !== 1) { call_user_func($cb, 'expired'); return; } if (strtolower($t['text']) !== strtolower($text)) { call_user_func($cb, 'incorrect'); return; } call_user_func($cb, 'ok'); }); }, ['where' => ['_id' => $id, 'rnd' => $rnd, 'ctime' => ['$gt' => time() - 3600]]]); }
/** * @param string $hash * @param callable $cb */ public function findByIntToken($str, $cb = null) { $this->externalAuthTokens->findOne($cb, ['where' => ['intToken' => $str]]); }
/** * @param array $credentials * @param callable $cb */ public function getRequestByCredentials(array $credentials, $cb = null) { $this->externalSignupRequests->findOne($cb, ['credentials' => ['$elemMatch' => $credentials]]); }