Browse Source

fix using mailer codes

* remove views/mail dir and move templates to locales dir
Yuki Takei 7 years ago
parent
commit
c289172857

+ 0 - 0
src/server/views/mail/admin/userInvitation.txt → resource/locales/en-US/admin/userInvitation.txt


+ 0 - 0
src/server/views/mail/admin/userWaitingActivation.txt → resource/locales/en-US/admin/userWaitingActivation.txt


+ 14 - 0
resource/locales/ja/admin/userInvitation.txt

@@ -0,0 +1,14 @@
+Hi, {{ email }}
+
+You are invited to our Wiki, you can log in with following account:
+
+Email: {{ email }}
+Password: {{ password }}
+(This password was auto generated. Update required at the first time you logging in)
+
+We are waiting for you!
+{{ url }}
+
+--
+{{ appTitle }}
+{{ url }}

+ 21 - 0
resource/locales/ja/admin/userWaitingActivation.txt

@@ -0,0 +1,21 @@
+Hi, {{ adminUser.name }}
+
+A user registered to {{ appTitle }}.
+
+
+====
+Created user:
+
+Name: {{ createdUser.name }}
+User Name: {{ createdUser.username }}
+Email: {{ createdUser.email }}
+====
+
+Please do some action with following URL:
+{{ url }}/admin/users
+
+
+--
+{{ appTitle }}
+{{ url }}
+

+ 0 - 1
src/server/crowi/index.js

@@ -27,7 +27,6 @@ function Crowi(rootdir, env) {
   this.libDir      = path.join(this.rootDir, 'src/server') + sep;
   this.eventsDir   = path.join(this.libDir, 'events') + sep;
   this.viewsDir    = path.join(this.libDir, 'views') + sep;
-  this.mailDir     = path.join(this.viewsDir, 'mail') + sep;
   this.resourceDir = path.join(this.rootDir, 'resource') + sep;
   this.localeDir   = path.join(this.resourceDir, 'locales') + sep;
   this.tmpDir      = path.join(this.rootDir, 'tmp') + sep;

+ 4 - 4
src/server/models/user.js

@@ -1,11 +1,11 @@
 module.exports = function(crowi) {
-  var debug = require('debug')('growi:models:user')
+  const debug = require('debug')('growi:models:user')
+    , path = require('path')
     , mongoose = require('mongoose')
     , mongoosePaginate = require('mongoose-paginate')
     , uniqueValidator = require('mongoose-unique-validator')
     , crypto = require('crypto')
     , async = require('async')
-    , ObjectId = mongoose.Schema.Types.ObjectId
 
     , STATUS_REGISTERED = 1
     , STATUS_ACTIVE     = 2
@@ -23,7 +23,7 @@ module.exports = function(crowi) {
 
     , userEvent = crowi.event('user')
 
-    , userSchema;
+  let userSchema;
 
   userSchema = new mongoose.Schema({
     userId: String,
@@ -654,7 +654,7 @@ module.exports = function(crowi) {
               mailer.send({
                 to: user.email,
                 subject: 'Invitation to ' + Config.appTitle(config),
-                template: 'admin/userInvitation.txt',
+                template: path.join(crowi.localeDir, 'en-US/admin/userInvitation.txt'),
                 vars: {
                   email: user.email,
                   password: user.password,

+ 2 - 1
src/server/routes/login.js

@@ -3,6 +3,7 @@ module.exports = function(crowi, app) {
 
   const debug = require('debug')('growi:routes:login')
     , logger = require('@alias/logger')('growi:routes:login')
+    , path = require('path')
     , async    = require('async')
     , config = crowi.getConfig()
     , mailer = crowi.getMailer()
@@ -203,7 +204,7 @@ module.exports = function(crowi, app) {
                     mailer.send({
                       to: adminUser.email,
                       subject: '[' + appTitle + ':admin] A New User Created and Waiting for Activation',
-                      template: 'admin/userWaitingActivation.txt',
+                      template: path.join(crowi.localeDir, 'en-US/admin/userWaitingActivation.txt'),
                       vars: {
                         createdUser: userData,
                         adminUser: adminUser,

+ 7 - 2
src/server/service/global-notification.js

@@ -1,4 +1,5 @@
-const debug = require('debug')('growi:service:GlobalNotification');
+const logger = require('@alias/logger')('growi:service:GlobalNotification');
+const path = require('path');
 /**
  * the service class of GlobalNotificationSetting
  */
@@ -54,6 +55,8 @@ class GlobalNotificationService {
       slack: {},
     };
 
+    logger.debug('notifyPageCreate', option);
+
     this.sendNotification(notifications, option);
   }
 
@@ -68,7 +71,7 @@ class GlobalNotificationService {
     const option = {
       mail: {
         subject: `#pageEdit - ${page.creator.username} edited ${page.path}`,
-        template: `../../locales/${lang}/notifications/pageEdit.txt`,
+        template: path.join(this.crowi.localeDir, `${lang}/notifications/pageEdit.txt`),
         vars: {
           appTitle: this.appTitle,
           path: page.path,
@@ -78,6 +81,8 @@ class GlobalNotificationService {
       slack: {},
     };
 
+    logger.debug('notifyPageEdit', option);
+
     this.sendNotification(notifications, option);
   }
 

+ 1 - 2
src/server/util/mailer.js

@@ -12,7 +12,6 @@ module.exports = function(crowi) {
     , config = crowi.getConfig()
     , mailConfig = {}
     , mailer = {}
-    , MAIL_TEMPLATE_DIR = crowi.mailDir
     ;
 
 
@@ -105,7 +104,7 @@ module.exports = function(crowi) {
     if (mailer) {
       var templateVars = config.vars || {};
       return swig.renderFile(
-        MAIL_TEMPLATE_DIR + config.template,
+        config.template,
         templateVars,
         function(err, output) {
           if (err) {