diff --git a/README.md b/README.md index 180f325..03713c3 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # web -![Last Update](https://img.shields.io/badge/last_update-16_Feb_2024-blue) +![Last Update](https://img.shields.io/badge/last_update-24_Feb_2024-blue) [![License: CC0-1.0](https://img.shields.io/badge/License-CC0_1.0-lightgrey.svg)](http://creativecommons.org/publicdomain/zero/1.0/) [![Build Status](https://git.pontusmail.org/librecloud/web/actions/workflows/docker.yaml/badge.svg)](https://git.pontusmail.org/librecloud/web/actions/?workflow=docker.yaml) [![Build Status](https://git.pontusmail.org/librecloud/web/actions/workflows/ci.yaml/badge.svg)](https://git.pontusmail.org/librecloud/web/actions/?workflow=ci.yaml) diff --git a/app/account/dashboard/settings/page.tsx b/app/account/dashboard/settings/page.tsx index 45da57d..215ceb0 100644 --- a/app/account/dashboard/settings/page.tsx +++ b/app/account/dashboard/settings/page.tsx @@ -2,6 +2,10 @@ import { motion } from "framer-motion" import { SideMenu } from "@/components/pages/dashboard/SideMenu" +//import { Switch } from "@/components/ui/switch" +//import { Label } from "@/components/ui/label" +//import { Card } from "@/components/ui/card" +import { ChangePassword } from "@/components/cards/dashboard/Settings/ChangePassword" const fadeIn = { initial: { opacity: 0, y: 20 }, @@ -17,7 +21,50 @@ export default function Settings() {

Settings

-

Coming soon

+
+ + {/* DISABLED FOR NOW + +

UI Settings

+
+
+ + +
+ +
+ + +
+ +
+ + +
+
+
+ + +

Notifications

+
+
+ + +
+ +
+ + +
+ +
+ + +
+
+
+ */} +
diff --git a/app/api/mail/password/route.ts b/app/api/mail/password/route.ts new file mode 100644 index 0000000..29040c4 --- /dev/null +++ b/app/api/mail/password/route.ts @@ -0,0 +1,45 @@ +import { auth } from "@/auth" +import { NextResponse } from "next/server" + +export async function POST(request: Request) { + try { + const session = await auth() + const body = await request.json() + const { password } = body + + if (!session || !session.user?.email) { + return NextResponse.json({ error: "Unauthorized" }, { status: 401 }) + } else if (!password || typeof password !== "string") { + return NextResponse.json({ error: "Invalid password" }, { status: 400 }) + } + + const { email } = session.user + + const response = await fetch(`${process.env.MAIL_CONNECT_API_URL}/accounts/update/password`, { + method: "POST", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify({ email: email, password: password }), + }); + + if (!response.ok) { + return NextResponse.json({ error: "Failed to Update" }, { status: response.status }) + } + + const resData = await response.json() + + if (resData.success) { + return NextResponse.json({ success: true }) + } else if (resData.success === false) { + return NextResponse.json({ error: "Failed to Update" }, { status: 400 }) + } else { + if (resData.error) { console.log("Error:", resData.error) } // sorry, i like this style + return NextResponse.json({ error: "Failed to Update" }, { status: 500 }) + } + } catch (error) { + console.error("mail-connect API error:", error) + return NextResponse.json({ error: "Server error" }, { status: 500 }) + } +} + diff --git a/components/cards/dashboard/Settings/ChangePassword.tsx b/components/cards/dashboard/Settings/ChangePassword.tsx new file mode 100644 index 0000000..8290b1a --- /dev/null +++ b/components/cards/dashboard/Settings/ChangePassword.tsx @@ -0,0 +1,73 @@ +"use client"; + +import { useState } from "react"; +import { Card, CardContent, CardHeader, CardTitle, CardDescription } from "@/components/ui/card"; +import { Input } from "@/components/ui/input"; +import { Button } from "@/components/ui/button"; +import { Label } from "@/components/ui/label"; +import Link from "next/link"; + +export function ChangePassword() { + const [newPassword, setNewPassword] = useState(""); + const [loading, setLoading] = useState(false); + const [message, setMessage] = useState(null); + + const handlePasswordChange = async (e: React.FormEvent) => { + e.preventDefault(); + setLoading(true); + setMessage(null); + try { + const response = await fetch("/api/mail/password", { + method: "POST", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify({ password: newPassword }), + }); + const resData = await response.json(); + + if (response.ok && resData.success) { + setMessage("Password Updated"); + setLoading(false); + } else if (resData.error) { + setMessage(resData.error); + setLoading(false); + } else { + setMessage("[1] Failed to Update"); + setLoading(false); + } + } catch (error) { + console.log(error) + setMessage("[2] Failed to Update"); + setLoading(false); + } + }; + + return ( + + + Change Email Password + Please note, this will NOT change your Authentik password. You can change that here. + + +
+
+ + setNewPassword(e.target.value)} + /> +
+ + {message &&

{message}

} +
+
+
+ ); +} + +export default ChangePassword; \ No newline at end of file