Skip to content

Commit

Permalink
modify: 修改登录 api 从 mock 到 nest;修改所有 username 为 account
Browse files Browse the repository at this point in the history
  • Loading branch information
kangood committed Feb 5, 2024
1 parent a87aa14 commit 17608bb
Show file tree
Hide file tree
Showing 18 changed files with 42 additions and 42 deletions.
6 changes: 3 additions & 3 deletions src/_mock/_user.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ import { UserApi } from '@/api/services/userService';
import { USER_LIST } from './assets';

const signIn = rest.post(`/api${UserApi.SignIn}`, async (req, res, ctx) => {
const { username, password } = await req.json();
const { account, password } = await req.json();

const user = USER_LIST.find((item) => item.username === username);
const user = USER_LIST.find((item) => item.account === account);

if (!user || user.password !== password) {
return res(
ctx.json({
status: 10001,
message: 'Incorrect username or password.',
message: 'Incorrect account or password.',
}),
);
}
Expand Down
8 changes: 4 additions & 4 deletions src/_mock/assets.js
Original file line number Diff line number Diff line change
Expand Up @@ -499,19 +499,19 @@ export const ROLE_LIST = [ADMIN_ROLE, TEST_ROLE];
*/
export const DEFAULT_USER = {
id: faker.string.uuid(),
username: '[email protected]',
account: 'lamp',
email: faker.internet.email(),
avatar: faker.image.avatarLegacy(),
createdAt: faker.date.anytime(),
updatedAt: faker.date.recent(),
password: 'demo1234',
password: '123456',
role: ADMIN_ROLE,
permissions: ADMIN_ROLE.permission,
};
export const TEST_USER = {
id: faker.string.uuid(),
username: '[email protected]',
password: 'demo1234',
account: 'lamp_pt',
password: '123456',
email: faker.internet.email(),
avatar: faker.image.avatarLegacy(),
createdAt: faker.date.anytime(),
Expand Down
2 changes: 1 addition & 1 deletion src/api/services/userService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import apiClient from '../apiClient';
import { UserInfo, UserToken } from '#/entity';

export interface SignInReq {
username: string;
account: string;
password: string;
}

Expand Down
4 changes: 2 additions & 2 deletions src/layouts/_common/account-dropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const { VITE_APP_HOMEPAGE: HOMEPAGE } = import.meta.env;
*/
export default function AccountDropdown() {
const { replace } = useRouter();
const { username, email, avatar } = useUserInfo();
const { account, email, avatar } = useUserInfo();
const { clearUserInfoAndToken } = useUserActions();
const { backToLogin } = useLoginStateContext();
const { t } = useTranslation();
Expand Down Expand Up @@ -48,7 +48,7 @@ export default function AccountDropdown() {
const dropdownRender: DropdownProps['dropdownRender'] = (menu) => (
<div style={contentStyle}>
<div className="flex flex-col items-start p-4">
<div>{username}</div>
<div>{account}</div>
<div className="text-gray">{email}</div>
</div>
<Divider style={{ margin: 0 }} />
Expand Down
4 changes: 2 additions & 2 deletions src/locales/lang/en_US/sys.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
"loginSuccessTitle": "Login successful",
"loginSuccessDesc": "Welcome back",

"accountPlaceholder": "Please input username",
"accountPlaceholder": "Please input account",
"passwordPlaceholder": "Please input password",
"confirmPasswordPlaceholder": "Please input confirm password",
"emaildPlaceholder": "Please input email",
Expand All @@ -61,7 +61,7 @@
"policyPlaceholder": "Register after checking",
"diffPwd": "The two passwords are inconsistent",

"userName": "Username",
"account": "Account",
"password": "Password",
"confirmPassword": "Confirm Password",
"email": "Email",
Expand Down
2 changes: 1 addition & 1 deletion src/locales/lang/zh_CN/sys.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
"policyPlaceholder": "勾选后才能注册",
"diffPwd": "两次输入密码不一致",

"userName": "账号",
"account": "账号",
"password": "密码",
"confirmPassword": "确认密码",
"email": "邮箱",
Expand Down
4 changes: 2 additions & 2 deletions src/pages/dashboard/workbench/banner-card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { useUserInfo } from '@/store/userStore';
import { useThemeToken } from '@/theme/hooks';

export default function BannerCard() {
const { username } = useUserInfo();
const { account } = useUserInfo();
const themeToken = useThemeToken();

const bg = `linear-gradient(135deg, ${Color(themeToken.colorPrimaryHover).alpha(0.2)}, ${Color(
Expand All @@ -26,7 +26,7 @@ export default function BannerCard() {
style={{ color: themeToken.colorPrimaryActive }}
>
<h4>Welcome back 👋 </h4>
<h4>{username}</h4>
<h4>{account}</h4>
</div>
<p
style={{ color: themeToken.colorPrimaryTextActive }}
Expand Down
2 changes: 1 addition & 1 deletion src/pages/management/system/user/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export default function RolePage() {
<div className="flex">
<img alt="" src={record.avatar} className="h-10 w-10 rounded-full" />
<div className="ml-2 flex flex-col">
<span className="text-sm">{record.username}</span>
<span className="text-sm">{record.account}</span>
<span style={{ color: colorTextSecondary }} className="text-xs">
{record.email}
</span>
Expand Down
6 changes: 3 additions & 3 deletions src/pages/management/user/account/general-tab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ type FieldType = {
};
export default function GeneralTab() {
const { notification } = App.useApp();
const { avatar, username, email } = useUserInfo();
const { avatar, account, email } = useUserInfo();
const initFormValues = {
name: username,
name: account,
email,
phone: faker.phone.number(),
address: faker.location.county(),
Expand Down Expand Up @@ -58,7 +58,7 @@ export default function GeneralTab() {
>
<Row gutter={16}>
<Col span={12}>
<Form.Item<FieldType> label="Username" name="name">
<Form.Item<FieldType> label="Account" name="name">
<Input />
</Form.Item>
</Col>
Expand Down
4 changes: 2 additions & 2 deletions src/pages/management/user/profile/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import ProjectsTab from './projects-tab';
import TeamsTab from './teams-tab';

function UserProfile() {
const { avatar, username } = useUserInfo();
const { avatar, account } = useUserInfo();
const { colorTextBase } = useThemeToken();
const [currentTabIndex, setcurrentTabIndex] = useState(0);

Expand Down Expand Up @@ -55,7 +55,7 @@ function UserProfile() {
className="ml-6 mt-6 flex flex-col justify-center md:mt-0"
style={{ color: '#fff' }}
>
<span className="mb-2 text-2xl font-medium">{username}</span>
<span className="mb-2 text-2xl font-medium">{account}</span>
<span className="text-center opacity-50 md:text-left">TS FullStack</span>
</div>
</div>
Expand Down
6 changes: 3 additions & 3 deletions src/pages/management/user/profile/profile-tab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ interface DataType {
}

export default function ProfileTab() {
const { username } = useUserInfo();
const { account } = useUserInfo();
const theme = useThemeToken();
const AboutItems = [
{ icon: <Iconify icon="fa-solid:user" size={18} />, label: 'Full Name', val: username },
{ icon: <Iconify icon="fa-solid:user" size={18} />, label: 'Full Name', val: account },
{ icon: <Iconify icon="eos-icons:role-binding" size={18} />, label: 'Role', val: 'Developer' },
{ icon: <Iconify icon="tabler:location-filled" size={18} />, label: 'Country', val: 'USA' },
{ icon: <Iconify icon="ion:language" size={18} />, label: 'Language', val: 'English' },
{ icon: <Iconify icon="ph:phone-fill" size={18} />, label: 'Contact', val: '(123)456-7890' },
{ icon: <Iconify icon="ic:baseline-email" size={18} />, label: 'Email', val: username },
{ icon: <Iconify icon="ic:baseline-email" size={18} />, label: 'Email', val: account },
];

const ConnectionsItems = [
Expand Down
18 changes: 9 additions & 9 deletions src/pages/sys/login/LoginForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ function LoginForm() {

if (loginState !== LoginStateEnum.LOGIN) return null;

const handleFinish = async ({ username, password }: SignInReq) => {
const handleFinish = async ({ account, password }: SignInReq) => {
setLoading(true);
try {
await signIn({ username, password });
await signIn({ account, password });
} finally {
setLoading(false);
}
Expand All @@ -37,7 +37,7 @@ function LoginForm() {
size="large"
initialValues={{
remember: true,
username: DEFAULT_USER.username,
account: DEFAULT_USER.account,
password: DEFAULT_USER.password,
}}
onFinish={handleFinish}
Expand All @@ -48,16 +48,16 @@ function LoginForm() {
description={
<div className="flex flex-col">
<div className="flex">
<ProTag className="flex-shrink-0">Admin {t('sys.login.userName')}:</ProTag>
<ProTag className="flex-shrink-0">Admin {t('sys.login.account')}:</ProTag>
<strong className="ml-1" style={{ color: themeToken.colorInfoTextHover }}>
<span>{DEFAULT_USER.username}</span>
<span>{DEFAULT_USER.account}</span>
</strong>
</div>

<div className="flex">
<ProTag className="flex-shrink-0">Test {t('sys.login.userName')}:</ProTag>
<ProTag className="flex-shrink-0">Test {t('sys.login.account')}:</ProTag>
<strong className="ml-1" style={{ color: themeToken.colorInfoTextHover }}>
<span>{TEST_USER.username}</span>
<span>{TEST_USER.account}</span>
</strong>
</div>

Expand All @@ -74,10 +74,10 @@ function LoginForm() {
</div>

<Form.Item
name="username"
name="account"
rules={[{ required: true, message: t('sys.login.accountPlaceholder') }]}
>
<Input placeholder={t('sys.login.userName')} />
<Input placeholder={t('sys.login.account')} />
</Form.Item>
<Form.Item
name="password"
Expand Down
4 changes: 2 additions & 2 deletions src/pages/sys/login/RegisterForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ function RegisterForm() {
<div className="mb-4 text-2xl font-bold xl:text-3xl">{t('sys.login.signUpFormTitle')}</div>
<Form name="normal_login" size="large" initialValues={{ remember: true }} onFinish={onFinish}>
<Form.Item
name="username"
name="account"
rules={[{ required: true, message: t('sys.login.accountPlaceholder') }]}
>
<Input placeholder={t('sys.login.userName')} />
<Input placeholder={t('sys.login.account')} />
</Form.Item>
<Form.Item
name="email"
Expand Down
6 changes: 3 additions & 3 deletions src/pages/sys/others/kanban/task-detail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,12 @@ export default function TaskDetail({ task }: Props) {
padding: '24px 20px 40px',
}}
>
{comments?.map(({ avatar, username, content, time }) => (
<div key={username} className="flex gap-4">
{comments?.map(({ avatar, account, content, time }) => (
<div key={account} className="flex gap-4">
<Avatar src={avatar} size={40} className="flex-shrink-0" />
<div className="flex flex-grow flex-col flex-wrap gap-1 text-gray">
<div className="flex justify-between">
<Typography.Text>{username}</Typography.Text>
<Typography.Text>{account}</Typography.Text>
<Typography.Text>{dayjs(time).format('DD/MM/YYYY HH:mm')}</Typography.Text>
</div>
<p>{content}</p>
Expand Down
2 changes: 1 addition & 1 deletion src/pages/sys/others/kanban/task-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const fakeComment = (count: number): TaskComment[] => {
const result = [];
for (let index = 0; index < count; index += 1) {
result.push({
username: faker.person.fullName(),
account: faker.person.fullName(),
avatar: faker.image.avatarLegacy(),
content: faker.lorem.lines({ min: 1, max: 3 }),
time: faker.date.past(),
Expand Down
2 changes: 1 addition & 1 deletion src/pages/sys/others/kanban/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export enum TaskTag {
}

export type TaskComment = {
username: string;
account: string;
avatar: string;
content: string;
time: Date;
Expand Down
2 changes: 1 addition & 1 deletion src/store/userStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export const useSignIn = () => {

notification.success({
message: t('sys.login.loginSuccessTitle'),
description: `${t('sys.login.loginSuccessDesc')}: ${data.username}`,
description: `${t('sys.login.loginSuccessDesc')}: ${data.account}`,
duration: 3,
});
} catch (err) {
Expand Down
2 changes: 1 addition & 1 deletion types/entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export interface UserToken {
export interface UserInfo {
id: string;
email: string;
username: string;
account: string;
password?: string;
avatar?: string;
role?: Role;
Expand Down

0 comments on commit 17608bb

Please sign in to comment.