private static function _nominate() { $out = new stdClass(); $out->success = false; $bracketId = Lib\Url::Post('bracketId', true); $nomineeName = Lib\Url::Post('nomineeName'); $nomineeSource = Lib\Url::Post('nomineeSource'); $verified = Lib\Url::Post('verified') === 'true'; $image = Lib\Url::Post('image'); if ($bracketId && $nomineeName && $image) { // Verify the image first if (self::_verifyImage($image)) { $nominee = new Api\Nominee(); $nominee->bracketId = $bracketId; $nominee->name = $nomineeName; $nominee->source = $nomineeSource; $nominee->created = time(); $nominee->image = $image; $nominee->processed = $verified ? 1 : null; if ($nominee->sync()) { $out->success = true; } else { $out->message = 'Unable to save to database'; } } else { $out->message = 'Invalid image'; } } else { $out->message = 'Missing fields'; $out->data = $_POST; } return $out; }
private static function _nominate(Api\User $user) { $out = new stdClass(); $out->success = false; $bracketId = Lib\Url::Post('bracketId', true); $bracket = Api\Bracket::getById($bracketId); $nomineeName = Lib\Url::Post('nomineeName'); $nomineeSource = Lib\Url::Post('nomineeSource'); $verified = Lib\Url::Post('verified') === 'true'; $image = Lib\Url::Post('image'); if ($bracket && $nomineeName && $image) { if (self::_verifyAccountAge($user, $bracket)) { // Verify the image first if (self::_verifyImage($image)) { $nominee = new Api\Nominee(); $nominee->bracketId = $bracket->id; $nominee->name = $nomineeName; $nominee->source = $nomineeSource; $nominee->created = time(); $nominee->image = $image; $nominee->processed = $verified ? 1 : null; if ($nominee->sync()) { $out->success = true; } else { $out->message = 'Unable to save to database'; } } else { $out->message = 'Invalid image'; } } else { $out->message = 'Your reddit account is not old enough to nominate in this bracket'; $out->date = $_POST; } } else { $out->message = 'Missing fields'; $out->data = $_POST; } return $out; }