diff --git a/src/APIClient/APIClient10.js b/src/APIClient/APIClient10.js index 4c00a8a..9400e55 100644 --- a/src/APIClient/APIClient10.js +++ b/src/APIClient/APIClient10.js @@ -6,10 +6,10 @@ import Cookies from 'js-cookie'; class APIClient10 { constructor() { this.apiUrl = localStorage.getItem('NODE_URL') ? localStorage.getItem('NODE_URL') : "http://localhost:5001"; + this.token = Cookies.get(this.apiUrl) || ''; this.request = async (url, body, config) => { const isFormData = body instanceof FormData - const token = Cookies.get(this.apiUrl) || ''; - const addToken = url.includes('?')? `&token=${token}` : `?token=${token}` + const addToken = url.includes('?')? `&token=${this.token}` : `?token=${this.token}` return new Promise(async (resolve, reject) => { try { @@ -67,6 +67,10 @@ class APIClient10 { this.apiUrl = url; } + updateToken() { + this.token = Cookies.get(this.apiUrl) || '' + } + getHostVersion() { return this.request('/api/v1/version'); diff --git a/src/components/Login/PasswordLogin.js b/src/components/Login/PasswordLogin.js index 7a311cc..b60ede7 100644 --- a/src/components/Login/PasswordLogin.js +++ b/src/components/Login/PasswordLogin.js @@ -1,7 +1,7 @@ -import React, {useState, useEffect } from 'react'; +import React, { useState, useEffect } from 'react'; import { useIntl } from 'react-intl'; -import {useHistory } from 'react-router-dom'; -import { Form, Input } from 'antd'; +import { useHistory } from 'react-router-dom'; +import { Form, Input } from 'antd'; import { t } from 'utils/text.js'; import { aseEncode } from 'utils/BTFSUtil'; import { ArrowLeftOutlined } from '@ant-design/icons'; @@ -10,6 +10,7 @@ import Cookies from 'js-cookie'; import Emitter from 'utils/eventBus'; import { login } from 'services/login.js'; +import { updateLoginToken } from 'services/otherService'; const PasswordLogin = ({ color, endpoint }) => { const history = useHistory(); @@ -26,6 +27,7 @@ const PasswordLogin = ({ color, endpoint }) => { let res = await login(psw); if (res && res.Success) { Cookies.set(endpoint, res.Text, { expires: 1 }); + updateLoginToken(); history.push('/admin/settings'); } else { setTimes(times + 1); @@ -34,12 +36,15 @@ const PasswordLogin = ({ color, endpoint }) => { }; const LostPassword = () => { + if (isLock) { + return; + } Emitter.emit('handleLostPassword'); }; - const backPrevious = ()=>{ + const backPrevious = () => { Emitter.emit('showEndpoint'); - } + }; useEffect(() => { if (times >= 5) { @@ -64,7 +69,12 @@ const PasswordLogin = ({ color, endpoint }) => { return (
-
{t('login_title')}
+
+ + + + {t('login_title')} +
{ API {t('endpoint')}
} name="endpoint"> - + { }, ]}> + placeholder={intl.formatMessage({ id: 'enter_password_placeholder' })} + className="mr-2 common-input theme-bg theme-border-color theme-text-main" + />
{validateMsg} diff --git a/src/components/Modals/ChangePasswordModal.js b/src/components/Modals/ChangePasswordModal.js index bb02a94..4c4e010 100644 --- a/src/components/Modals/ChangePasswordModal.js +++ b/src/components/Modals/ChangePasswordModal.js @@ -1,5 +1,8 @@ import React, { useEffect, useState } from 'react'; import { useIntl } from 'react-intl'; +import { useHistory } from 'react-router-dom'; +import { logout } from 'services/login.js'; + import { LoadingOutlined } from '@ant-design/icons'; import { Spin, Form, Input } from 'antd'; import Emitter from 'utils/eventBus'; @@ -14,6 +17,7 @@ export default function ChangePasswordModal({ color }) { const [form] = Form.useForm(); const [showModal, setShowModal] = useState(false); const [loading, setLoading] = useState(false); + const history = useHistory(); useEffect(() => { const set = async function (params) { @@ -60,6 +64,9 @@ export default function ChangePasswordModal({ color }) { type: 'frontEnd', }); closeModal(); + await logout(); + Cookies.remove(NODE_URL); + history.push('/login'); } else { Emitter.emit('showMessageAlert', { message: 'change_password_fail', @@ -104,9 +111,7 @@ export default function ChangePasswordModal({ color }) { onFinish={onFinish} autoComplete="off"> {t('enter_old_password')}
- } + label={
{t('enter_old_password')}
} name="oldpassword" rules={[ { required: true, message: t('private_key_validate_required') }, diff --git a/src/components/Modals/EncryptFileModal.js b/src/components/Modals/EncryptFileModal.js index 0a34577..fecbc46 100644 --- a/src/components/Modals/EncryptFileModal.js +++ b/src/components/Modals/EncryptFileModal.js @@ -45,6 +45,8 @@ export default function EncryptFileModal({ color }) { const [isCurHost, setIsCurHost] = useState(true); const [password, setPassword] = useState(''); const [validateKeyMsg, setValidateKeyMsg] = useState(''); + const [path, setPath] = useState(null); + // const controller = useRef(new AbortController()); const init = () => { @@ -61,8 +63,9 @@ export default function EncryptFileModal({ color }) { }; useEffect(() => { const set = async function (params) { - console.log('openEncryptFileModal event has occured'); + console.log('openEncryptFileModal event has occured',params); init(); + setPath(params.path); openModal(); }; Emitter.on('openEncryptFileModal', set); @@ -121,7 +124,7 @@ export default function EncryptFileModal({ color }) { setLoading(true); let hostid = encryptType === 'host' ? hostId : ''; let passwords = encryptType === 'host' ? '' : password; - let result = await encryptUploadFiles(currentFile, hostid, passwords, onUploadProgress(fileName)); + let result = await encryptUploadFiles(currentFile, hostid, passwords,path,onUploadProgress(fileName)); Emitter.emit('openEncryptFileCidModal', result); Emitter.emit('updateFiles'); } catch (e) { diff --git a/src/services/filesService.js b/src/services/filesService.js index 0c45f4a..23ba761 100644 --- a/src/services/filesService.js +++ b/src/services/filesService.js @@ -291,10 +291,12 @@ export const removeFiles = async (hash, name, path, type) => { } }; -export const encryptUploadFiles = async (file, hostId, password, onUploadProgress) => { +export const encryptUploadFiles = async (file, hostId, password,path, onUploadProgress) => { + console.log(file, hostId, password,path, onUploadProgress) try { const formData = new FormData(); formData.append('file', file); + formData.append('path', path); let res = await Client10.encrypt(formData, hostId, password, onUploadProgress); if (res?.Type === 'error') { return Promise.reject(res); diff --git a/src/services/otherService.js b/src/services/otherService.js index 8bdafa7..b355006 100644 --- a/src/services/otherService.js +++ b/src/services/otherService.js @@ -6,6 +6,15 @@ export const setApiUrl = (url) => { try { Client10.setApiUrl(url); setFileServiceApiUrl(url) + updateLoginToken() + } catch (e) { + console.log(e); + } +}; + +export const updateLoginToken = () => { + try { + Client10.updateToken(); } catch (e) { console.log(e); }