ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From anovi...@apache.org
Subject incubator-ignite git commit: # 843 WIP.
Date Mon, 18 May 2015 06:05:00 GMT
Repository: incubator-ignite
Updated Branches:
  refs/heads/ignite-843 53660999b -> d58bae6b4


# 843 WIP.


Project: http://git-wip-us.apache.org/repos/asf/incubator-ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ignite/commit/d58bae6b
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/d58bae6b
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/d58bae6b

Branch: refs/heads/ignite-843
Commit: d58bae6b4216f77fe97665e9e2652d0bc4a3cfe7
Parents: 5366099
Author: Andrey <anovikov@gridgain.com>
Authored: Mon May 18 13:04:44 2015 +0700
Committer: Andrey <anovikov@gridgain.com>
Committed: Mon May 18 13:04:44 2015 +0700

----------------------------------------------------------------------
 modules/webconfig/nodejs/app.js                 | 84 +++++++++++++-------
 modules/webconfig/nodejs/db.js                  | 26 +++---
 .../public/javascripts/controllers/clusters.js  |  3 +-
 modules/webconfig/nodejs/settings.js            |  3 +
 4 files changed, 76 insertions(+), 40 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/d58bae6b/modules/webconfig/nodejs/app.js
----------------------------------------------------------------------
diff --git a/modules/webconfig/nodejs/app.js b/modules/webconfig/nodejs/app.js
index bc12c71..666dbff 100644
--- a/modules/webconfig/nodejs/app.js
+++ b/modules/webconfig/nodejs/app.js
@@ -9,8 +9,10 @@ var session = require('express-session')
 var pageRoutes = require('./routes/pages');
 var clusterRouter = require('./routes/clusters');
 
-//var passport = require('passport')
-//var LocalStrategy = require('passport-local').Strategy;
+var passport = require('passport');
+var LocalStrategy = require('passport-local').Strategy;
+
+var db = require('./db.js');
 
 var app = express();
 
@@ -23,12 +25,12 @@ app.use(favicon(__dirname + '/public/favicon.ico'));
 app.use(logger('dev'));
 app.use(bodyParser.json());
 app.use(bodyParser.urlencoded({extended: false}));
-//app.use(cookieParser());
+app.use(cookieParser());
 app.use(require('less-middleware')(path.join(__dirname, 'public')));
 app.use(express.static(path.join(__dirname, 'public')));
 
-//app.use(passport.initialize());
-//app.use(passport.session());
+app.use(passport.initialize());
+app.use(passport.session());
 
 app.use('/', pageRoutes);
 app.use('/rest', clusterRouter);
