Skip to content

Commit 0d3a462

Browse files
committed
fix logincookie() error
1 parent 291f5c0 commit 0d3a462

File tree

3 files changed

+15
-16
lines changed

3 files changed

+15
-16
lines changed

app/Http/Controllers/AuthenticateController.php

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,6 @@ public function passkeyLogin($passkey)
5757
$user = User::query()->where('passkey', $passkey)->first(['id', 'passhash', 'secret', 'auth_key']);
5858
if ($user) {
5959
$ip = getip();
60-
/**
61-
* Not IP related
62-
* @since 1.8.0
63-
*/
64-
// $passhash = md5($user->passhash . $ip);
65-
// $passhash = md5($user->passhash);
66-
// do_log(sprintf('passhash: %s, ip: %s, md5: %s', $user->passhash, $ip, $passhash));
67-
// logincookie($user->id, $passhash,false, get_setting('system.cookie_valid_days', 365) * 86400, true, true, true);
6860
logincookie($user->id, $user->auth_key);
6961
$user->last_login = now();
7062
$user->save();

app/Models/User.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ protected function serializeDate(\DateTimeInterface $date): string
185185
'username', 'email', 'passhash', 'secret', 'stylesheet', 'editsecret', 'added', 'enabled', 'status',
186186
'leechwarn', 'leechwarnuntil', 'page', 'class', 'uploaded', 'downloaded', 'clientselect', 'showclienterror', 'last_home',
187187
'seedbonus', 'downloadpos', 'vip_added', 'vip_until', 'title', 'invites', 'attendance_card',
188-
'seed_points_per_hour', 'passkey', 'auth_key'
188+
'seed_points_per_hour', 'passkey', 'auth_key', 'last_login', 'lang'
189189
];
190190

191191
/**

include/functions.php

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2958,7 +2958,7 @@ function httperr($code = 404) {
29582958
function logincookie($id, $authKey, $duration = 0)
29592959
{
29602960
if (empty($authKey)) {
2961-
throw new \RuntimeException("user secret or auth_key is empty");
2961+
throw new \RuntimeException("auth_key is empty");
29622962
}
29632963
if ($duration <= 0) {
29642964
$duration = get_setting('system.cookie_valid_days', 365) * 86400;
@@ -2972,7 +2972,14 @@ function logincookie($id, $authKey, $duration = 0)
29722972
$signature = hash_hmac('sha256', $tokenJson, $authKey);
29732973
$authToken = base64_encode($tokenJson . '.' . $signature);
29742974
setcookie("c_secure_pass", $authToken, $expires, "/", "", true, true);
2975-
sql_query("UPDATE users SET last_login = NOW(), lang=" . sqlesc(get_langid_from_langcookie()) . " WHERE id = ".sqlesc($id));
2975+
$update = [
2976+
'last_login' => now(),
2977+
];
2978+
$langId = get_langid_from_langcookie();
2979+
if ($langId > 0) {
2980+
$update['lang'] = $langId;
2981+
}
2982+
\App\Models\User::query()->where("id", $id)->update($update);
29762983
}
29772984

29782985
function set_langfolder_cookie($folder, $expires = 0x7fffffff)
@@ -3005,12 +3012,12 @@ function get_protocol_prefix()
30053012
function get_langid_from_langcookie($lang = '')
30063013
{
30073014
if (empty($lang)) {
3008-
global $CURLANGDIR;
3009-
$lang = $CURLANGDIR;
3015+
$lang = get_langfolder_cookie();
30103016
}
3011-
3012-
$row = mysql_fetch_array(sql_query("SELECT id FROM language WHERE site_lang = 1 AND site_lang_folder = " . sqlesc($lang) . "ORDER BY id ASC")) or sqlerr(__FILE__, __LINE__);
3013-
return $row['id'];
3017+
$row = \App\Models\Language::query()->where('site_lang', 1)->where("site_lang_folder", $lang)->orderBy("id")->first();
3018+
return $row->id ?? 0;
3019+
// $row = mysql_fetch_array(sql_query("SELECT id FROM language WHERE site_lang = 1 AND site_lang_folder = " . sqlesc($lang) . "ORDER BY id ASC")) or sqlerr(__FILE__, __LINE__);
3020+
// return $row['id'];
30143021
}
30153022

30163023
function make_folder($pre, $folder_name)

0 commit comments

Comments
 (0)