From c3665cb1bb4cffad333373e40ab99581df1d89ee Mon Sep 17 00:00:00 2001 From: yoan <536464346@qq.com> Date: Wed, 28 Aug 2024 14:36:11 +0800 Subject: [PATCH] Add password modification. --- README.md | 8 +- internal/domains/deploy.go | 2 +- ui/src/pages/DashboardLayout.tsx | 12 ++- ui/src/pages/SettingLayout.tsx | 21 +++++ ui/src/pages/setting/Password.tsx | 146 ++++++++++++++++++++++++++++++ ui/src/router.tsx | 12 +++ 6 files changed, 194 insertions(+), 7 deletions(-) create mode 100644 ui/src/pages/SettingLayout.tsx create mode 100644 ui/src/pages/setting/Password.tsx diff --git a/README.md b/README.md index 1800a8f8..c3fc2884 100644 --- a/README.md +++ b/README.md @@ -18,6 +18,7 @@ Certimate 旨在为用户提供一个安全、简便的 SSL 证书管理解决 - [安装](#安装) - [二进制文件](#二进制文件) - [Docker 安装](#docker-安装) + - [默认账号:](#默认账号) - [概念](#概念) - [域名](#域名) - [dns 服务商授权信息](#dns-服务商授权信息) @@ -37,19 +38,18 @@ Certimate 旨在为用户提供一个安全、简便的 SSL 证书管理解决 ./certimate serve ``` -然后在浏览器中访问 http://127.0.0.1:8090 即可访问 Certimate 管理页面。 ### Docker 安装 ```bash -git clone git@github.com:usual2970/certimate.git && cd certimate/docker && docker-compose up -d +git clone git@github.com:usual2970/certimate.git && cd certimate/docker && docker compose up -d ``` -配置 +然后在浏览器中访问 http://127.0.0.1:8090 即可访问 Certimate 管理页面。 -默认账号: +### 默认账号: ```bash 用户名:admin@certimate.fun diff --git a/internal/domains/deploy.go b/internal/domains/deploy.go index ee07bad8..ce628623 100644 --- a/internal/domains/deploy.go +++ b/internal/domains/deploy.go @@ -30,7 +30,7 @@ func deploy(ctx context.Context, record *models.Record) error { currRecord, err := app.GetApp().Dao().FindRecordById("domains", record.Id) history := NewHistory(record) defer history.commit() - +da // ############1.检查域名配置 history.record(checkPhase, "开始检查", nil) diff --git a/ui/src/pages/DashboardLayout.tsx b/ui/src/pages/DashboardLayout.tsx index 0225a2ed..79a31f97 100644 --- a/ui/src/pages/DashboardLayout.tsx +++ b/ui/src/pages/DashboardLayout.tsx @@ -41,6 +41,10 @@ export default function Dashboard() { getPb().authStore.clear(); navigate("/login"); }; + + const handleSettingClick = () => { + navigate("/setting/password"); + }; return ( <> @@ -160,11 +164,15 @@ export default function Dashboard() { - My Account + 账户 + + 设置 + + - Logout + 退出 diff --git a/ui/src/pages/SettingLayout.tsx b/ui/src/pages/SettingLayout.tsx new file mode 100644 index 00000000..40ed51f9 --- /dev/null +++ b/ui/src/pages/SettingLayout.tsx @@ -0,0 +1,21 @@ +import { Toaster } from "@/components/ui/toaster"; +import { Outlet } from "react-router-dom"; + +const SettingLayout = () => { + return ( +
+ +
设置密码
+
+ {/*
+ + 密码 + +
*/} + +
+
+ ); +}; + +export default SettingLayout; diff --git a/ui/src/pages/setting/Password.tsx b/ui/src/pages/setting/Password.tsx new file mode 100644 index 00000000..d917840f --- /dev/null +++ b/ui/src/pages/setting/Password.tsx @@ -0,0 +1,146 @@ +import { Button } from "@/components/ui/button"; +import { + Form, + FormControl, + FormField, + FormItem, + FormLabel, + FormMessage, +} from "@/components/ui/form"; +import { Input } from "@/components/ui/input"; +import { useToast } from "@/components/ui/use-toast"; +import { getErrMessage } from "@/lib/error"; +import { getPb } from "@/repository/api"; +import { zodResolver } from "@hookform/resolvers/zod"; +import { useForm } from "react-hook-form"; +import { useNavigate } from "react-router-dom"; + +import { z } from "zod"; + +const formSchema = z + .object({ + oldPassword: z.string().min(10, { + message: "密码至少10个字符", + }), + newPassword: z.string().min(10, { + message: "密码至少10个字符", + }), + confirmPassword: z.string().min(10, { + message: "密码至少10个字符", + }), + }) + .refine((data) => data.newPassword === data.confirmPassword, { + message: "两次密码不一致", + path: ["confirmPassword"], + }); + +const Password = () => { + const { toast } = useToast(); + const navigate = useNavigate(); + + const form = useForm>({ + resolver: zodResolver(formSchema), + defaultValues: { + oldPassword: "", + newPassword: "", + confirmPassword: "", + }, + }); + + const onSubmit = async (values: z.infer) => { + try { + await getPb().admins.authWithPassword( + getPb().authStore.model?.email, + values.oldPassword + ); + } catch (e) { + const message = getErrMessage(e); + form.setError("oldPassword", { message }); + } + + try { + await getPb().admins.update(getPb().authStore.model?.id, { + password: values.newPassword, + passwordConfirm: values.confirmPassword, + }); + + getPb().authStore.clear(); + toast({ + title: "修改密码成功", + description: "请重新登录", + }); + setTimeout(() => { + navigate("/login"); + }, 500); + } catch (e) { + const message = getErrMessage(e); + toast({ + title: "修改密码失败", + description: message, + variant: "destructive", + }); + } + }; + + return ( + <> +
+ + ( + + 当前密码 + + + + + + + )} + /> + + ( + + 新密码 + + + + + + + )} + /> + + ( + + 确认密码 + + + + + + + )} + /> +
+ +
+ + + + ); +}; + +export default Password; diff --git a/ui/src/router.tsx b/ui/src/router.tsx index b36168bc..9ea85304 100644 --- a/ui/src/router.tsx +++ b/ui/src/router.tsx @@ -7,6 +7,8 @@ import Access from "./pages/access/Access"; import History from "./pages/history/History"; import Login from "./pages/login/Login"; import LoginLayout from "./pages/LoginLayout"; +import Password from "./pages/setting/Password"; +import SettingLayout from "./pages/SettingLayout"; export const router = createHashRouter([ { @@ -29,6 +31,16 @@ export const router = createHashRouter([ path: "/history", element: , }, + { + path: "/setting", + element: , + children: [ + { + path: "/setting/password", + element: , + }, + ], + }, ], }, {