Make file system an available notifier option for testing purpose

pull/130/head
Clement Michaud 2017-10-08 22:48:20 +02:00
parent 26418278bc
commit 346c559141
3 changed files with 30 additions and 0 deletions

View File

@ -182,6 +182,10 @@ storage:
# registration or a TOTP registration.
# Use only an available configuration: filesystem, gmail
notifier:
# For testing purpose, notifications can be sent in a file
# filesystem:
# filename: /tmp/authelia/notification.txt
# Use your gmail account to send the notifications. You can use an app password.
# gmail:
# username: user@example.com

View File

@ -0,0 +1,22 @@
import * as BluebirdPromise from "bluebird";
import * as util from "util";
import * as Fs from "fs";
import { INotifier } from "./INotifier";
import { Identity } from "../../../types/Identity";
import { FileSystemNotifierConfiguration } from "../configuration/Configuration";
export class FileSystemNotifier implements INotifier {
private filename: string;
constructor(options: FileSystemNotifierConfiguration) {
this.filename = options.filename;
}
notify(identity: Identity, subject: string, link: string): BluebirdPromise<void> {
const content = util.format("Date: %s\nUser: %s\nSubject: %s\nLink: %s", new Date().toString(), identity.userid,
subject, link);
const writeFilePromised: any = BluebirdPromise.promisify(Fs.writeFile);
return writeFilePromised(this.filename, content);
}
}

View File

@ -3,6 +3,7 @@ import { NotifierConfiguration } from "../configuration/Configuration";
import { Nodemailer } from "../../../types/Dependencies";
import { INotifier } from "./INotifier";
import { FileSystemNotifier } from "./FileSystemNotifier";
import { GMailNotifier } from "./GMailNotifier";
import { SmtpNotifier } from "./SmtpNotifier";
@ -14,6 +15,9 @@ export class NotifierFactory {
else if ("smtp" in options) {
return new SmtpNotifier(options.smtp, nodemailer);
}
else if ("filesystem" in options) {
return new FileSystemNotifier(options.filesystem);
}
else {
throw new Error("No available notifier option detected.");
}