From 346c55914120e24cb3835141ced389a53d5bb6fe Mon Sep 17 00:00:00 2001 From: Clement Michaud Date: Sun, 8 Oct 2017 22:48:20 +0200 Subject: [PATCH] Make file system an available notifier option for testing purpose --- config.template.yml | 4 ++++ .../src/lib/notifiers/FileSystemNotifier.ts | 22 +++++++++++++++++++ server/src/lib/notifiers/NotifierFactory.ts | 4 ++++ 3 files changed, 30 insertions(+) create mode 100644 server/src/lib/notifiers/FileSystemNotifier.ts diff --git a/config.template.yml b/config.template.yml index dfc185f03..0e499d1fe 100644 --- a/config.template.yml +++ b/config.template.yml @@ -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 diff --git a/server/src/lib/notifiers/FileSystemNotifier.ts b/server/src/lib/notifiers/FileSystemNotifier.ts new file mode 100644 index 000000000..efa9c6229 --- /dev/null +++ b/server/src/lib/notifiers/FileSystemNotifier.ts @@ -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 { + 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); + } +} \ No newline at end of file diff --git a/server/src/lib/notifiers/NotifierFactory.ts b/server/src/lib/notifiers/NotifierFactory.ts index 2567db6eb..5e85b525b 100644 --- a/server/src/lib/notifiers/NotifierFactory.ts +++ b/server/src/lib/notifiers/NotifierFactory.ts @@ -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."); }