Added E-Mail Account Saving
This commit is contained in:
@@ -7,7 +7,7 @@ import {secrets} from "../utils/secrets";
|
|||||||
export default async function emailAsUserRoutes(server: FastifyInstance) {
|
export default async function emailAsUserRoutes(server: FastifyInstance) {
|
||||||
|
|
||||||
// Create E-Mail Account
|
// Create E-Mail Account
|
||||||
server.post("/email/accounts/", async (req, reply) => {
|
server.post("/email/accounts/:id?", async (req, reply) => {
|
||||||
if (!req.user?.tenant_id) {
|
if (!req.user?.tenant_id) {
|
||||||
return reply.code(400).send({ error: "No tenant selected" });
|
return reply.code(400).send({ error: "No tenant selected" });
|
||||||
}
|
}
|
||||||
@@ -23,6 +23,34 @@ export default async function emailAsUserRoutes(server: FastifyInstance) {
|
|||||||
imap_ssl: boolean
|
imap_ssl: boolean
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if(req.params.id) {
|
||||||
|
//SAVE Existing
|
||||||
|
let saveData = {
|
||||||
|
email_encrypted: body.email ? encrypt(body.email) : undefined,
|
||||||
|
password_encrypted: body.password ? encrypt(body.password) : undefined,
|
||||||
|
smtp_host_encrypted: body.smtp_host ? encrypt(body.smtp_host) : undefined,
|
||||||
|
smtp_port: body.smtp_port,
|
||||||
|
smtp_ssl: body.smtp_ssl,
|
||||||
|
imap_host_encrypted: body.imap_host ? encrypt(body.imap_host) : undefined,
|
||||||
|
imap_port: body.imap_port,
|
||||||
|
imap_ssl: body.imap_ssl,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
const { data, error } = await server.supabase
|
||||||
|
.from("user_credentials")
|
||||||
|
.update(saveData)
|
||||||
|
.eq("id", req.params.id)
|
||||||
|
.select("*")
|
||||||
|
.single();
|
||||||
|
|
||||||
|
if (error) {
|
||||||
|
return reply.code(400).send({ error: error.message });
|
||||||
|
} else {
|
||||||
|
return reply.send({success: true})
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
//Create New
|
||||||
let createData = {
|
let createData = {
|
||||||
user_id: req.user.user_id,
|
user_id: req.user.user_id,
|
||||||
email_encrypted: encrypt(body.email),
|
email_encrypted: encrypt(body.email),
|
||||||
@@ -46,9 +74,13 @@ export default async function emailAsUserRoutes(server: FastifyInstance) {
|
|||||||
|
|
||||||
if (error) {
|
if (error) {
|
||||||
return reply.code(400).send({ error: error.message });
|
return reply.code(400).send({ error: error.message });
|
||||||
|
} else {
|
||||||
|
return reply.send({success: true})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return data;
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
server.get("/email/accounts/:id?", async (req, reply) => {
|
server.get("/email/accounts/:id?", async (req, reply) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user