mirror of
https://github.com/lkddi/nexusphp.git
synced 2026-04-24 12:07:23 +08:00
improve login notify + migrate torrent purchase to announce
This commit is contained in:
+7
-3
@@ -82,7 +82,7 @@ $seeder = ($left == 0) ? "yes" : "no";
|
||||
|
||||
// check passkey
|
||||
if (!$az = $Cache->get_value('user_passkey_'.$passkey.'_content')){
|
||||
$res = sql_query("SELECT id, username, downloadpos, enabled, uploaded, downloaded, class, parked, clientselect, showclienterror, passkey, donor, donoruntil FROM users WHERE passkey=". sqlesc($passkey)." LIMIT 1");
|
||||
$res = sql_query("SELECT id, username, downloadpos, enabled, uploaded, downloaded, class, parked, clientselect, showclienterror, passkey, donor, donoruntil, seedbonus FROM users WHERE passkey=". sqlesc($passkey)." LIMIT 1");
|
||||
$az = mysql_fetch_array($res);
|
||||
do_log("[check passkey], currentUser: " . nexus_json_encode($az));
|
||||
$Cache->cache_value('user_passkey_'.$passkey.'_content', $az, 3600);
|
||||
@@ -153,8 +153,12 @@ if ($torrent['approval_status'] != \App\Models\Torrent::APPROVAL_STATUS_ALLOW &&
|
||||
}
|
||||
if ($seeder == 'no' && isset($torrent['price']) && $torrent['price'] > 0 && $torrent['owner'] != $userid) {
|
||||
$hasBuy = \App\Models\TorrentBuyLog::query()->where('uid', $userid)->where('torrent_id', $torrent['id'])->exists();
|
||||
if (!$hasBuy) {
|
||||
err("You have not purchased this torrent yet");
|
||||
if (!$hasBuy && isset($az['seedbonus'])) {
|
||||
if ($az['seedbonus'] < $torrent['price']) {
|
||||
err("Not enough bonus to buy this paid torrent");
|
||||
}
|
||||
$bonusRep = new \App\Repositories\BonusRepository();
|
||||
$bonusRep->consumeToBuyTorrent($az['id'], $torrent['id'], 'Web');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+13
-10
@@ -117,16 +117,19 @@ if ((($row['banned'] == 'yes' || ($approvalNotAllowed && !$allowOwnerDownload))
|
||||
denyDownload();
|
||||
}
|
||||
|
||||
if ($row['price'] > 0 && $CURUSER['id'] != $row['owner']) {
|
||||
$hasBuy = \App\Models\TorrentBuyLog::query()->where('uid', $CURUSER['id'])->where('torrent_id', $id)->exists();
|
||||
if (!$hasBuy) {
|
||||
if ($CURUSER['seedbonus'] < $row['price']) {
|
||||
stderr('Error', nexus_trans('bonus.not_enough', ['require_bonus' => number_format($row['price']), 'now_bonus' => number_format($CURUSER['seedbonus'])]));
|
||||
}
|
||||
$bonusRep = new \App\Repositories\BonusRepository();
|
||||
$bonusRep->consumeToBuyTorrent($CURUSER['id'], $id, 'Web');
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Migrate to announce.php, due to IYUU will download torrent automatically
|
||||
*/
|
||||
//if ($row['price'] > 0 && $CURUSER['id'] != $row['owner']) {
|
||||
// $hasBuy = \App\Models\TorrentBuyLog::query()->where('uid', $CURUSER['id'])->where('torrent_id', $id)->exists();
|
||||
// if (!$hasBuy) {
|
||||
// if ($CURUSER['seedbonus'] < $row['price']) {
|
||||
// stderr('Error', nexus_trans('bonus.not_enough', ['require_bonus' => number_format($row['price']), 'now_bonus' => number_format($CURUSER['seedbonus'])]));
|
||||
// }
|
||||
// $bonusRep = new \App\Repositories\BonusRepository();
|
||||
// $bonusRep->consumeToBuyTorrent($CURUSER['id'], $id, 'Web');
|
||||
// }
|
||||
//}
|
||||
|
||||
sql_query("UPDATE torrents SET hits = hits + 1 WHERE id = ".sqlesc($id)) or sqlerr(__FILE__, __LINE__);
|
||||
|
||||
|
||||
+4
-18
@@ -37,24 +37,10 @@ $log = "user: {$row['id']}, ip: $ip";
|
||||
if ($row["passhash"] != md5($row["secret"] . $password . $row["secret"])) {
|
||||
login_failedlogins();
|
||||
}
|
||||
$locationInfo = get_ip_location_from_geoip($ip);
|
||||
$thisLoginLog = \App\Models\LoginLog::query()->create([
|
||||
'ip' => $ip,
|
||||
'uid' => $row['id'],
|
||||
'country' => $locationInfo['country_en'] ?? '',
|
||||
'city' => $locationInfo['city_en'] ?? '',
|
||||
'client' => 'Web',
|
||||
]);
|
||||
$lastLoginLog = \App\Models\LoginLog::query()->where('uid', $row['id'])->orderBy('id', 'desc')->first();
|
||||
if (
|
||||
$lastLoginLog && $lastLoginLog->country && $lastLoginLog->city
|
||||
&& $locationInfo['country_en'] && $locationInfo['city_en']
|
||||
&& ($lastLoginLog->country != $locationInfo['country_en'] || $lastLoginLog->city != $locationInfo['city_en'])
|
||||
) {
|
||||
$command = sprintf("user:login_notify --this_id=%s --last_id=%s", $thisLoginLog->id, $lastLoginLog->id);
|
||||
do_log("[LOGIN_NOTIFY], user: {$row['id']}, $command");
|
||||
executeCommand($command, "string", true, false);
|
||||
}
|
||||
|
||||
$userRep = new \App\Repositories\UserRepository();
|
||||
$userRep->saveLoginLog($row['id'], $ip, 'Web', true);
|
||||
|
||||
if ($row["enabled"] == "no")
|
||||
bark($lang_takelogin['std_account_disabled']);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user