Repository: incubator-ignite Updated Branches: refs/heads/ignite-843 d7125f6a3 -> bea625984
# IGNITE-843 Implement profile form. Project: http://git-wip-us.apache.org/repos/asf/incubator-ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-ignite/commit/bea62598 Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/bea62598 Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/bea62598 Branch: refs/heads/ignite-843 Commit: bea625984924e42d32fbaee69a49a57c35e029d6 Parents: d7125f6 Author: sevdokimov <sergey.evdoki...@jetbrains.com> Authored: Thu Jul 9 13:43:59 2015 +0300 Committer: sevdokimov <sergey.evdoki...@jetbrains.com> Committed: Thu Jul 9 13:44:14 2015 +0300 ---------------------------------------------------------------------- .../nodejs/controllers/profile-controller.js | 28 ++++++++++++--- .../web-control-center/nodejs/routes/profile.js | 38 ++++++++++++++++---- .../nodejs/views/profile.jade | 13 +++++-- 3 files changed, 67 insertions(+), 12 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/bea62598/modules/web-control-center/nodejs/controllers/profile-controller.js ---------------------------------------------------------------------- diff --git a/modules/web-control-center/nodejs/controllers/profile-controller.js b/modules/web-control-center/nodejs/controllers/profile-controller.js index eca0147..ff239a9 100644 --- a/modules/web-control-center/nodejs/controllers/profile-controller.js +++ b/modules/web-control-center/nodejs/controllers/profile-controller.js @@ -15,23 +15,43 @@ * limitations under the License. */ -controlCenterModule.controller('profileController', ['$scope', '$alert', '$http', function ($scope, $alert, $http) { +controlCenterModule.controller('profileController', ['$scope', '$alert', '$http', 'commonFunctions', + function ($scope, $alert, $http, commonFunctions) { $scope.editableUser = angular.copy($scope.savedUser); $scope.editField = null; $scope.showInfo = function (msg) { + $scope.showAlert(msg, 'success'); + }; + + $scope.showError = function (msg) { + $scope.showAlert(msg, 'danger'); + }; + + $scope.showAlert = function (msg, type) { if ($scope.alert) $scope.alert.hide(); $scope.alert = $alert({ - type: 'success', + type: type, title: msg, duration: 2 }); }; + $scope.changePass = function() { + if (!$scope.pass1 || $scope.pass1.length == 0 || $scope.pass1 != $scope.pass2) + return; + + $http.post('/profile/changePassword', {_id: $scope.editableUser._id, pass: $scope.pass1}).success(function() { + $scope.showInfo('Password has been changed'); + }).error(function(err) { + $scope.showError('Failed to change password: ' + commonFunctions.errorMessage(err)); + }); + }; + $scope.$watch('editField', function(val) { if (!angular.equals($scope.editableUser, $scope.savedUser)) { $http.post('/profile/saveUser', $scope.editableUser).success(function(updatedUser) { @@ -39,8 +59,8 @@ controlCenterModule.controller('profileController', ['$scope', '$alert', '$http' angular.copy(updatedUser, $scope.editableUser); $scope.showInfo('Profile has been updated'); - }).error(function(data) { - $scope.showInfo('Failed to update profile: ' + data); + }).error(function(err) { + $scope.showError('Failed to update profile: ' + commonFunctions.errorMessage(err)); }); } }); http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/bea62598/modules/web-control-center/nodejs/routes/profile.js ---------------------------------------------------------------------- diff --git a/modules/web-control-center/nodejs/routes/profile.js b/modules/web-control-center/nodejs/routes/profile.js index 008addf..11eb04b 100644 --- a/modules/web-control-center/nodejs/routes/profile.js +++ b/modules/web-control-center/nodejs/routes/profile.js @@ -19,6 +19,15 @@ var router = require('express').Router(); var db = require('../db'); var uiUtils = require('../helpers/ui-utils'); +router.all('/profile/*', function(req, res, next) { + var userId = req.body._id; + + if (userId != req.currentUserId() && userId != req.user._id) + return res.sendStatus(403); + else + next(); +}); + /** * Get list of user accounts. */ @@ -34,16 +43,11 @@ router.get('/profile', function(req, res) { }); router.post('/profile/saveUser', function(req, res) { - var userId = req.body._id; - - if (userId != req.currentUserId() && userId != req.user._id) - return res.sendStatus(403); - var u = { username: req.body.username }; - db.Account.findByIdAndUpdate(userId, u, {new: true}, function(err, val) { + db.Account.findByIdAndUpdate(req.body._id, u, {new: true}, function(err, val) { if (err) return res.status(500).send(err); @@ -51,4 +55,26 @@ router.post('/profile/saveUser', function(req, res) { }) }); +router.post('/profile/changePassword', function(req, res) { + var pass = req.body.pass; + + if (!pass || pass.length == 0) + return res.sendStatus(500); + + db.Account.findById(req.body._id, function(err, user) { + if (err) + return res.status(500).send(err); + + user.salt = user.makeSalt(); + user.hash = user.encryptPassword(pass); + + user.save(function (err) { + if (err) + return res.status(500).send(err); + + res.json(uiUtils.filterUser(val)); + }); + }) +}); + module.exports = router; \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/bea62598/modules/web-control-center/nodejs/views/profile.jade ---------------------------------------------------------------------- diff --git a/modules/web-control-center/nodejs/views/profile.jade b/modules/web-control-center/nodejs/views/profile.jade index 6d5276d..c85b5e5 100644 --- a/modules/web-control-center/nodejs/views/profile.jade +++ b/modules/web-control-center/nodejs/views/profile.jade @@ -29,7 +29,6 @@ block content .docs-body() div(ng-controller='profileController') | User name: - div(ng-show='editField != "username"') a(href ng-click='editField = "username"') {{editableUser.username}} div(ng-show='editField == "username"') @@ -37,4 +36,14 @@ block content .input-tip input.form-control(type='text' ng-model='editableUser.username') - \ No newline at end of file + p + button.btn.btn-link(ng-show='!showChangePasswordForm' ng-click='showChangePasswordForm = true') Change password + form.form-inline(ng-show='showChangePasswordForm', role="form") + .form-group + label(for='pass1') New password: + input#pass1.form-control(type='password', ng-model='pass1') + .form-group + label(for='pass2') Repeat password: + input#pass2.form-control(type='password', ng-model='pass2') + + i.stackTipField.fa.fa-floppy-o(ng-click='changePass()')