--- /dev/null
+/* Copyright (c) 2019 AT&T Intellectual Property. #\r
+# #\r
+# Licensed under the Apache License, Version 2.0 (the "License"); #\r
+# you may not use this file except in compliance with the License. #\r
+# You may obtain a copy of the License at #\r
+# #\r
+# http://www.apache.org/licenses/LICENSE-2.0 #\r
+# #\r
+# Unless required by applicable law or agreed to in writing, software #\r
+# distributed under the License is distributed on an "AS IS" BASIS, #\r
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #\r
+# See the License for the specific language governing permissions and #\r
+# limitations under the License. #\r
+##############################################################################*/\r
+\r
+\r
+var env = require('config').env;\r
+\r
+module.exports = function(app) {\r
+\r
+ function getLink(type, hash) {\r
+ const url = app.get('otf').url + "account/" + type + '?token=' + hash;\r
+ return url\r
+ }\r
+\r
+ function sendEmail(email) {\r
+ var environment = env.toUpperCase();\r
+ email.subject = "Open Test Framework (" + environment + ") - " + email.subject;\r
+ return app.service(app.get('base-path') + 'mailer').create(email).then(function (result) {\r
+ console.log('Sent email', result)\r
+ }).catch(err => {\r
+ console.log('Error sending email: ', email, err)\r
+ })\r
+ }\r
+\r
+ return {\r
+ notifier: function(type, user, notifierOptions) {\r
+ let tokenLink;\r
+ let email;\r
+ let sender = app.get('otf').email;\r
+ switch (type) {\r
+ case 'resendVerifySignup': //sending the user the verification email\r
+ tokenLink = getLink('verify', user.verifyToken)\r
+ email = {\r
+ from: sender,\r
+ to: user['email'],\r
+ subject: 'Verify Signup',\r
+ html: 'Please verify your email address by clicking the link below.' + '</br>' + tokenLink\r
+\r
+ }\r
+ return sendEmail(email)\r
+ break\r
+\r
+ case 'verifySignup': // confirming verification\r
+ let adminLink = app.get('otf').url + 'user-management?filter=' + user['email'];\r
+\r
+ email = {\r
+ from: sender,\r
+ to: user['email'],\r
+ subject: 'Signup Confirmed',\r
+ html: 'Thanks for verifying your email!' + '</br>' + 'You will be notified when an admin enables your account.'\r
+ }\r
+\r
+ let adminEmail = {\r
+ from: sender,\r
+ to: sender,\r
+ subject: 'Approve Verified User',\r
+ html: 'User has verified their email.' + '</br>' +\r
+ 'Details: ' + '</br>' +\r
+ ' Email: ' + user['email'] + '</br>' +\r
+ ' First Name: ' + user['firstName'] + '</br>' +\r
+ ' Last Name: ' + user['lastName'] + '</br>' +\r
+ '</br>' +\r
+ 'Enable their account by visiting ' + '</br>' + adminLink\r
+ }\r
+ sendEmail(adminEmail);\r
+ return sendEmail(email);\r
+ break\r
+\r
+ case 'sendApprovalNotification':\r
+ email = {\r
+ from: sender,\r
+ to: user['email'],\r
+ subject: 'Approved',\r
+ html: 'Your account has been approved for access.' + '</br>' +\r
+ 'You can now log into the OTF website: ' + app.get('otf').url\r
+\r
+ }\r
+ return sendEmail(email);\r
+ break\r
+\r
+ case 'sendResetPwd':\r
+ tokenLink = getLink('reset', user.resetToken)\r
+ email = {}\r
+ return sendEmail(email)\r
+ break\r
+\r
+ case 'resetPwd':\r
+ tokenLink = getLink('reset', user.resetToken)\r
+ email = {}\r
+ return sendEmail(email)\r
+ break\r
+\r
+ case 'passwordChange':\r
+ email = {}\r
+ return sendEmail(email)\r
+ break\r
+\r
+ case 'identityChange':\r
+ tokenLink = getLink('verifyChanges', user.verifyToken)\r
+ email = {}\r
+ return sendEmail(email)\r
+ break\r
+\r
+ default:\r
+ break\r
+ }\r
+ }\r
+ }\r
+}\r