From f7243f879b33e57cbc5fd645d625eb7d08682171 Mon Sep 17 00:00:00 2001 From: Gucheng Wang Date: Tue, 12 Jul 2022 20:45:22 +0800 Subject: [PATCH] Fix some JS warnings. --- web/src/App.js | 2 ++ web/src/UserEditPage.js | 8 ++++---- web/src/WebauthnCredentialTable.js | 26 ++++++++++++++---------- web/src/auth/LoginPage.js | 28 ++++++++++++-------------- web/src/backend/UserWebauthnBackend.js | 13 ++++++------ 5 files changed, 41 insertions(+), 36 deletions(-) diff --git a/web/src/App.js b/web/src/App.js index d81055ad..35846299 100644 --- a/web/src/App.js +++ b/web/src/App.js @@ -287,10 +287,12 @@ class App extends Component { +   {i18next.t("account:My Account")} +   {i18next.t("account:Logout")} diff --git a/web/src/UserEditPage.js b/web/src/UserEditPage.js index cda592d9..a73005ba 100644 --- a/web/src/UserEditPage.js +++ b/web/src/UserEditPage.js @@ -517,15 +517,15 @@ class UserEditPage extends React.Component { }} /> - ) + ); } else if(accountItem.name === "WebAuthn credentials") { return ( - - + + {Setting.getLabel(i18next.t("user:WebAuthn credentials"), i18next.t("user:WebAuthn credentials"))} : - {this.updateUserField('webauthnCredentials',table)}} refresh={this.getUser.bind(this)}/> + {this.updateUserField("webauthnCredentials", table);}} refresh={this.getUser.bind(this)} /> ); diff --git a/web/src/WebauthnCredentialTable.js b/web/src/WebauthnCredentialTable.js index 48c28802..08f67258 100644 --- a/web/src/WebauthnCredentialTable.js +++ b/web/src/WebauthnCredentialTable.js @@ -13,7 +13,7 @@ // limitations under the License. import React from "react"; -import {Button, Table} from 'antd'; +import {Button, Table} from "antd"; import i18next from "i18next"; import * as UserWebauthnBackend from "./backend/UserWebauthnBackend"; import * as Setting from "./Setting"; @@ -23,30 +23,34 @@ class WebAuthnCredentialTable extends React.Component { const columns = [ { title: i18next.t("user:WebAuthn credentials"), - dataIndex: 'ID', - key: 'ID', + dataIndex: "ID", + key: "ID", }, { title: i18next.t("general:Action"), - key: 'action', + key: "action", render: (text, record, index) => { return ( - - ) + ); } } - ] + ]; + return ( - (
{i18next.t("user:WebAuthn credentials")}     - +
)} - />) + /> + ); } deleteRow(table, i) { @@ -57,7 +61,7 @@ class WebAuthnCredentialTable extends React.Component { registerWebAuthn() { UserWebauthnBackend.registerWebauthnCredential().then((res) => { if (res.msg === "") { - Setting.showMessage("success", `Successfully added webauthn credentials`); + Setting.showMessage("success", "Successfully added webauthn credentials"); } else { Setting.showMessage("error", res.msg); } diff --git a/web/src/auth/LoginPage.js b/web/src/auth/LoginPage.js index 135151f8..0788b8b6 100644 --- a/web/src/auth/LoginPage.js +++ b/web/src/auth/LoginPage.js @@ -50,7 +50,7 @@ import CustomGithubCorner from "../CustomGithubCorner"; import {CountDownInput} from "../common/CountDownInput"; import BilibiliLoginButton from "./BilibiliLoginButton"; -const { TabPane } = Tabs; +const {TabPane} = Tabs; class LoginPage extends React.Component { constructor(props) { @@ -475,14 +475,14 @@ class LoginPage extends React.Component { ) : ( - ) @@ -639,13 +639,13 @@ class LoginPage extends React.Component { } credentialRequestOptions.publicKey.challenge = UserWebauthnBackend.webAuthnBufferDecode(credentialRequestOptions.publicKey.challenge); - credentialRequestOptions.publicKey.allowCredentials.forEach(function (listItem) { + credentialRequestOptions.publicKey.allowCredentials.forEach(function(listItem) { listItem.id = UserWebauthnBackend.webAuthnBufferDecode(listItem.id); }); return navigator.credentials.get({ publicKey: credentialRequestOptions.publicKey - }) + }); }) .then((assertion) => { let authData = assertion.response.authenticatorData; @@ -670,7 +670,7 @@ class LoginPage extends React.Component { }) .then(res => res.json()).then((res) => { if (res.msg === "") { - Setting.showMessage("success", `Successfully logged in with webauthn credentials`); + Setting.showMessage("success", "Successfully logged in with webauthn credentials"); Setting.goToLink("/"); } else { Setting.showMessage("error", res.msg); @@ -679,7 +679,7 @@ class LoginPage extends React.Component { .catch(error => { Setting.showMessage("error", `Failed to connect to server: ${error}`); }); - }) + }); } renderPasswordOrCodeInput() { @@ -707,23 +707,21 @@ class LoginPage extends React.Component { disabled={!application.enablePassword} /> - ) + ); } } - renderMethodChoiceBox(){ + renderMethodChoiceBox() { let application = this.getApplicationObj(); if (application.enableWebAuthn) { return (
- {this.setState({loginMethod: key})}} centered> - - - - + {this.setState({loginMethod: key});}} centered> + +
- ) + ); } } diff --git a/web/src/backend/UserWebauthnBackend.js b/web/src/backend/UserWebauthnBackend.js index 3d9ea2b1..94fbdc05 100644 --- a/web/src/backend/UserWebauthnBackend.js +++ b/web/src/backend/UserWebauthnBackend.js @@ -30,7 +30,7 @@ export function registerWebauthnCredential() { } return navigator.credentials.create({ publicKey: credentialCreationOptions.publicKey - }) + }); }) .then((credential) => { let attestationObject = credential.response.attestationObject; @@ -50,18 +50,19 @@ export function registerWebauthnCredential() { }) }) .then(res => res.json()); - }) + }); } export function deleteUserWebAuthnCredential(credentialID) { - let form = new FormData() - form.append("credentialID", credentialID) + let form = new FormData(); + form.append("credentialID", credentialID); + return fetch(`${Setting.ServerUrl}/api/webauthn/delete-credential`, { method: "POST", credentials: "include", body: form, dataType: "text" - }).then(res => res.json()) + }).then(res => res.json()); } // Base64 to ArrayBuffer @@ -74,5 +75,5 @@ export function webAuthnBufferEncode(value) { return btoa(String.fromCharCode.apply(null, new Uint8Array(value))) .replace(/\+/g, "-") .replace(/\//g, "_") - .replace(/=/g, "");; + .replace(/=/g, ""); }