Skip to content

Commit

Permalink
feat: v3.1
Browse files Browse the repository at this point in the history
  • Loading branch information
lulu-tro committed Aug 26, 2024
1 parent 7d439e1 commit 61a1c3c
Show file tree
Hide file tree
Showing 17 changed files with 657 additions and 187 deletions.
23 changes: 23 additions & 0 deletions src/APIClient/APIClient10.js
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,29 @@ class APIClient10 {
return this.request(`/api/v1/accesskey/delete/${key}`);
}

//login
checkLoginPassword() {
return this.request(`/api/v1/dashboard/check`);
}
setLoginPassword(arg){
return this.request(`/api/v1/dashboard/set?arg=${arg}`);
}
login(){
return this.request(`/api/v1/dashboard/login`);
}
loginValidate(){
return this.request(`/api/v1/dashboard/validate`);
}
changePassword(){
return this.request(`/api/v1/dashboard/change`);
}
resetLoginPassword(){
return this.request(`/api/v1/dashboard/reset`);
}
logout(){
return this.request(`/api/v1/dashboard/logout`);
}

}

const Client10 = new APIClient10();
Expand Down
41 changes: 29 additions & 12 deletions src/components/Cards/CardSettings.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { Tooltip } from 'antd';
import { QuestionCircleOutlined } from '@ant-design/icons';
import { mainContext } from 'reducer';
import Emitter from 'utils/eventBus';
import {useHistory } from 'react-router-dom';

import { nodeStatusCheck, getPrivateKey, getRepo, setApiUrl } from 'services/otherService.js';
import { t } from 'utils/text.js';
import { urlCheck } from 'utils/checks.js';
Expand All @@ -14,6 +16,9 @@ import S3CardConfig from './S3CardConfig';
import { getParameterByName } from 'utils/BTFSUtil.js';
import { MAIN_PAGE_MODE } from 'utils/constants';

import { logout } from 'services/login.js';


