improve add account flow
This commit is contained in:
parent
f40b6758de
commit
ae73326820
@ -12,10 +12,10 @@ export default class Account {
|
||||
}
|
||||
|
||||
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) => {
|
||||
registerAccount(addressId, pwd, xoauth, xoauth2, host, port, tls)
|
||||
.then((mailboxId) => {
|
||||
registerAccount(addressId, pwd, xoauth, xoauth2, imapHost, smtpHost, imapPort, smtpPort, tls)
|
||||
.then((mailboxId) => {0
|
||||
res.status(statusCodes.OK).json({ id: mailboxId });
|
||||
})
|
||||
.catch(() => {
|
||||
|
@ -1,12 +1,12 @@
|
||||
import { execQueryAsync, execQueryAsyncWithId } from "./db";
|
||||
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 = `
|
||||
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);
|
||||
}
|
||||
|
||||
|
@ -18,8 +18,10 @@ CREATE TABLE app_account (
|
||||
account_pwd BINARY(22),
|
||||
xoauth VARCHAR(116),
|
||||
xoauth2 VARCHAR(116),
|
||||
host VARCHAR(255) NOT NULL DEFAULT 'localhost',
|
||||
port INT(5) NOT NULL DEFAULT 143,
|
||||
imap_host VARCHAR(255) NOT NULL DEFAULT 'localhost',
|
||||
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,
|
||||
PRIMARY KEY (account_id),
|
||||
FOREIGN KEY (user_id) REFERENCES address(address_id) ON DELETE CASCADE
|
||||
|
@ -6,9 +6,11 @@ export async function getAllAccounts() {
|
||||
app_account.account_id AS id,
|
||||
address.email AS user,
|
||||
app_account.account_pwd AS password,
|
||||
app_account.host AS host,
|
||||
app_account.port AS port,
|
||||
app_account.tls AS tls
|
||||
app_account.imap_host,
|
||||
app_account.imap_port,
|
||||
app_account.smtp_host,
|
||||
app_account.smtp_port,
|
||||
app_account.tls
|
||||
FROM app_account INNER JOIN address
|
||||
WHERE address.address_id = app_account.user_id
|
||||
`;
|
||||
|
@ -14,9 +14,9 @@ export class ImapInstance {
|
||||
this.imap = new Imap({
|
||||
user: account.user,
|
||||
password: account.password,
|
||||
tlsOptions: { servername: account.host },
|
||||
host: account.host,
|
||||
port: account.port,
|
||||
tlsOptions: { servername: account.imap_host },
|
||||
host: account.imap_host,
|
||||
port: account.imap_port,
|
||||
tls: account.tls,
|
||||
});
|
||||
this.account = account;
|
||||
|
@ -5,12 +5,11 @@ export class SmtpInstance {
|
||||
transporter: Transporter;
|
||||
user: string;
|
||||
|
||||
constructor(account: { user: string; password: string }) {
|
||||
// todo store other data
|
||||
constructor(account: { user: string; password: string, smtp_host: string, smtp_port: number }) {
|
||||
this.user = account.user;
|
||||
this.transporter = nodemailer.createTransport({
|
||||
host: "smtp.gmail.com",
|
||||
port: 465,
|
||||
host: account.smtp_host,
|
||||
port: account.smtp_port,
|
||||
secure: true,
|
||||
auth: {
|
||||
user: account.user,
|
||||
|
@ -5,10 +5,12 @@
|
||||
"pwd": { "type": "string" },
|
||||
"xoauth": { "type": "string" },
|
||||
"xoauth2": { "type": "string" },
|
||||
"host": { "type": "string", "format": "hostname" },
|
||||
"port": { "type": "number", "maximum": 65535 },
|
||||
"imapHost": { "type": "string", "format": "hostname" },
|
||||
"smtpHost": { "type": "string", "format": "hostname" },
|
||||
"imapPort": { "type": "number", "maximum": 65535 },
|
||||
"smtpPort": { "type": "number", "maximum": 65535 },
|
||||
"tls": { "type": "boolean" }
|
||||
},
|
||||
"required": ["email", "host", "port", "tls"],
|
||||
"required": ["email", "imapHost", "smtpHost", "imapPort", "smtpPort", "tls"],
|
||||
"additionalProperties": false
|
||||
}
|
@ -142,11 +142,11 @@ function mailChange() {
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div class="field">
|
||||
<Input label="Plain password:" v-model="pwd" type="password" />
|
||||
</div>
|
||||
<!-- <fieldset>
|
||||
<legend>Authentification method</legend>
|
||||
<div class="field">
|
||||
<Input label="Plain password:" v-model="pwd" type="password" />
|
||||
</div>
|
||||
<div class="field">
|
||||
<Input label="Xoauth:" v-model="xoauth" type="text" />
|
||||
</div>
|
||||
|
Loading…
Reference in New Issue
Block a user