Sfoglia il codice sorgente

Merge pull request #600 from weseek/fix/559-email-broken

Fix/559 email broken
Yuki Takei 7 anni fa
parent
commit
b44eac1569

+ 4 - 0
config/logger/config.dev.js

@@ -11,11 +11,15 @@ module.exports = {
   // 'growi:routes:login': 'debug',
   'growi:routes:login-passport': 'debug',
   'growi:service:PassportService': 'debug',
+  // 'growi:service:GlobalNotification': 'debug',
   // 'growi:lib:importer': 'debug',
   // 'growi:routes:page': 'debug',
   // 'growi-plugin:*': 'debug',
   // 'growi:InterceptorManager': 'debug',
 
+  // email
+  // 'growi:lib:mailer': 'debug',
+
   //// configure level for client
   'growi:app': 'debug',
 };

+ 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,

+ 9 - 8
src/server/routes/login.js

@@ -1,7 +1,9 @@
 module.exports = function(crowi, app) {
   'use strict';
 
-  var debug = require('debug')('growi:routes:login')
+  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()
@@ -10,7 +12,7 @@ module.exports = function(crowi, app) {
     , actions = {};
 
 
-  var clearGoogleSession = function(req) {
+  const clearGoogleSession = function(req) {
     req.session.googleAuthCode
       = req.session.googleId
       = req.session.googleEmail
@@ -18,14 +20,13 @@ module.exports = function(crowi, app) {
       = req.session.googleImage
       = null;
   };
-  var loginSuccess = function(req, res, userData) {
+  const loginSuccess = function(req, res, userData) {
     req.user = req.session.user = userData;
 
     // update lastLoginAt
     userData.updateLastLoginAt(new Date(), (err, uData) => {
       if (err) {
-        console.log(`updateLastLoginAt dumps error: ${err}`);
-        debug(`updateLastLoginAt dumps error: ${err}`);
+        logger.error(`updateLastLoginAt dumps error: ${err}`);
       }
     });
 
@@ -35,7 +36,7 @@ module.exports = function(crowi, app) {
 
     clearGoogleSession(req);
 
-    var jumpTo = req.session.jumpTo;
+    const jumpTo = req.session.jumpTo;
     if (jumpTo) {
       req.session.jumpTo = null;
       return res.redirect(jumpTo);
@@ -45,7 +46,7 @@ module.exports = function(crowi, app) {
     }
   };
 
-  var loginFailure = function(req, res) {
+  const loginFailure = function(req, res) {
     req.flash('warningMessage', 'Sign in failure.');
     return res.redirect('/login');
   };
@@ -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) {