You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by an...@apache.org on 2016/02/16 05:42:22 UTC
[1/2] ignite git commit: IGNITE-843 Refactor serve to es6.
Repository: ignite
Updated Branches:
refs/heads/ignite-843-rc2 3e9942e07 -> f80a0384e
IGNITE-843 Refactor serve to es6.
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/42873202
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/42873202
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/42873202
Branch: refs/heads/ignite-843-rc2
Commit: 42873202fea7cf848c5c9f017430eab7783cf961
Parents: 63bd2c0
Author: Andrey <an...@gridgain.com>
Authored: Tue Feb 16 11:42:26 2016 +0700
Committer: Andrey <an...@gridgain.com>
Committed: Tue Feb 16 11:42:26 2016 +0700
----------------------------------------------------------------------
.../src/main/js/serve/mail.js | 71 +++++++++++++++++
.../src/main/js/serve/routes/admin.js | 83 ++++++--------------
.../src/main/js/serve/routes/public.js | 69 ++++------------
.../src/main/js/serve/settings.js | 1 +
4 files changed, 114 insertions(+), 110 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ignite/blob/42873202/modules/control-center-web/src/main/js/serve/mail.js
----------------------------------------------------------------------
diff --git a/modules/control-center-web/src/main/js/serve/mail.js b/modules/control-center-web/src/main/js/serve/mail.js
new file mode 100644
index 0000000..817c5d1
--- /dev/null
+++ b/modules/control-center-web/src/main/js/serve/mail.js
@@ -0,0 +1,71 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+'use strict';
+
+// Fire me up!
+
+module.exports = {
+ implements: 'mail',
+ inject: ['require(nodemailer)', 'settings']
+};
+
+module.exports.factory = function(nodemailer, settings) {
+ return {
+ /**
+ * Send mail to user.
+ * @param {Account} user
+ * @param {String} subject
+ * @param {String} html
+ * @param {String} sendErr
+ *
+ * @return {Promise}
+ */
+ send: (user, subject, html, sendErr) => {
+ const transporter = {
+ service: settings.smtp.service,
+ auth: {
+ user: settings.smtp.email,
+ pass: settings.smtp.password
+ }
+ };
+
+ if (transporter.service === '' || transporter.auth.user === '' || transporter.auth.pass === '')
+ return Promise.reject('Can\'t send e-mail because not configured SMTP server. Please ask webmaster to setup SMTP server!');
+
+ const mailer = nodemailer.createTransport(transporter);
+
+ const sign = settings.smtp.sign ? `<br><br>--------------<br>${settings.smtp.sign}<br>` : '';
+
+ const mail = {
+ from: settings.smtp.address(settings.smtp.username, settings.smtp.email),
+ to: settings.smtp.address(user.username, user.email),
+ subject,
+ html: html + sign
+ };
+
+ return new Promise((resolve, reject) => {
+ mailer.sendMail(mail, (err) => {
+ if (err)
+ return reject(sendErr ? new Error(sendErr) : err);
+
+ resolve(user);
+ });
+ });
+ }
+ };
+};
http://git-wip-us.apache.org/repos/asf/ignite/blob/42873202/modules/control-center-web/src/main/js/serve/routes/admin.js
----------------------------------------------------------------------
diff --git a/modules/control-center-web/src/main/js/serve/routes/admin.js b/modules/control-center-web/src/main/js/serve/routes/admin.js
index 50488b1..ab2760a 100644
--- a/modules/control-center-web/src/main/js/serve/routes/admin.js
+++ b/modules/control-center-web/src/main/js/serve/routes/admin.js
@@ -21,10 +21,10 @@
module.exports = {
implements: 'admin-routes',
- inject: ['require(lodash)', 'require(express)', 'require(nodemailer)', 'settings', 'mongo']
+ inject: ['require(lodash)', 'require(express)', 'require(nodemailer)', 'settings', 'mail', 'mongo']
};
-module.exports.factory = function(_, express, nodemailer, settings, mongo) {
+module.exports.factory = function(_, express, nodemailer, settings, mail, mongo) {
return new Promise((factoryResolve) => {
const router = new express.Router();
@@ -40,65 +40,34 @@ module.exports.factory = function(_, express, nodemailer, settings, mongo) {
// Remove user.
router.post('/remove', (req, res) => {
const userId = req.body.userId;
- let user = {};
mongo.Account.findByIdAndRemove(userId).exec()
- .then((removedUser) => {
- user = removedUser;
+ .then((user) => {
+ res.sendStatus(200);
- return mongo.spaces(userId);
- })
- .then((spaces) => {
- const promises = [];
-
- _.forEach(spaces, (space) => {
- promises.push(mongo.Cluster.remove({space: space._id}).exec());
- promises.push(mongo.Cache.remove({space: space._id}).exec());
- promises.push(mongo.DomainModel.remove({space: space._id}).exec());
- promises.push(mongo.Notebook.remove({space: space._id}).exec());
- promises.push(mongo.Space.remove({owner: space._id}).exec());
- });
-
- return Promise.all(promises);
+ mongo.spaces(userId)
+ .then((spaces) => {
+ const spacesIds = mongo.spacesIds(spaces);
+
+ return Promise.all([
+ mongo.Cluster.remove({space: {$in: spacesIds}}).exec(),
+ mongo.Cache.remove({space: {$in: spacesIds}}).exec(),
+ mongo.DomainModel.remove({space: {$in: spacesIds}}).exec(),
+ mongo.Notebook.remove({space: {$in: spacesIds}}).exec(),
+ mongo.Space.remove({owner: {$in: spacesIds}}).exec()
+ ]);
+ })
+ .catch((err) => {
+ console.error(`Failed to cleanup spaces [user=${user.username}, err=${err}`);
+ });
+
+ return Promise.resolve(user)
})
- .then(() => {
- return new Promise((resolveMail, rejectMail) => {
- const transporter = {
- service: settings.smtp.service,
- auth: {
- user: settings.smtp.email,
- pass: settings.smtp.password
- }
- };
-
- if (transporter.service !== '' || transporter.auth.user !== '' || transporter.auth.pass !== '') {
- const mailer = nodemailer.createTransport(transporter);
-
- const mailOptions = {
- from: settings.smtp.address(settings.smtp.username, settings.smtp.email),
- to: settings.smtp.address(user.username, user.email),
- subject: 'Your account was deleted',
- text: 'You are receiving this e-mail because admin remove your account.\n\n' +
- '--------------\n' +
- settings.smtp.username + ' http://' + req.headers.host + '\n'
- };
-
- mailer.sendMail(mailOptions, (errMailer) => {
- if (errMailer) {
- rejectMail({
- code: 503,
- message: 'Account was removed, but failed to send e-mail notification to user!<br />' + errMailer
- });
- }
- else
- resolveMail();
- });
- }
- else
- rejectMail({code: 503, message: 'Account was removed, but failed to send e-mail notification to user, because mailer is not configured!'});
- });
- })
- .then(() => res.sendStatus(200))
+ .then((user) => mail.send(user, 'Your account was deleted',
+ `Hello ${user.username}!<br><br>` +
+ `You are receiving this e-mail because "${req.user.username}" remove your account.`,
+ 'Account was removed, but failed to send e-mail notification to user!')
+ )
.catch((err) => mongo.handleError(res, err));
});
http://git-wip-us.apache.org/repos/asf/ignite/blob/42873202/modules/control-center-web/src/main/js/serve/routes/public.js
----------------------------------------------------------------------
diff --git a/modules/control-center-web/src/main/js/serve/routes/public.js b/modules/control-center-web/src/main/js/serve/routes/public.js
index b83208d..8eb1b6e 100644
--- a/modules/control-center-web/src/main/js/serve/routes/public.js
+++ b/modules/control-center-web/src/main/js/serve/routes/public.js
@@ -21,10 +21,10 @@
module.exports = {
implements: 'public-routes',
- inject: ['require(express)', 'require(passport)', 'require(nodemailer)', 'settings', 'mongo']
+ inject: ['require(express)', 'require(passport)', 'require(nodemailer)', 'settings', 'mail', 'mongo']
};
-module.exports.factory = function(express, passport, nodemailer, settings, mongo) {
+module.exports.factory = function(express, passport, nodemailer, settings, mail, mongo) {
return new Promise((factoryResolve) => {
const router = new express.Router();
@@ -40,42 +40,6 @@ module.exports.factory = function(express, passport, nodemailer, settings, mongo
return res;
};
- /**
- * Send mail to user.
- * @private
- * @return {Promise}
- */
- const _sendMail = (user, subject, text, sendErrMsg) => {
- const transporter = {
- service: settings.smtp.service,
- auth: {
- user: settings.smtp.email,
- pass: settings.smtp.password
- }
- };
-
- if (transporter.service === '' || transporter.auth.user === '' || transporter.auth.pass === '')
- return Promise.reject('Can\'t send e-mail because not configured SMTP server. Please ask webmaster to setup SMTP server!');
-
- const mailer = nodemailer.createTransport(transporter);
-
- const mail = {
- from: settings.smtp.address(settings.smtp.username, settings.smtp.email),
- to: settings.smtp.address(user.username, user.email),
- subject,
- text: text + (settings.smtp.username ? `\n\n--------------\n${settings.smtp.username}\n` : '')
- };
-
- return new Promise((resolve, reject) => {
- mailer.sendMail(mail, (err) => {
- if (err)
- return reject(sendErrMsg || err.message);
-
- resolve(user);
- });
- });
- };
-
// GET user.
router.post('/user', (req, res) => {
const becomeUsed = req.session.viewedUser && req.user.admin;
@@ -139,13 +103,12 @@ module.exports.factory = function(express, passport, nodemailer, settings, mongo
account.resetPasswordToken = _randomString();
account.save()
- .then(() =>
- _sendMail(account, `Thanks for signing up for ${settings.smtp.username}.`,
- `Hello ${account.username}!\n\n` +
- `You are receiving this e-mail because you (or someone else) signing up on the ${settings.smtp.username}.\n\n` +
- 'If you did not request this, please ignore this email.\n' +
- 'You may reset password by clicking on the following link, or paste this into your browser:\n\n' +
- 'http://' + req.headers.host + '/password/reset?token=' + account.resetPasswordToken));
+ .then(() => mail.send(account, `Thanks for signing up for ${settings.smtp.username}.`,
+ `Hello ${account.username}!<br><br>` +
+ `You are receiving this e-mail because you have signed up to use <a href="http://${req.headers.host}">${settings.smtp.username}</a>.<br><br>` +
+ 'If you have not done the sign up and do not know what this email is about, please ignore it.<br>' +
+ 'You may reset the password by clicking on the following link, or paste this into your browser:<br><br>' +
+ `http://${req.headers.host}/password/reset?token=${account.resetPasswordToken}`));
})
.catch((err) => {
res.status(401).send(err.message);
@@ -194,11 +157,11 @@ module.exports.factory = function(express, passport, nodemailer, settings, mongo
return user.save();
})
- .then((user) =>
- _sendMail(user, 'Password Reset',
- 'You are receiving this because you (or someone else) have requested the reset of the password for your account.\n\n' +
- 'Please click on the following link, or paste this into your browser to complete the process:\n\n' +
- 'http://' + req.headers.host + '/password/reset?token=' + user.resetPasswordToken + '\n\n' +
+ .then((user) => mail.send(user, 'Password Reset',
+ `Hello ${user.username}!<br><br>` +
+ 'You are receiving this because you (or someone else) have requested the reset of the password for your account.<br><br>' +
+ 'Please click on the following link, or paste this into your browser to complete the process:<br><br>' +
+ 'http://' + req.headers.host + '/password/reset?token=' + user.resetPasswordToken + '<br><br>' +
'If you did not request this, please ignore this email and your password will remain unchanged.',
'Failed to send e-mail with reset link!')
)
@@ -230,9 +193,9 @@ module.exports.factory = function(express, passport, nodemailer, settings, mongo
});
})
.then((user) => {
- return _sendMail(user, 'Your password has been changed',
- 'Hello,\n\n' +
- 'This is a confirmation that the password for your account ' + user.email + ' has just been changed.\n\n' +
+ return mail.send(user, 'Your password has been changed',
+ `Hello ${user.username}!<br><br>` +
+ 'This is a confirmation that the password for your account ' + user.email + ' has just been changed.<br><br>' +
'Now you can login: http://' + req.headers.host,
'Password was changed, but failed to send confirmation e-mail!');
})
http://git-wip-us.apache.org/repos/asf/ignite/blob/42873202/modules/control-center-web/src/main/js/serve/settings.js
----------------------------------------------------------------------
diff --git a/modules/control-center-web/src/main/js/serve/settings.js b/modules/control-center-web/src/main/js/serve/settings.js
index f3d19d9..c5f8b84 100644
--- a/modules/control-center-web/src/main/js/serve/settings.js
+++ b/modules/control-center-web/src/main/js/serve/settings.js
@@ -68,6 +68,7 @@ module.exports.factory = function(nconf, fs) {
smtp: {
service: nconf.get('smtp:service'),
username: nconf.get('smtp:username'),
+ sign: nconf.get('smtp:sign'),
email: nconf.get('smtp:email'),
password: nconf.get('smtp:password'),
address: (username, email) => username ? '"' + username + '" <' + email + '>' : email
[2/2] ignite git commit: Merge remote-tracking branch
'origin/ignite-843-rc2' into ignite-843-rc2
Posted by an...@apache.org.
Merge remote-tracking branch 'origin/ignite-843-rc2' into ignite-843-rc2
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/f80a0384
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/f80a0384
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/f80a0384
Branch: refs/heads/ignite-843-rc2
Commit: f80a0384e72d49721b779d8d30fcb7e7882c00c2
Parents: 4287320 3e9942e
Author: Andrey <an...@gridgain.com>
Authored: Tue Feb 16 11:42:45 2016 +0700
Committer: Andrey <an...@gridgain.com>
Committed: Tue Feb 16 11:42:45 2016 +0700
----------------------------------------------------------------------
.../src/main/js/controllers/igfs-controller.js | 7 ++++++-
modules/control-center-web/src/main/js/serve/routes/caches.js | 2 +-
.../control-center-web/src/main/js/serve/routes/clusters.js | 4 ++--
.../control-center-web/src/main/js/serve/routes/domains.js | 7 ++++++-
4 files changed, 15 insertions(+), 5 deletions(-)
----------------------------------------------------------------------