chore: update token related logic

This commit is contained in:
JustSong
2022-11-11 20:02:28 +08:00
parent e1d09aa58f
commit d42b4511cf
6 changed files with 71 additions and 55 deletions
+1 -13
View File
@@ -1,7 +1,7 @@
import React, { useEffect, useState } from 'react';
import { Button, Form, Image, Modal } from 'semantic-ui-react';
import { Link } from 'react-router-dom';
import { API, copy, showError, showSuccess } from '../helpers';
import { API, showError, showSuccess } from '../helpers';
const PersonalSetting = () => {
const [inputs, setInputs] = useState({
@@ -25,17 +25,6 @@ const PersonalSetting = () => {
setInputs((inputs) => ({ ...inputs, [name]: value }));
};
const generateToken = async () => {
const res = await API.get('/api/user/token');
const { success, message, data } = res.data;
if (success) {
await copy(data);
showSuccess(`令牌已重置并已复制到剪切板:${data}`);
} else {
showError(message);
}
};
const bindWeChat = async () => {
if (inputs.wechat_verification_code === '') return;
const res = await API.get(
@@ -86,7 +75,6 @@ const PersonalSetting = () => {
<Button as={Link} to={`/user/edit/`}>
更新个人信息
</Button>
<Button onClick={generateToken}>生成访问令牌</Button>
<Button
onClick={() => {
setShowWeChatBindModal(true);
+47 -22
View File
@@ -13,9 +13,18 @@ const EditUser = () => {
password: '',
github_id: '',
wechat_id: '',
email:''
email: '',
token: '',
});
const { username, display_name, password, github_id, wechat_id, email } = inputs;
const {
username,
display_name,
password,
github_id,
wechat_id,
email,
token,
} = inputs;
const handleInputChange = (e, { name, value }) => {
setInputs((inputs) => ({ ...inputs, [name]: value }));
};
@@ -30,6 +39,9 @@ const EditUser = () => {
const { success, message, data } = res.data;
if (success) {
data.password = '';
if (data.token === ' ') {
data.token = '';
}
setInputs(data);
} else {
showError(message);
@@ -58,64 +70,77 @@ const EditUser = () => {
return (
<>
<Segment loading={loading}>
<Header as="h3">更新用户信息</Header>
<Form autoComplete="off">
<Header as='h3'>更新用户信息</Header>
<Form autoComplete='off'>
<Form.Field>
<Form.Input
label="用户名"
name="username"
label='用户名'
name='username'
placeholder={'请输入新的用户名'}
onChange={handleInputChange}
value={username}
autoComplete="off"
autoComplete='off'
/>
</Form.Field>
<Form.Field>
<Form.Input
label="密码"
name="password"
label='密码'
name='password'
type={'password'}
placeholder={'请输入新的密码'}
onChange={handleInputChange}
value={password}
autoComplete="off"
autoComplete='off'
/>
</Form.Field>
<Form.Field>
<Form.Input
label="显示名称"
name="display_name"
label='显示名称'
name='display_name'
placeholder={'请输入新的显示名称'}
onChange={handleInputChange}
value={display_name}
autoComplete="off"
autoComplete='off'
/>
</Form.Field>
<Form.Field>
<Form.Input
label="已绑定的 GitHub 账户"
name="github_id"
label='推送鉴权 Token'
name='token'
placeholder={'请输入新的 Token,留空则将 Token 置空'}
onChange={handleInputChange}
value={token}
autoComplete='off'
/>
</Form.Field>
<Form.Field>
<Form.Input
label='已绑定的 GitHub 账户'
name='github_id'
value={github_id}
autoComplete="off"
autoComplete='off'
readOnly
placeholder={'如需绑定请到个人设置页面进行绑定'}
/>
</Form.Field>
<Form.Field>
<Form.Input
label="已绑定的微信账户"
name="wechat_id"
label='已绑定的微信账户'
name='wechat_id'
value={wechat_id}
autoComplete="off"
autoComplete='off'
readOnly
placeholder={'如需绑定请到个人设置页面进行绑定'}
/>
</Form.Field>
<Form.Field>
<Form.Input
label="已绑定的邮箱账户"
name="email"
label='已绑定的邮箱账户'
name='email'
value={email}
autoComplete="off"
autoComplete='off'
readOnly
placeholder={'如需绑定请到个人设置页面进行绑定'}
/>
</Form.Field>
<Button onClick={submit}>提交</Button>