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 29, 2024
1 parent 61a1c3c commit bf2e1f9
Show file tree
Hide file tree
Showing 26 changed files with 19,706 additions and 16,512 deletions.
3,883 changes: 3,373 additions & 510 deletions package-lock.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"file-type": "^16.5.3",
"ipfs-http-client": "^54.0.0",
"is-ipfs": "6.0.2",
"js-cookie": "^3.0.5",
"moment": "^2.29.4",
"qrcode": "^1.5.0",
"qrcode.react": "^1.0.1",
Expand Down
16 changes: 8 additions & 8 deletions src/APIClient/APIClient10.js
Original file line number Diff line number Diff line change
Expand Up @@ -377,8 +377,8 @@ class APIClient10 {
});
}

decrypt({cid,hostid,password}, body, config) {
return this.request(`/api/v1/decrypt?arg=${cid}&from=${hostid}&p=${password}`, body, config);
decrypt({cid,hostid,password,t}, body, config) {
return this.request(`/api/v1/decrypt?arg=${cid}&from=${hostid}&p=${password}&t=${t}`, body, config);
}

// s3 api
Expand Down Expand Up @@ -415,14 +415,14 @@ class APIClient10 {
setLoginPassword(arg){
return this.request(`/api/v1/dashboard/set?arg=${arg}`);
}
login(){
return this.request(`/api/v1/dashboard/login`);
login(arg){
return this.request(`/api/v1/dashboard/login?arg=${arg}`);
}
loginValidate(){
return this.request(`/api/v1/dashboard/validate`);
loginValidate(arg,token){
return this.request(`/api/v1/dashboard/validate?arg=${arg}&token=${token}`);
}
changePassword(){
return this.request(`/api/v1/dashboard/change`);
changePassword(arg,newpassword,token){
return this.request(`/api/v1/dashboard/change?arg=${arg}&arg=${newpassword}&token=${token}`);
}
resetLoginPassword(){
return this.request(`/api/v1/dashboard/reset`);
Expand Down
Binary file added src/assets/img/background.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 14 additions & 0 deletions src/assets/img/lock-dark.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 14 additions & 0 deletions src/assets/img/lock.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 8 additions & 1 deletion src/assets/styles/main.scss
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,9 @@


.login-bg {
background: #F2F5F7;
// background:;
background: #F2F5F7 url(../img/background.png) no-repeat right;
background-size: contain;

}

Expand Down Expand Up @@ -321,3 +323,8 @@
font-size: 14px;
font-weight: bold;
}


.ant-form-item .ant-input{
background-color: transparent
}
17 changes: 12 additions & 5 deletions src/components/Cards/CardSettings.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,16 @@ export default function CardSettings({ color }) {
const [copyUrl, setCopyUrl] = useState(getCopyUrl(NODE_URL));
const reveal = async () => {
// e.preventDefault();
Emitter.emit('openCheckPrivateKeyModal');

Emitter.emit('openPasswordVerifyModal',{callbackFn:getPrivateKeys});
};

const getPrivateKeys = async () => {
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();
Expand Down Expand Up @@ -100,7 +107,7 @@ export default function CardSettings({ color }) {
}
};

const logout = async ()=>{
const handleLogout = async ()=>{
await logout()
history.push('/login');
}
Expand Down Expand Up @@ -136,13 +143,13 @@ export default function CardSettings({ color }) {
<div className="flex">
<input
type="text"
className="mr-2 common-input theme-bg theme-border-color"
className="mr-2 common-input theme-text-desc theme-base-bg border-none"
defaultValue="http://localhost:5001"
ref={inputRef}
onChange={handleChange}
disabled
/>
<button className="ml-2 common-btn theme-common-btn" type="button" onClick={logout}>
<button className="ml-2 common-btn theme-common-btn" type="button" onClick={handleLogout}>
{t('logout')}
</button>
</div>
Expand Down
39 changes: 39 additions & 0 deletions src/components/Lock/AccountLock.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import React, { useContext, useEffect } from 'react';
import { useHistory } from 'react-router-dom';
import Cookies from 'js-cookie';
import { mainContext } from 'reducer';

const AccountLock = () => {
const { dispatch, state } = useContext(mainContext);
const history = useHistory();

const { theme } = state;
const lockAccount = e => {
e.preventDefault();
e.stopPropagation();
e.nativeEvent.stopImmediatePropagation();

let NODE_URL = localStorage.getItem('NODE_URL')
? localStorage.getItem('NODE_URL')
: 'http://localhost:5001';
Cookies.remove(NODE_URL);
history.push('/login');
};

useEffect(() => {
if (theme === 'dark') {
document.documentElement.classList.add('dark');
} else {
document.documentElement.classList.remove('dark');
}
}, [theme]);

return (
<button onClick={lockAccount} className="ml-2 round-btn theme-round-btn ">
{theme === 'light' && <img src={require(`assets/img/lock.svg`).default} alt="" />}
{theme === 'dark' && <img src={require(`assets/img/lock-dark.svg`).default} alt="" />}
</button>
);
};

export default AccountLock;
102 changes: 62 additions & 40 deletions src/components/Login/PasswordLogin.js
Original file line number Diff line number Diff line change
@@ -1,62 +1,79 @@
import React, { useContext } from 'react';
import { mainContext } from 'reducer';
import { Dropdown, Menu } from 'antd';
import themeStyle from 'utils/themeStyle.js';
import { QuestionCircleOutlined } from '@ant-design/icons';
import { Tooltip, Form, Input, Button } from 'antd';
import { Truncate } from 'utils/text.js';
import React, {useState, useEffect } from 'react';
import { useIntl } from 'react-intl';
import {useHistory } from 'react-router-dom';
import { Form, Input } from 'antd';
import { t } from 'utils/text.js';
import ClipboardCopy from 'components/Utils/ClipboardCopy';
import { aseEncode } from 'utils/BTFSUtil';
import Emitter from 'utils/eventBus';

import Cookies from 'js-cookie';

import Emitter from 'utils/eventBus';

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

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

const onFinish =async (values: any) => {
let password = values.password
let psw = aseEncode(password,endpoint)
let res = await login(psw)
if(res){
const PasswordLogin = ({ color, endpoint }) => {
const history = useHistory();
const intl = useIntl();
const [form] = Form.useForm();
const [times, setTimes] = useState(0);
const [isLock, setIsLock] = useState(false);
const [validateMsg, setValidateMsg] = useState('');

const onFinish = async (values: any) => {
if (isLock) return;
let password = values.password;
let psw = aseEncode(password, endpoint);
let res = await login(psw);
if (res && res.Success) {
Cookies.set(endpoint, res.Text, { expires: 1, domain: 'localhost' });
history.push('/admin/settings');
} else {
setTimes(times + 1);
Emitter.emit('showMessageAlert', { message: res.Text || 'error', status: 'error' });
}
};

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

const LostPassword = ()=>{
Emitter.emit('handleLostPassword')
}
useEffect(() => {
if (times >= 5) {
setIsLock(true);
}
}, [times]);

useEffect(() => {
let timer = null;
if (isLock) {
setValidateMsg(t('login_lock_message'));
timer = setTimeout(() => {
setIsLock(false);
}, 600000);
} else {
setValidateMsg('');
setTimes(0);
}
return () => clearInterval(timer);
}, [isLock]);

return (
<div className="flex flex-col justify-center max-w-515px min-w-334px">
<div className="min-h-400">
<div className="login-title">{t('set_login_password')}</div>
<div className="text-gray-900 text-sm font-bold mb-12">{t('set_login_password_desc')}</div>
<div className="login-title mb-12">{t('login_title')}</div>

<Form
name="basic"
layout="vertical"
form={form}
requiredMark={false}
// labelWrap={true}
labelCol={{ span: 24 }}
// wrapperCol={{ span: 16 }}
initialValues={{endpoint }}
initialValues={{ endpoint }}
onFinish={onFinish}
// onFinishFailed={onFinishFailed}
autoComplete="off">
<Form.Item
label={<div className="font-bold theme-text-main">API {t('endpoint')}</div>}
name="endpoint">
<Input
defaultValue="http://localhost:5001"
className="mr-2 common-input theme-bg theme-border-color"
disabled
/>
<Input className="mr-2 common-input theme-bg theme-border-color" disabled />
</Form.Item>

<Form.Item
Expand All @@ -65,7 +82,9 @@ const PasswordLogin = ({ color,endpoint }) => {
<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 cursor-pointer" onClick={LostPassword}>
<span
className="text-sm font-medium theme-text-base cursor-pointer"
onClick={LostPassword}>
{t('lost_password')}
</span>
</div>
Expand All @@ -74,17 +93,20 @@ const PasswordLogin = ({ color,endpoint }) => {
rules={[
{ required: true, message: t('password_validate_required') },
{
pattern: /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)[a-zA-Z\d]{8,}$/,
pattern: /^(?=.*[a-zA-Z])(?=.*\d)[a-zA-Z\d]{8,}$/,
message: t('password_validate_pattern'),
},
]}>
<Input.Password className="mr-2 common-input theme-bg theme-border-color" />
<Input.Password

placeholder={intl.formatMessage({ id: 'enter_password_placeholder' })}
className="mr-2 common-input theme-bg theme-border-color" />
</Form.Item>
<div className="flex justify-between w-full mt-2 ml-1 ">
<span className="theme-text-error text-xs pt-1">{validateMsg}</span>
</div>
<Form.Item>
<button
className="mt-5 common-btn theme-common-btn login-btn"
type="primary"
>
<button className="mt-5 common-btn theme-common-btn login-btn" type="primary">
{t('next')}
</button>
</Form.Item>
Expand Down
Loading

0 comments on commit bf2e1f9

Please sign in to comment.