ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From anovi...@apache.org
Subject ignite git commit: IGNITE-843 Refactor serve to es6.
Date Mon, 15 Feb 2016 08:07:52 GMT
Repository: ignite
Updated Branches:
  refs/heads/ignite-843-rc2 471ac276e -> 4f90db196


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/4f90db19
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/4f90db19
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/4f90db19

Branch: refs/heads/ignite-843-rc2
Commit: 4f90db196b350bb90d486c61f7b3935be421330e
Parents: 471ac27
Author: Andrey <anovikov@gridgain.com>
Authored: Mon Feb 15 15:08:11 2016 +0700
Committer: Andrey <anovikov@gridgain.com>
Committed: Mon Feb 15 15:08:11 2016 +0700

----------------------------------------------------------------------
 .../src/main/js/controllers/common-module.js    |   2 +-
 modules/control-center-web/src/main/js/serve.js |   2 +
 .../control-center-web/src/main/js/serve/app.js |   2 +
 .../src/main/js/serve/routes/notebooks.js       |   2 +
 .../src/main/js/serve/routes/profile.js         |   2 +
 .../src/main/js/serve/routes/public.js          | 182 +++++++++----------
 .../src/main/js/views/login.jade                |  28 +--
 7 files changed, 110 insertions(+), 110 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/4f90db19/modules/control-center-web/src/main/js/controllers/common-module.js