@@ -70,27 +72,55 @@ app.use(function (err, req, res, next) {
 //    next();
 //});
 
-//app.use(session({
-//    secret: 'keyboard cat',
-//    resave: false,
-//    saveUninitialized: true
-//}))
-//
-//passport.use(new LocalStrategy(
-//    function (username, password, done) {
-//        User.findOne({username: username}, function (err, user) {
-//            if (err) {
-//                return done(err);
-//            }
-//            if (!user) {
-//                return done(null, false, {message: 'Incorrect username.'});
-//            }
-//            if (!user.validPassword(password)) {
-//                return done(null, false, {message: 'Incorrect password.'});
-//            }
-//            return done(null, user);
-//        });
-//    }
-//));
+app.use(session({
+    secret: 'keyboard cat',
+    resave: false,
+    saveUninitialized: true
+}));
+
+passport.serializeUser(function(user, done) {
+    done(null, user._id);
+});
+
+passport.deserializeUser(function(id, done) {
+    db.User.findById(id, function(err, user) {
+        done(err, user);
+    });
+});
+
+// passport/login.js
+passport.use('login', new LocalStrategy({
+        passReqToCallback : true
+    },
+    function(req, username, password, done) {
+        // check in mongo if a user with username exists or not
+        db.User.findOne({ 'username' :  username },
+            function(err, user) {
+                // In case of any error, return using the done method
+                if (err)
+                    return done(err);
+
+                // Username does not exist, log error & redirect back
+                if (!user) {
+                    console.log('User Not Found with username ' + username);
+
+                    return done(null, false,
+                        req.flash('message', 'User Not found.'));
+                }
+
+                // User exists but wrong password, log the error
+                if (!isValidPassword(user, password)) {
+                    console.log('Invalid Password');
+
+                    return done(null, false,
+                        req.flash('message', 'Invalid Password'));
+                }
+
+                // User and password both match, return user from done method which will
be treated like success
+                return done(null, user);
+            }
+        );
+    })
+);
 
 module.exports = app;

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/d58bae6b/modules/webconfig/nodejs/db.js
----------------------------------------------------------------------
diff --git a/modules/webconfig/nodejs/db.js b/modules/webconfig/nodejs/db.js
index 446f1d8..33764b7 100644
--- a/modules/webconfig/nodejs/db.js
+++ b/modules/webconfig/nodejs/db.js
@@ -1,25 +1,29 @@
+var settings = require('./settings.js');
+
 // mongoose for mongodb
 var mongoose = require('mongoose');
 
 // connect to mongoDB database on modulus.io
-var uri = 'mongodb://localhost/web-configurator';
+mongoose.connect(settings.url, {server: {poolSize: 4}});
 
-mongoose.connect(uri, {server: {poolSize: 4}});
+// define user model.
+exports.User = mongoose.model('User', new mongoose.Schema({
+    username: String,
+    password: String,
+    email: String
+}));
 
-// define model
-var cacheSchema = new mongoose.Schema({
+// define cache model.
+exports.Cache =  mongoose.model('Cache', new mongoose.Schema({
     name: String,
     mode: { type: String, enum: ['PARTITIONED', 'REPLICATED', 'LOCAL'] },
     backups: Number
-});
-
-exports.Cache =  mongoose.model('Cache', cacheSchema);
+}));
 
-var clusterSchema = new mongoose.Schema({
+// define cluster model.
+exports.Cluster =  mongoose.model('Cluster', new mongoose.Schema({
     name : String,
     caches : [String],
     discovery : { type: String, enum: ['VM', 'Multicast'] },
     addresses : [String]
-});
-
-exports.Cluster =  mongoose.model('Cluster', clusterSchema);
\ No newline at end of file
+}));
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/d58bae6b/modules/webconfig/nodejs/public/javascripts/controllers/clusters.js
----------------------------------------------------------------------
diff --git a/modules/webconfig/nodejs/public/javascripts/controllers/clusters.js b/modules/webconfig/nodejs/public/javascripts/controllers/clusters.js
index 16aef47..9be3f8d 100644
--- a/modules/webconfig/nodejs/public/javascripts/controllers/clusters.js
+++ b/modules/webconfig/nodejs/public/javascripts/controllers/clusters.js
@@ -1,6 +1,5 @@
 angular.module('ignite-web-configurator', ['ngTable', 'mgcrea.ngStrap', 'ngSanitize'])
     .controller('clusterRouter', ['$scope', '$modal', '$http', '$filter', 'ngTableParams',
function($scope, $modal, $http, $filter, ngTableParams) {
-
         $scope.discoveries = [
             {value: 'VM', label: 'VM'},
             {value: 'Multicast', label: 'Multicast'}
@@ -59,7 +58,7 @@ angular.module('ignite-web-configurator', ['ngTable', 'mgcrea.ngStrap',
'ngSanit
         };
 
         $scope.create = function () {
-            $scope.cluster = { discovery: 'VM' };
+            $scope.cluster = {};
 
             // Show when some event occurs (use $promise property to ensure the template
has been loaded)
             myOtherModal.$promise.then(myOtherModal.show);

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/d58bae6b/modules/webconfig/nodejs/settings.js
----------------------------------------------------------------------
diff --git a/modules/webconfig/nodejs/settings.js b/modules/webconfig/nodejs/settings.js
new file mode 100644
index 0000000..0c5cefc
--- /dev/null
+++ b/modules/webconfig/nodejs/settings.js
@@ -0,0 +1,3 @@
+module.exports = {
+    'url' : 'mongodb://localhost/web-configurator'
+}
\ No newline at end of file


Mime
View raw message