From dbecd54ad7b552508e923e58988a2adfe28e60f4 Mon Sep 17 00:00:00 2001 From: Chenx221 Date: Sat, 16 Mar 2024 20:26:21 +0800 Subject: [PATCH] =?UTF-8?q?Web=20Authn(2.5/3)=20=E5=AE=9E=E7=8E=B0?= =?UTF-8?q?=E7=94=A8=E6=88=B7=E4=BF=A1=E6=81=AF=E5=89=8D=E7=AB=AF=E7=9A=84?= =?UTF-8?q?=E5=AF=B9webauthn=E7=9A=84=E9=AA=8C=E8=AF=81=E8=AE=BE=E5=A4=87?= =?UTF-8?q?=E7=AE=A1=E7=90=86=20*=E4=BD=BF=E7=94=A8pjax=E5=8A=A8=E6=80=81?= =?UTF-8?q?=E5=88=B7=E6=96=B0=E5=86=85=E5=AE=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- views/user/_creIndex.php | 38 ++++++++++++++++++++++++++++++++++++++ views/user/info.php | 26 +++++++++++++++++++++++--- web/js/user-info.js | 15 +++++++++++++++ 3 files changed, 76 insertions(+), 3 deletions(-) create mode 100644 views/user/_creIndex.php diff --git a/views/user/_creIndex.php b/views/user/_creIndex.php new file mode 100644 index 0000000..2cb5711 --- /dev/null +++ b/views/user/_creIndex.php @@ -0,0 +1,38 @@ +'; +echo GridView::widget([ + 'dataProvider' => $dataProvider, + 'layout' => "{items}", + 'columns' => [ + [ + 'attribute' => 'name', + 'label' => '设备名', + ], + [ + 'attribute' => 'public_key_credential_id', + 'label' => '公钥凭证ID', + ], + [ + 'class' => ActionColumn::class, + 'template' => '{delete}', + 'buttons' => [ + 'delete' => function ($url, $model, $key) { + return Html::a('', ['credential-delete', 'id' => $model->id], [ + 'data' => [ + 'confirm' => '你确定要删除这个项目吗?', + 'method' => 'post', + 'pjax' => 1, + ], + ]); + }, + ], + ], + ], +]); +echo ''; \ No newline at end of file diff --git a/views/user/info.php b/views/user/info.php index 29dfb57..da050b3 100644 --- a/views/user/info.php +++ b/views/user/info.php @@ -15,6 +15,7 @@ use app\assets\FontAwesomeAsset; use app\assets\SimpleWebAuthnBrowser; +use app\models\PublicKeyCredentialSourceRepository; use app\models\User; use app\utils\FileSizeHelper; use app\utils\IPLocation; @@ -27,9 +28,13 @@ use Endroid\QrCode\Writer\PngWriter; use yii\bootstrap5\ActiveForm; use yii\bootstrap5\Html; use yii\bootstrap5\Modal; +use yii\data\ActiveDataProvider; +use yii\grid\ActionColumn; +use yii\grid\GridView; use yii\helpers\Url; use yii\web\JqueryAsset; use yii\web\View; +use yii\widgets\Pjax; $this->title = '个人设置'; FontAwesomeAsset::register($this); @@ -274,9 +279,9 @@ $darkMode = Yii::$app->user->identity->dark_mode; Passwordless验证 (Webauthn) (BETA)
- "webauthn_add", 'type' => 'button', 'class' => 'btn btn-primary btn-sm']) ?> - "webauthn_verify", 'type' => 'button', 'class' => 'btn btn-primary btn-sm']) ?> - "webauthn_detail", 'type' => 'button', 'class' => 'btn btn-primary btn-sm']) ?> + "webauthn_add", 'type' => 'button', 'class' => 'btn btn-primary btn-sm']) ?> + "webauthn_verify", 'type' => 'button', 'class' => 'btn btn-primary btn-sm']) ?> + "webauthn_detail", 'type' => 'button', 'class' => 'btn btn-primary btn-sm']) ?>
'

管理已添加的Webauthn设备

', + 'id' => 'credentialModal', + 'size' => 'modal-lg', +]); + +echo Html::tag('div', '你可以在下方查看和删除已经添加的Webauthn设备', ['class' => 'modal-body']); +$dataProvider = new ActiveDataProvider([ + 'query' => PublicKeyCredentialSourceRepository::find()->where(['user_id' => Yii::$app->user->id]), +]); +// 使用 GridView 小部件显示数据 +Pjax::begin(); +echo Html::tag('div', '', ['id' => 'pjax-container']); +Pjax::end(); Modal::end(); $this->registerJsFile('@web/js/user-info.js', ['depends' => [JqueryAsset::class, SimpleWebAuthnBrowser::class], 'position' => View::POS_END]); ?> diff --git a/web/js/user-info.js b/web/js/user-info.js index cc6250b..f36c832 100644 --- a/web/js/user-info.js +++ b/web/js/user-info.js @@ -1,3 +1,4 @@ +$.pjax.defaults.scrollTo = false; $(document).ready(function () { $('#deleteConfirm').change(function () { if (this.checked) { @@ -43,6 +44,20 @@ document.querySelector('.editable-username').addEventListener('click', function $('#changeAccountName').modal('show'); }); +document.querySelector('#webauthn_detail').addEventListener('click', function () { + // $('#credentialModal').modal('show'); + $.ajax({ + url: 'index.php?r=user%2Fcredential-list', // 替换为你的 API 路径 + method: 'GET', + success: function(data) { + $('#pjax-container').html(data); + }, + complete: function() { + $('#credentialModal').modal('show'); + } + }); +}); + // WebAuthn registration #BEGIN const { startRegistration } = SimpleWebAuthnBrowser;