----------------------------------------------------------------------
diff --git a/modules/control-center-web/src/main/js/controllers/common-module.js b/modules/control-center-web/src/main/js/controllers/common-module.js
index 585cd1a..2686690 100644
--- a/modules/control-center-web/src/main/js/controllers/common-module.js
+++ b/modules/control-center-web/src/main/js/controllers/common-module.js
@@ -2020,7 +2020,7 @@ consoleModule.controller('resetPassword', [
     '$scope', '$modal', '$http', '$common', '$focus', 'Auth', '$state',
     function ($scope, $modal, $http, $common, $focus, Auth, $state) {
         if ($state.params.token)
-            $http.post('/api/v1/validate/token', {token: $state.params.token})
+            $http.post('/api/v1/password/validate/token', {token: $state.params.token})
                 .success(function (res) {
                     $scope.email = res.email;
                     $scope.token = res.token;

http://git-wip-us.apache.org/repos/asf/ignite/blob/4f90db19/modules/control-center-web/src/main/js/serve.js
----------------------------------------------------------------------
diff --git a/modules/control-center-web/src/main/js/serve.js b/modules/control-center-web/src/main/js/serve.js
index b5897a2..a962539 100644
--- a/modules/control-center-web/src/main/js/serve.js
+++ b/modules/control-center-web/src/main/js/serve.js
@@ -15,6 +15,8 @@
  * limitations under the License.
  */
 
+'use strict';
+
 const http = require('http'),
     https = require('https'),
     path = require('path');

http://git-wip-us.apache.org/repos/asf/ignite/blob/4f90db19/modules/control-center-web/src/main/js/serve/app.js
----------------------------------------------------------------------
diff --git a/modules/control-center-web/src/main/js/serve/app.js b/modules/control-center-web/src/main/js/serve/app.js
index 6d19b44..5f4e4fb 100644
--- a/modules/control-center-web/src/main/js/serve/app.js
+++ b/modules/control-center-web/src/main/js/serve/app.js
@@ -15,6 +15,8 @@
  * limitations under the License.
  */
 
+'use strict';
+
 // Fire me up!
 
 module.exports = {

http://git-wip-us.apache.org/repos/asf/ignite/blob/4f90db19/modules/control-center-web/src/main/js/serve/routes/notebooks.js
----------------------------------------------------------------------
diff --git a/modules/control-center-web/src/main/js/serve/routes/notebooks.js b/modules/control-center-web/src/main/js/serve/routes/notebooks.js
index a595303..a12dacf 100644
--- a/modules/control-center-web/src/main/js/serve/routes/notebooks.js
+++ b/modules/control-center-web/src/main/js/serve/routes/notebooks.js
@@ -15,6 +15,8 @@
  * limitations under the License.
  */
 
+'use strict';
+
 // Fire me up!
 
 module.exports = {

http://git-wip-us.apache.org/repos/asf/ignite/blob/4f90db19/modules/control-center-web/src/main/js/serve/routes/profile.js
----------------------------------------------------------------------
diff --git a/modules/control-center-web/src/main/js/serve/routes/profile.js b/modules/control-center-web/src/main/js/serve/routes/profile.js
index e080ce3..7deff37 100644
--- a/modules/control-center-web/src/main/js/serve/routes/profile.js
+++ b/modules/control-center-web/src/main/js/serve/routes/profile.js
@@ -15,6 +15,8 @@
  * limitations under the License.
  */
 
+'use strict';
+
 // Fire me up!
 
 module.exports = {

http://git-wip-us.apache.org/repos/asf/ignite/blob/4f90db19/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 638bda6..6f78d73 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
@@ -40,6 +40,42 @@ 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();
+                });
+            });
+        };
+
         // GET user.
         router.post('/user', function(req, res) {
             const becomeUsed = req.session.viewedUser && req.user.admin;
@@ -58,40 +94,51 @@ module.exports.factory = function(express, passport, nodemailer, settings,
mongo
         /**
          * Register new account.
          */
-        router.post('/register', function(req, res) {
-            mongo.Account.count(function(errCount, cnt) {
-                if (errCount)
-                    return res.status(401).send(errCount.message);
-
-                req.body.admin = cnt === 0;
-
-                const _account = new mongo.Account(req.body);
+        router.post('/signup', function(req, res) {
+            mongo.Account.count().exec()
+                .then((cnt) => {
+                    req.body.admin = cnt === 0;
 
-                _account.token = _randomString();
+                    req.body.token = _randomString();
 
-                mongo.Account.register(_account, req.body.password, function(errRegister,
account) {
-                    if (errRegister)
-                        return res.status(401).send(errRegister.message);
+                    const account = new mongo.Account(req.body);
 
-                    if (!account)
-                        return res.status(500).send('Failed to create account.');
+                    return Promise.resolve(account);
+                })
+                .then((account) => {
+                    return new Promise((resolve, reject) => {
+                        mongo.Account.register(account, req.body.password, (err, _account)
=> {
+                            if (err)
+                                return reject(err.message);
 
-                    new mongo.Space({name: 'Personal space', owner: account._id}).save();
+                            if (!account)
+                                return reject('Failed to create account.');
 
-                    req.logIn(account, {}, function(errLogIn) {
-                        if (errLogIn)
-                            return res.status(401).send(errLogIn.message);
+                            resolve(_account);
+                        });
+                    });
+                })
+                .then((account) => {
+                    return new Promise((resolve, reject) => {
+                        req.logIn(account, {}, (err) => {
+                            if (err)
+                                return reject(err.message);
 
-                        return res.sendStatus(200);
+                            resolve(account);
+                        });
                     });
+                })
+                .then((account) => new mongo.Space({name: 'Personal space', owner: account._id}).save())
+                .then(() => res.sendStatus(200))
+                .catch((errMsg) => {
+                    res.status(401).send(errMsg);
                 });
-            });
         });
 
         /**
          * Login in exist account.
          */
-        router.post('/login', function(req, res, next) {
+        router.post('/signin', function(req, res, next) {
             passport.authenticate('local', function(errAuth, user) {
                 if (errAuth)
                     return res.status(401).send(errAuth.message);
@@ -121,55 +168,27 @@ module.exports.factory = function(express, passport, nodemailer, settings,
mongo
          * Send e-mail to user with reset token.
          */
         router.post('/password/forgot', function(req, res) {
-            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 res.status(401).send('Can\'t send e-mail with instructions to reset
password. Please ask webmaster to setup SMTP server!');
-
-            const token = _randomString();
-
             mongo.Account.findOne({email: req.body.email}).exec()
                 .then((user) => {
                     if (!user)
                         return Promise.reject('Account with that email address does not exists!');
 
-                    user.resetPasswordToken = token;
+                    user.resetPasswordToken = _randomString();
 
                     return user.save();
                 })
                 .then((user) => {
-                    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: 'Password Reset',
-                        text: 'You are receiving this because you (or someone else) have
requested the reset of the password for your account.\n\n' +
+                    return _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=' + token +
'\n\n' +
-                        'If you did not request this, please ignore this email and your password
will remain unchanged.\n\n' +
-                        '--------------\n' +
-                        settings.smtp.username + '\n'
-                    };
-
-                    return new Promise((resolve, reject) => {
-                        mailer.sendMail(mailOptions, (err) => {
-                            if (err)
-                                return reject();
-
-                            resolve(res.status(200).send('An e-mail has been sent with further
instructions.'));
-                        });
-                    });
+                        'http://' + req.headers.host + '/password/reset?token=' + user.resetPasswordToken
+ '\n\n' +
+                        'If you did not request this, please ignore this email and your password
will remain unchanged.',
+                        'Failed to send e-mail with reset link!');
                 })
-                .catch((err) => {
+                .then(() => res.status(200).send('An e-mail has been sent with further
instructions.'))
+                .catch((errMsg) => {
                     // TODO IGNITE-843 Send email to admin
-                    return res.status(401).send('Failed to send e-mail with reset link!'
+ (err ? '<br>' + err : ''));
+                    return res.status(401).send(errMsg);
                 });
         });
 
@@ -181,14 +200,11 @@ module.exports.factory = function(express, passport, nodemailer, settings,
mongo
                 .then((user) => {
                     return new Promise((resolve, reject) => {
                         if (!user)
-                            return reject();
+                            return reject('Failed to find account with this token! Please
check link from e-mail.');
 
                         user.setPassword(req.body.password, (err, _user) => {
-                            if (err) {
-                                console.log('Failed to reset password: ' + err.message);
-
-                                return reject();
-                            }
+                            if (err)
+                                return reject('Failed to reset password: ' + err.message);
 
                             _user.resetPasswordToken = undefined; // eslint-disable-line
no-undefined
 
@@ -197,43 +213,19 @@ module.exports.factory = function(express, passport, nodemailer, settings,
mongo
                     });
                 })
                 .then((user) => {
-                    const transporter = {
-                        service: settings.smtp.service,
-                        auth: {
-                            user: settings.smtp.email,
-                            pass: settings.smtp.password
-                        }
-                    };
-
-                    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 password has been changed',
-                        text: 'Hello,\n\n' +
+                    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' +
-                        'Now you can login: http://' + req.headers.host + '\n\n' +
-                        '--------------\n' +
-                        'Apache Ignite Web Console\n'
-                    };
-
-                    return new Promise((resolve) => {
-                        mailer.sendMail(mailOptions, (err) => {
-                            if (err)
-                                return resolve(res.status(500).send('Password was changed,
but failed to send confirmation e-mail!'));
-
-                            resolve(res.status(200).send(user.email));
-                        });
-                    });
+                        'Now you can login: http://' + req.headers.host,
+                        'Password was changed, but failed to send confirmation e-mail!');
                 })
-                .catch(() => {
-                    res.status(500).send('Failed to reset password! Please check link from
e-mail.');
+                .catch((errMsg) => {
+                    res.status(500).send(errMsg);
                 });
         });
 
         /* GET reset password page. */
-        router.post('/validate/token', function(req, res) {
+        router.post('/password/validate/token', function(req, res) {
             const token = req.body.token;
 
             mongo.Account.findOne({resetPasswordToken: token}).exec()

http://git-wip-us.apache.org/repos/asf/ignite/blob/4f90db19/modules/control-center-web/src/main/js/views/login.jade
----------------------------------------------------------------------
diff --git a/modules/control-center-web/src/main/js/views/login.jade b/modules/control-center-web/src/main/js/views/login.jade
index 4908002..35767f4 100644
--- a/modules/control-center-web/src/main/js/views/login.jade
+++ b/modules/control-center-web/src/main/js/views/login.jade
@@ -34,28 +34,28 @@ header#header.header
             .col-xs-12.col-md-6
                 form(name='loginForm' novalidate)
                     .modal-body.row(style='padding-bottom: 10px; margin: 0')
-                        .settings-row(ng-if='action == "register"')
+                        .settings-row(ng-if='action == "signup"')
                             h3.login-header Sign Up
-                        .settings-row(ng-if='action == "login"')
+                        .settings-row(ng-if='action == "signin"')
                             h3.login-header Sign In
                         .settings-row(ng-if='action == "password/forgot"')
                             h3.login-header Forgot password?
                         .settings-row
                             p.col-xs-12.col-md-11(ng-show='action == "password/forgot"')
                                 | That's ok! Simply enter your email below and a reset password
link will be sent to you via email. You can then follow that link and select a new password.
-                        .settings-row(ng-show='action == "register"')
+                        .settings-row(ng-show='action == "signup"')
                             +lblRequired('Full Name:')
                             .col-xs-9.col-md-8
-                                input#user_name.form-control(enter-focus-next='user_email'
type='text' ng-model='user_info.username' placeholder='John Smith' ng-required='action=="register"')
+                                input#user_name.form-control(enter-focus-next='user_email'
type='text' ng-model='user_info.username' placeholder='John Smith' ng-required='action=="signup"')
                         .settings-row
                             +lblRequired('Email:')
                             .col-xs-9.col-md-8
                                 input#user_email.form-control(enter-focus-next='company'
type='email' ng-model='user_info.email' placeholder='you@domain.com' required)
-                        .settings-row(ng-show='action == "register"')
+                        .settings-row(ng-show='action == "signup"')
                             +lbl('Company:')
                             .col-xs-9.col-md-8
                                 input#company.form-control(enter-focus-next='country' type='text'
ng-model='user_info.company' placeholder='Your company name')
-                        .settings-row(ng-show='action == "register"')
+                        .settings-row(ng-show='action == "signup"')
                             +lbl('Country:')
                             .col-xs-9.col-md-8
                                 button#country.select-toggle.form-control(bs-select bs-options='item
for item in countries' enter-focus-next='user_password' type='text' ng-model='user_info.country'
placeholder='Choose your country')
@@ -63,28 +63,28 @@ header#header.header
                             +lblRequired('Password:')
                             .col-xs-9.col-md-8
                                 input#user_password.form-control(enter-focus-next='user_confirm'
type='password' ng-model='user_info.password' placeholder='Password' ng-required='action !=
"password/forgot"' on-enter='action == "login" && loginForm.$valid && auth(action,
user_info)')
-                        .settings-row(ng-if='action == "register"')
+                        .settings-row(ng-if='action == "signup"')
                             +lblRequired('Confirm:')
                             .col-xs-9.col-md-8
-                                input#user_confirm.form-control(type='password' ng-model='user_info.confirm'
match='user_info.password' placeholder='Confirm password' ng-required='action == "register"'
on-enter='loginForm.$valid && auth(action, user_info)')
+                                input#user_confirm.form-control(type='password' ng-model='user_info.confirm'
match='user_info.password' placeholder='Confirm password' ng-required='action == "signup"'
on-enter='loginForm.$valid && auth(action, user_info)')
                         .settings-row(ignite-terms)
-                            .col-md-offset-3(ng-if='action == "register" && terms.termsState')
+                            .col-md-offset-3(ng-if='action == "signup" && terms.termsState')
                                 label
                                     input(type='checkbox' ng-model='user_info.agree', ng-required='true')
                                     | I agree to the #[a(ui-sref='{{::terms.termsState}}'
target='_blank') terms and conditions]
                     .col-xs-12.col-md-11
-                        .login-footer(ng-show='action == "register"')
+                        .login-footer(ng-show='action == "signup"')
                             a.labelField(ng-click='action = "password/forgot"' on-click-focus='user_email')
Forgot password?
-                            a.labelLogin(ng-click='action = "login"' on-click-focus='user_email')
Sign In
+                            a.labelLogin(ng-click='action = "signin"' on-click-focus='user_email')
Sign In
                             button#signup.btn.btn-primary(ng-click='auth(action, user_info)'
ng-disabled='loginForm.$invalid') Sign Up
                     .col-xs-12.col-md-11
                         .login-footer(ng-show='action == "password/forgot"')
-                            a.labelField(ng-click='action = "login"' on-click-focus='user_email')
Sign In
+                            a.labelField(ng-click='action = "signin"' on-click-focus='user_email')
Sign In
                             button#forgot.btn.btn-primary(ng-click='auth(action, user_info)'
ng-disabled='loginForm.$invalid') Send it to me
                     .col-xs-12.col-md-11
-                        .login-footer(ng-show='action == "login"')
+                        .login-footer(ng-show='action == "signin"')
                             a.labelField(ng-click='action = "password/forgot"' on-click-focus='user_email')
Forgot password?
-                            a.labelLogin(ng-click='action = "register"' on-click-focus='user_name')
Sign Up
+                            a.labelLogin(ng-click='action = "signup"' on-click-focus='user_name')
Sign Up
                             button#login.btn.btn-primary(ng-click='auth(action, user_info)'
ng-disabled='loginForm.$invalid') Sign In
 
                 .col-xs-12.col-md-11.home-panel


Mime
View raw message