improve add account flow

This commit is contained in:
grimhilt 2023-07-16 16:24:30 +02:00
parent f40b6758de
commit ae73326820
8 changed files with 29 additions and 24 deletions

View File

@ -12,10 +12,10 @@ export default class Account {
} }
static async register(body, res: Response) { static async register(body, res: Response) {
const { email, pwd, xoauth, xoauth2, host, port, tls } = body; const { email, pwd, xoauth, xoauth2, imapHost, smtpHost, imapPort, smtpPort, tls } = body;
getAddressId(email).then((addressId) => { getAddressId(email).then((addressId) => {
registerAccount(addressId, pwd, xoauth, xoauth2, host, port, tls) registerAccount(addressId, pwd, xoauth, xoauth2, imapHost, smtpHost, imapPort, smtpPort, tls)
.then((mailboxId) => { .then((mailboxId) => {0
res.status(statusCodes.OK).json({ id: mailboxId }); res.status(statusCodes.OK).json({ id: mailboxId });
}) })
.catch(() => { .catch(() => {

View File

@ -1,12 +1,12 @@
import { execQueryAsync, execQueryAsyncWithId } from "./db"; import { execQueryAsync, execQueryAsyncWithId } from "./db";
import { queryCcId, queryToId, queryFromId } from "./utils/addressQueries"; import { queryCcId, queryToId, queryFromId } from "./utils/addressQueries";
export async function registerAccount(userId, pwd, xoauth, xoauth2, host, port, tls) { export async function registerAccount(userId, pwd, xoauth, xoauth2, imapHost, smtpHost, imapPort, smtpPort, tls) {
const query = ` const query = `
INSERT INTO app_account INSERT INTO app_account
(user_id, account_pwd, xoauth, xoauth2, host, port, tls) VALUES (?, ?, ?, ?, ?, ?, ?) (user_id, account_pwd, xoauth, xoauth2, imap_host, smtp_host, imap_port, smtp_port, tls) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)
`; `;
const values = [userId, pwd, xoauth, xoauth2, host, port, tls]; const values = [userId, pwd, xoauth, xoauth2, imapHost, smtpHost, imapPort, smtpPort, tls];
return await execQueryAsyncWithId(query, values); return await execQueryAsyncWithId(query, values);
} }

View File

@ -18,8 +18,10 @@ CREATE TABLE app_account (
account_pwd BINARY(22), account_pwd BINARY(22),
xoauth VARCHAR(116), xoauth VARCHAR(116),
xoauth2 VARCHAR(116), xoauth2 VARCHAR(116),
host VARCHAR(255) NOT NULL DEFAULT 'localhost', imap_host VARCHAR(255) NOT NULL DEFAULT 'localhost',
port INT(5) NOT NULL DEFAULT 143, imap_port INT(5) NOT NULL DEFAULT 993,
smtp_host VARCHAR(255) NOT NULL DEFAULT 'localhost',
smtp_port INT(5) NOT NULL DEFAULT 465,
tls BOOLEAN NOT NULL DEFAULT true, tls BOOLEAN NOT NULL DEFAULT true,
PRIMARY KEY (account_id), PRIMARY KEY (account_id),
FOREIGN KEY (user_id) REFERENCES address(address_id) ON DELETE CASCADE FOREIGN KEY (user_id) REFERENCES address(address_id) ON DELETE CASCADE

View File

@ -6,9 +6,11 @@ export async function getAllAccounts() {
app_account.account_id AS id, app_account.account_id AS id,
address.email AS user, address.email AS user,
app_account.account_pwd AS password, app_account.account_pwd AS password,
app_account.host AS host, app_account.imap_host,
app_account.port AS port, app_account.imap_port,
app_account.tls AS tls app_account.smtp_host,
app_account.smtp_port,
app_account.tls
FROM app_account INNER JOIN address FROM app_account INNER JOIN address
WHERE address.address_id = app_account.user_id WHERE address.address_id = app_account.user_id
`; `;

View File

@ -14,9 +14,9 @@ export class ImapInstance {
this.imap = new Imap({ this.imap = new Imap({
user: account.user, user: account.user,
password: account.password, password: account.password,
tlsOptions: { servername: account.host }, tlsOptions: { servername: account.imap_host },
host: account.host, host: account.imap_host,
port: account.port, port: account.imap_port,
tls: account.tls, tls: account.tls,
}); });
this.account = account; this.account = account;

View File

@ -5,12 +5,11 @@ export class SmtpInstance {
transporter: Transporter; transporter: Transporter;
user: string; user: string;
constructor(account: { user: string; password: string }) { constructor(account: { user: string; password: string, smtp_host: string, smtp_port: number }) {
// todo store other data
this.user = account.user; this.user = account.user;
this.transporter = nodemailer.createTransport({ this.transporter = nodemailer.createTransport({
host: "smtp.gmail.com", host: account.smtp_host,
port: 465, port: account.smtp_port,
secure: true, secure: true,
auth: { auth: {
user: account.user, user: account.user,

View File

@ -5,10 +5,12 @@
"pwd": { "type": "string" }, "pwd": { "type": "string" },
"xoauth": { "type": "string" }, "xoauth": { "type": "string" },
"xoauth2": { "type": "string" }, "xoauth2": { "type": "string" },
"host": { "type": "string", "format": "hostname" }, "imapHost": { "type": "string", "format": "hostname" },
"port": { "type": "number", "maximum": 65535 }, "smtpHost": { "type": "string", "format": "hostname" },
"imapPort": { "type": "number", "maximum": 65535 },
"smtpPort": { "type": "number", "maximum": 65535 },
"tls": { "type": "boolean" } "tls": { "type": "boolean" }
}, },
"required": ["email", "host", "port", "tls"], "required": ["email", "imapHost", "smtpHost", "imapPort", "smtpPort", "tls"],
"additionalProperties": false "additionalProperties": false
} }

View File

@ -142,11 +142,11 @@ function mailChange() {
/> />
</div> </div>
<div class="field">
<Input label="Plain password:" v-model="pwd" type="password" />
</div>
<!-- <fieldset> <!-- <fieldset>
<legend>Authentification method</legend> <legend>Authentification method</legend>
<div class="field">
<Input label="Plain password:" v-model="pwd" type="password" />
</div>
<div class="field"> <div class="field">
<Input label="Xoauth:" v-model="xoauth" type="text" /> <Input label="Xoauth:" v-model="xoauth" type="text" />
</div> </div>