mirror of
https://github.com/lkddi/nexusphp.git
synced 2026-04-14 20:40:49 +08:00
add login by passkey
This commit is contained in:
@@ -78,7 +78,7 @@ class Test extends Command
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$r = Carbon::parse('2022-07-03 04:00:00')->diffInSeconds();
|
||||
$r = \Composer\InstalledVersions::getPrettyVersion('filament/filament');
|
||||
dd($r);
|
||||
}
|
||||
|
||||
|
||||
@@ -5,10 +5,12 @@ namespace App\Http\Controllers;
|
||||
use App\Http\Resources\ExamResource;
|
||||
use App\Http\Resources\UserResource;
|
||||
use App\Models\Setting;
|
||||
use App\Models\User;
|
||||
use App\Repositories\AuthenticateRepository;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Cookie;
|
||||
|
||||
class AuthenticateController extends Controller
|
||||
{
|
||||
@@ -42,5 +44,17 @@ class AuthenticateController extends Controller
|
||||
return $this->success($result);
|
||||
}
|
||||
|
||||
public function passkeyLogin($passkey)
|
||||
{
|
||||
$user = User::query()->where('passkey', $passkey)->first(['id', 'passhash']);
|
||||
if ($user) {
|
||||
$passhash = md5($user->passhash . $_SERVER["REMOTE_ADDR"]);
|
||||
logincookie($user->id, $passhash,false,0x7fffffff, true, true, true);
|
||||
$user->last_login = now();
|
||||
$user->save();
|
||||
}
|
||||
return redirect('index.php');
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -12,8 +12,6 @@ use Illuminate\Support\Facades\DB;
|
||||
|
||||
class DashboardRepository extends BaseRepository
|
||||
{
|
||||
const FILAMENT_VERSION = '2.13.15';
|
||||
|
||||
public function getSystemInfo(): array
|
||||
{
|
||||
$result = [];
|
||||
@@ -39,7 +37,7 @@ class DashboardRepository extends BaseRepository
|
||||
$result[$name] = [
|
||||
'name' => $name,
|
||||
'text' => nexus_trans("dashboard.system_info.$name"),
|
||||
'value' => self::FILAMENT_VERSION,
|
||||
'value' => \Composer\InstalledVersions::getPrettyVersion('filament/filament'),
|
||||
];
|
||||
$name = 'php_version';
|
||||
$result[$name] = [
|
||||
|
||||
@@ -699,7 +699,8 @@ $lang_settings = array
|
||||
'text_login_type_warning' => '当游客访问方式不为正常时,必须使用秘密登录才能登录',
|
||||
'row_login_secret' => '登录密钥',
|
||||
'text_login_secret_current' => '当前密钥',
|
||||
'text_login_url_with_secret' => '登录链接',
|
||||
'text_login_url_with_secret' => '秘密登录链接',
|
||||
'text_login_url_with_passkey' => 'passkey 登录链接',
|
||||
'text_login_secret_regenerate_yes' => '重新生成(保存后会更新并延长有效期)',
|
||||
'text_login_secret_regenerate_no' => '保持当前(保存后不变)',
|
||||
'text_login_secret_lifetime' => '有效期',
|
||||
@@ -764,6 +765,7 @@ $lang_settings = array
|
||||
'text_approval_status_none_visible_note' => "默认:'是'。若改为'否',审核不为[通过]状态时强制显示审核状态图标。",
|
||||
'row_imdb_language' => 'IMDB 语言',
|
||||
'text_imdb_language_note' => '抓取 IMDB 数据使用的语言。',
|
||||
'text_login_type_passkey' => 'passkey',
|
||||
);
|
||||
|
||||
?>
|
||||
|
||||
@@ -699,7 +699,8 @@ $lang_settings = array
|
||||
'text_login_type_warning' => '當遊客訪問方式不為正常時,必須使用秘密登錄才能登錄',
|
||||
'row_login_secret' => '登錄密鑰',
|
||||
'text_login_secret_current' => '當前密鑰',
|
||||
'text_login_url_with_secret' => '登錄鏈接',
|
||||
'text_login_url_with_secret' => '秘密登錄鏈接',
|
||||
'text_login_url_with_passkey' => 'passkey 登錄鏈接',
|
||||
'text_login_secret_regenerate_yes' => '重新生成(保存後會更新並延長有效期)',
|
||||
'text_login_secret_regenerate_no' => '保持當前(保存後不變)',
|
||||
'text_login_secret_lifetime' => '有效期',
|
||||
@@ -764,6 +765,7 @@ $lang_settings = array
|
||||
'text_approval_status_none_visible_note' => "默認:'是'。若改為'否',審核不為[通過]狀態時強製顯示審核狀態圖標。",
|
||||
'row_imdb_language' => 'IMDB 語言',
|
||||
'text_imdb_language_note' => '抓取 IMDB 數據使用的語言。',
|
||||
'text_login_type_passkey' => 'passkey',
|
||||
);
|
||||
|
||||
?>
|
||||
|
||||
@@ -699,7 +699,8 @@ $lang_settings = array
|
||||
'text_login_type_warning' => "When 'Guest visit' != Normal, user can only login through the 'Secret' way",
|
||||
'row_login_secret' => 'Login secret',
|
||||
'text_login_secret_current' => 'Current secret',
|
||||
'text_login_url_with_secret' => 'Login URL',
|
||||
'text_login_url_with_secret' => 'Secret login URL',
|
||||
'text_login_url_with_passkey' => 'Passkey login URL',
|
||||
'text_login_secret_regenerate_yes' => "Re-generate(will update secret and extend it's lifetime after save)",
|
||||
'text_login_secret_regenerate_no' => "Remain(won't change secret and it's lifetime after save)",
|
||||
'text_login_secret_lifetime' => 'Deadline',
|
||||
@@ -764,6 +765,7 @@ $lang_settings = array
|
||||
'text_approval_status_none_visible_note' => "Default: 'Yes'. If change to 'No', force to show approval status icon when audit is not [allow] status.",
|
||||
'row_imdb_language' => 'IMDB Language',
|
||||
'text_imdb_language_note' => 'Languages used to crawl IMDB data.',
|
||||
'text_login_type_passkey' => 'passkey',
|
||||
);
|
||||
|
||||
?>
|
||||
|
||||
@@ -381,13 +381,15 @@ elseif ($action == 'securitysettings') //security settings
|
||||
|
||||
$loginTypeRadio = '<label><input type="radio" name="login_type" value="normal"' . (empty($SECURITY['login_type']) || $SECURITY['login_type'] == 'normal' ? ' checked' : '') . ' onclick="document.getElementById(\'tbody_login_secret\').style.display=\'none\';">' . $lang_settings['text_login_type_normal'] . '</label>';
|
||||
$loginTypeRadio .= '<label><input type="radio" name="login_type" value="secret"' . ($SECURITY['login_type'] == 'secret' ? ' checked' : '') . ' onclick="document.getElementById(\'tbody_login_secret\').style.display=\'table-row-group\';">' . $lang_settings['text_login_type_secret'] . '</label>';
|
||||
$loginTypeRadio .= '<label><input type="radio" name="login_type" value="passkey"' . ($SECURITY['login_type'] == 'passkey' ? ' checked' : '') . ' onclick="document.getElementById(\'tbody_login_secret\').style.display=\'table-row-group\';">' . $lang_settings['text_login_type_passkey'] . '</label>';
|
||||
$loginTypeRadio .= sprintf('<b style="color: #DC143C; margin-left: 20px">%s</b>', $lang_settings['text_login_type_warning']);
|
||||
tr($lang_settings['row_login_type'], $loginTypeRadio, 1);
|
||||
|
||||
print '</tbody><tbody id="tbody_login_secret" style="display: ' . ($SECURITY['login_type'] == 'secret' ? 'table-row-group' : 'none') . '">';
|
||||
print '</tbody><tbody id="tbody_login_secret" style="display: ' . (in_array($SECURITY['login_type'], ['secret', 'passkey']) ? 'table-row-group' : 'none') . '">';
|
||||
$loginSecret = sprintf('%s:%s', $lang_settings['text_login_secret_current'], $SECURITY['login_secret'] ?? '');
|
||||
if (!empty($SECURITY['login_secret'])) {
|
||||
$loginSecret .= sprintf('<br/>%s: %s/login.php?secret=%s', $lang_settings['text_login_url_with_secret'], getSchemeAndHttpHost(), $SECURITY['login_secret']);
|
||||
$loginSecret .= sprintf('<br/>%s: %s/%s/{passkey}', $lang_settings['text_login_url_with_passkey'], getSchemeAndHttpHost(), $SECURITY['login_secret']);
|
||||
}
|
||||
$loginSecret .= sprintf('<br/><label><input type="radio" name="login_secret_regenerate" value="no"%s />%s</label>', !empty($SECURITY['login_secret']) ? ' checked' : '', $lang_settings['text_login_secret_regenerate_no']);
|
||||
$loginSecret .= sprintf('<br/><label><input type="radio" name="login_secret_regenerate" value="yes"%s />%s</label>', empty($SECURITY['login_secret']) ? ' checked' : '', $lang_settings['text_login_secret_regenerate_yes']);
|
||||
|
||||
@@ -17,3 +17,9 @@ Route::get('/', function () {
|
||||
return redirect('index.php');
|
||||
});
|
||||
|
||||
$passkeyLoginUri = get_setting('security.login_secret');
|
||||
if (!empty($passkeyLoginUri) && get_setting('security.login_type') == 'passkey') {
|
||||
Route::get("$passkeyLoginUri/{passkey}", [\App\Http\Controllers\AuthenticateController::class, 'passkeyLogin']);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user