chore: Extract authentication logic of the apps to their own classes

This commit is contained in:
Faruk AYDIN
2021-11-18 12:54:56 +01:00
committed by Ömer Faruk Aydın
parent 6b1dee053f
commit 46321f19f4
23 changed files with 707 additions and 617 deletions

View File

@@ -1,40 +1,9 @@
import nodemailer from 'nodemailer';
import App from '../../models/app';
import Authentication from './authentication';
export default class SMTP {
client: any
connectionData: any
appData: any
authenticationClient: any
constructor(connectionData: any) {
this.client = nodemailer.createTransport({
host: connectionData.host,
port: connectionData.port,
secure: connectionData.useTls,
auth: {
user: connectionData.username,
pass: connectionData.password,
},
});
this.connectionData = connectionData;
this.appData = App.findOneByKey('smtp');
}
async verifyCredentials() {
await this.client.verify()
return {
screenName: this.connectionData.username
}
}
async isStillVerified() {
try {
await this.client.verify()
return true;
} catch(error) {
return false
}
this.authenticationClient = new Authentication(connectionData);
}
}