export default function CardSettings({ color }) {
const apiUrl = getParameterByName('api', window.location.href);
let NODE_URL = localStorage.getItem('NODE_URL')
Expand All @@ -23,6 +28,7 @@ export default function CardSettings({ color }) {
setApiUrl(apiUrl);
NODE_URL = apiUrl;
}
const history = useHistory();
const inputRef = useRef(null);
const { dispatch, state } = useContext(mainContext);
const { pageMode } = state;
Expand Down Expand Up @@ -50,14 +56,14 @@ export default function CardSettings({ color }) {
// e.preventDefault();
Emitter.emit('openCheckPrivateKeyModal');

// let { privateKey } = await getPrivateKey();
// if (privateKey) {
// Emitter.emit('openMessageModal', { message: privateKey });
// } else {
// Emitter.emit('showMessageAlert', { message: 'api_not_set', status: 'error', type: 'frontEnd' });
// }

};
const changePassowrd = async () => {
// e.preventDefault();
Emitter.emit('openChangePasswordModal');
};


const getPath = async () => {
let { path, size } = await getRepo();
setPath(path);
Expand Down Expand Up @@ -94,6 +100,11 @@ export default function CardSettings({ color }) {
}
};

const logout = async ()=>{
await logout()
history.push('/login');
}

const changePath = async e => {
console.log('pathRef.current.value', pathRef.current.value);
Emitter.emit('openPathConfirmModal', { type: 'init', path: pathRef.current.value, volume: volume });
Expand Down Expand Up @@ -129,9 +140,10 @@ export default function CardSettings({ color }) {
defaultValue="http://localhost:5001"
ref={inputRef}
onChange={handleChange}
disabled
/>
<button className="ml-2 common-btn theme-common-btn" type="button" onClick={save}>
{t('submit')}
<button className="ml-2 common-btn theme-common-btn" type="button" onClick={logout}>
{t('logout')}
</button>
</div>
</div>
Expand Down Expand Up @@ -162,11 +174,16 @@ export default function CardSettings({ color }) {
<div className="mb-2 setting-header">
<h5 className="font-bold theme-text-main">{t('security')}</h5>
</div>
<div className="flex justify-between mb-2">
<div className="px-3.5 w-full h-9 rounded-lg flex items-center block text-xs font-bold leading-none transition-all theme-bg ">
<span>{t('setting_login_password')}</span>
</div>
<button className="ml-2 common-btn theme-common-btn" type="button" onClick={changePassowrd} style={{minWidth: 'auto'}}>
{t('setting_login_password_btn')}
</button>
</div>
<div className="flex justify-between">
<div className="px-3.5 w-full h-9 border rounded-lg flex items-center text-sm leading-none transition-all theme-border-color theme-bg theme-text-sub-info">
<span className='mr-2'>
<i className="fa-solid fa-lock"></i>
</span>
<div className="px-3.5 w-full h-9 rounded-lg flex items-center block text-xs font-bold leading-none transition-all theme-bg ">
<span>{t('private_key')}</span>
</div>
<button className="ml-2 common-btn theme-danger-btn" type="button" onClick={reveal} style={{minWidth: 'auto'}}>
Expand Down
70 changes: 64 additions & 6 deletions src/components/Login/Endpoint.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,83 @@
import React, { useContext } from 'react';
import React, { useContext,useState ,useRef,useEffect} from 'react';
import { mainContext } from 'reducer';
import { Dropdown, Menu } from 'antd';
import themeStyle from 'utils/themeStyle.js';
import { QuestionCircleOutlined } from '@ant-design/icons';
import Emitter from 'utils/eventBus';

import { nodeStatusCheck, getPrivateKey, getRepo, setApiUrl } from 'services/otherService.js';
import { urlCheck } from 'utils/checks.js';

import { Tooltip } from 'antd';
import { Truncate } from 'utils/text.js';
import { t } from 'utils/text.js';
import ClipboardCopy from 'components/Utils/ClipboardCopy';




const Endpoint = ({ color }) => {
// const { dispatch, state } = useContext(mainContext);
// const { account } = state;
const inputRef = useRef(null);
const { dispatch, state } = useContext(mainContext);
const [endpoint, setEndpoint] = useState('');
const [loading, setLoading] = useState(false);

const save = (e, wallet) => {
// connect(wallet, dispatch);

const getEndpoint = ()=>{
const NODE_URL = localStorage.getItem('NODE_URL');
console.log(NODE_URL)
if(NODE_URL){
inputRef.current.value = NODE_URL;
}
// const isMainMode = await getPageMode();
}

const getNodeUrl = () => {
let node_url = inputRef.current.value.replace(/\s*/g, '');
if (node_url.charAt(node_url.length - 1) === '/') {
node_url = node_url.substr(0, node_url.length - 1);
}
if (!urlCheck(node_url)) {
return null;
}
return node_url;
};

const save = async (e, wallet) => {
const node_url2 = getNodeUrl();
Emitter.emit('handleEndpoint', node_url2);
return
const node_url = getNodeUrl();
if (!node_url) return;
let result = await nodeStatusCheck(node_url);
if (result) {
window.nodeStatus = true;
dispatch({
type: 'SET_NODE_STATUS',
nodeStatus: true,
});
// getPath();
// Emitter.emit('showMessageAlert', { message: 'setting_success', status: 'success', type: 'frontEnd' });
// Emitter.emit('getHostId')
Emitter.emit('handleEndpoint', node_url);
} else {
// setPath('');
// Emitter.emit('showMessageAlert', { message: 'setting_error', status: 'error', type: 'frontEnd' });
}
// Emitter.emit('handleEndpoint', {});
// Emitter.emit('handleEndpoint', { checked, parentIndex, childIndex });
};

const handleChange = () => {
// disConnect(dispatch);
const handleChange = (e) => {
setEndpoint(e.target.value);
};

useEffect(() => {
getEndpoint()
}, []);

return (
<div className="flex flex-col justify-center max-w-515px">
<div className=" min-h-400">
Expand All @@ -40,7 +98,7 @@ const Endpoint = ({ color }) => {
type="text"
className="mr-2 common-input theme-bg theme-border-color"
defaultValue="http://localhost:5001"
// ref={inputRef}
ref={inputRef}
onChange={handleChange}
/>
<button className="mt-5 common-btn theme-common-btn login-btn" type="button" onClick={save}>
Expand Down
38 changes: 30 additions & 8 deletions src/components/Login/PasswordLogin.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,31 @@ import { Tooltip, Form, Input, Button } from 'antd';
import { Truncate } from 'utils/text.js';
import { t } from 'utils/text.js';
import ClipboardCopy from 'components/Utils/ClipboardCopy';
import { aseEncode } from 'utils/BTFSUtil';
import Emitter from 'utils/eventBus';

const Endpoint = ({ color }) => {


import { login } from 'services/login.js';

const PasswordLogin = ({ color,endpoint }) => {
// const { dispatch, state } = useContext(mainContext);
// const { account } = state;

const onFinish = (values: any) => {
console.log(values, '-------aaaa');
const onFinish =async (values: any) => {
let password = values.password
let psw = aseEncode(password,endpoint)
let res = await login(psw)
if(res){

}

};

const LostPassword = ()=>{
Emitter.emit('handleLostPassword')
}

return (
<div className="flex flex-col justify-center max-w-515px min-w-334px">
<div className="min-h-400">
Expand All @@ -29,7 +45,7 @@ const Endpoint = ({ color }) => {
// labelWrap={true}
labelCol={{ span: 24 }}
// wrapperCol={{ span: 16 }}
// initialValues={{ remember: true }}
initialValues={{endpoint }}
onFinish={onFinish}
// onFinishFailed={onFinishFailed}
autoComplete="off">
Expand All @@ -49,20 +65,26 @@ const Endpoint = ({ color }) => {
<h5 className="font-bold theme-text-main shrink-0" htmlFor="grid-password">
{t('login_password')}
</h5>
<span className="text-sm font-medium theme-text-base">
<span className="text-sm font-medium theme-text-base cursor-pointer" onClick={LostPassword}>
{t('lost_password')}
</span>
</div>
}
name="password"
rules={[{ required: true, message: 'Please input your password!' }]}>
rules={[
{ required: true, message: t('password_validate_required') },
{
pattern: /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)[a-zA-Z\d]{8,}$/,
message: t('password_validate_pattern'),
},
]}>
<Input.Password className="mr-2 common-input theme-bg theme-border-color" />
</Form.Item>
<Form.Item>
<button
className="mt-5 common-btn theme-common-btn login-btn"
type="primary"
htmlType="submit">
>
{t('next')}
</button>
</Form.Item>
Expand All @@ -72,4 +94,4 @@ const Endpoint = ({ color }) => {
);
};

export default Endpoint;
export default PasswordLogin;
Loading

0 comments on commit 61a1c3c

Please sign in to comment.