From f403c7ba342c2bb9349863e42c2424bea9bab8f3 Mon Sep 17 00:00:00 2001 From: Benjamin Benni Date: Wed, 26 Aug 2015 11:35:35 +0200 Subject: [PATCH] Commit garbage - delete login because IT DOES NOT WORK. YES. YOU READ RIGHT : THIS SIMPLE LITTLE THING JUST DOES NOT WORK AND IS DRIVING ME MAD. lol. :-1: --- backend/src/Backend.ts | 3 +- backend/src/Server.ts | 41 ------------------- backend/src/api/DashboardRouter.ts | 2 + backend/src/api/RouterItf.ts | 5 +-- frontend/app/index.html | 2 + frontend/app/scripts/app.js | 5 +++ .../scripts/controllers/ServiceDashboard.js | 1 + .../app/scripts/controllers/ServiceLogin.js | 21 ++++++++++ frontend/app/scripts/controllers/dashboard.js | 9 ++-- frontend/app/scripts/controllers/login.js | 25 +++++++++++ frontend/app/styles/login.css | 0 frontend/app/styles/main.css | 5 +++ frontend/app/views/login.html | 27 ++++++++++++ 13 files changed, 95 insertions(+), 51 deletions(-) create mode 100644 frontend/app/scripts/controllers/ServiceLogin.js create mode 100644 frontend/app/scripts/controllers/login.js create mode 100644 frontend/app/styles/login.css create mode 100644 frontend/app/views/login.html diff --git a/backend/src/Backend.ts b/backend/src/Backend.ts index fcd9be5..e46817f 100644 --- a/backend/src/Backend.ts +++ b/backend/src/Backend.ts @@ -79,7 +79,6 @@ class Backend extends Server { */ buildAPI() { var self = this; - var loginCheck = super.requireLogin; this.app.use('/dashboard', (new DashboardRouter(self.goalInstanceRepository, self.goalInstanceFactory, self.goalDefinitionRepository, self.userRepository,self.badgeRepository, new Middleware())).getRouter()); @@ -88,7 +87,7 @@ class Backend extends Server { this.app.use("/goals", (new GoalDefinitionRouter(self.goalDefinitionRepository, self.goalDefinitionFactory, self.goalInstanceRepository, self.userRepository)).getRouter()); this.app.use("/challenges", (new GoalInstanceRouter(self.goalInstanceRepository, self.goalInstanceFactory, self.goalDefinitionRepository, self.userRepository)).getRouter()); */ - + this.app.get('/test', function (req, res) { self.storingHandler.save( function (result) { diff --git a/backend/src/Server.ts b/backend/src/Server.ts index ee25530..c286105 100644 --- a/backend/src/Server.ts +++ b/backend/src/Server.ts @@ -67,14 +67,6 @@ class Server { this.app.use(bodyParser.json()); // for parsing application/json this.app.use(bodyParser.urlencoded({extended: true})); // for parsing application/x-www-form-urlencoded - // Handle client session with mozilla library - this.app.use(session({ - cookieName: 'session', - secret: 'random_string_goes_here', // TODO : make secret field a high-entropy string instead of this bullshit - duration: 30 * 60 * 1000, - activeDuration: 5 * 60 * 1000, - })); - this.app.use(function (req, res, next) { res.header("Access-Control-Allow-Origin", "*"); res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept"); @@ -82,42 +74,9 @@ class Server { next(); }); - this.app.use('/login', function (req, res, next) { - if (req.session && req.session.user) { - this.userRepository.userExists(req.session.user.id, - function (user) { - if (user) { - req.user = user; - delete req.user.password; // delete the password from the session - req.session.user = user; //refresh the session value - res.locals.user = user; - } - // finishing processing the middleware and run the route - next(); - }, - function (err) { - console.log("PROBLEME"); - res.send(err); - }); - } else { - next(); - } - - }); - - this.httpServer = http.createServer(this.app); } - requireLogin(req, res, next) { - if (!req.user) { - var route = req.get('host')+'/login'; - console.log('redirection vers', route); - res.redirect(route); - } else { - next(); - } - } /** * Runs the Server. diff --git a/backend/src/api/DashboardRouter.ts b/backend/src/api/DashboardRouter.ts index be4a210..bdb4aa4 100644 --- a/backend/src/api/DashboardRouter.ts +++ b/backend/src/api/DashboardRouter.ts @@ -28,6 +28,7 @@ class DashboardRouter extends RouterItf { private middleware:Middleware; + constructor(challengeRepository:ChallengeRepository, challengeFactory:ChallengeFactory, goalRepository:GoalRepository, userRepository:UserRepository, badgeRepository:BadgeRepository, middleware:Middleware) { super(); @@ -47,6 +48,7 @@ class DashboardRouter extends RouterItf { var self = this; this.router.get('/', function (req, res) { + console.log("Getting dashboard"); self.getDashboard(req, res); }); diff --git a/backend/src/api/RouterItf.ts b/backend/src/api/RouterItf.ts index 830dfd6..d6a0c3c 100644 --- a/backend/src/api/RouterItf.ts +++ b/backend/src/api/RouterItf.ts @@ -12,8 +12,6 @@ var express:any = require("express"); */ class RouterItf { - protected loginCheckFunc; - /** * Router property. * @@ -25,8 +23,7 @@ class RouterItf { /** * Constructor. */ - constructor(loginCheck = null) { - this.loginCheckFunc = loginCheck; + constructor() { this.router = express.Router(); // middleware specific to this router diff --git a/frontend/app/index.html b/frontend/app/index.html index c874cd7..67c2b5c 100644 --- a/frontend/app/index.html +++ b/frontend/app/index.html @@ -106,6 +106,7 @@ + @@ -113,6 +114,7 @@ + diff --git a/frontend/app/scripts/app.js b/frontend/app/scripts/app.js index 87328d9..e12149e 100644 --- a/frontend/app/scripts/app.js +++ b/frontend/app/scripts/app.js @@ -52,6 +52,11 @@ var app = angular controller: 'DashboardCtrl', controllerAs:'dashboard' }) + .when('/login', { + templateUrl: '../views/login.html', + controller: 'LoginCtrl', + controllerAs:'loginCtrl' + }) .otherwise({ redirectTo: '/' }); diff --git a/frontend/app/scripts/controllers/ServiceDashboard.js b/frontend/app/scripts/controllers/ServiceDashboard.js index dbbe4e0..487da29 100644 --- a/frontend/app/scripts/controllers/ServiceDashboard.js +++ b/frontend/app/scripts/controllers/ServiceDashboard.js @@ -18,6 +18,7 @@ app.service('ServiceDashboard', ['$http', function ServiceDashboard($http) { successFunc(data, goals, badges, challenges); }) .error(function (data) { + console.error('ServiceDashboard : fail get dashboard', data); failFunc(data); }); }; diff --git a/frontend/app/scripts/controllers/ServiceLogin.js b/frontend/app/scripts/controllers/ServiceLogin.js new file mode 100644 index 0000000..e834f47 --- /dev/null +++ b/frontend/app/scripts/controllers/ServiceLogin.js @@ -0,0 +1,21 @@ +'use strict'; + +var app = angular.module('ecoknowledgeApp'); + +var loginBasePath = 'http://localhost:3000/login/'; + +app.service('ServiceLogin', ['$http', function ServiceLogin($http) { + + this.login = function (name, successFunc, failFunc) { + var path = loginBasePath + ''; + console.log('ServiceLogin : login', path); + + $http.post(path, name) + .success(function (data) { + successFunc(data); + }) + .error(function (data) { + failFunc(data); + }); + }; +}]); diff --git a/frontend/app/scripts/controllers/dashboard.js b/frontend/app/scripts/controllers/dashboard.js index c22c9f8..d6e8b79 100644 --- a/frontend/app/scripts/controllers/dashboard.js +++ b/frontend/app/scripts/controllers/dashboard.js @@ -2,7 +2,7 @@ var app = angular.module('ecoknowledgeApp'); -app.controller('DashboardCtrl', ['ServiceDashboard', '$window', function (ServiceDashboard, $window) { +app.controller('DashboardCtrl', ['ServiceDashboard', '$window', '$location', function (ServiceDashboard, $window, $location) { var self = this; self.goals = {}; @@ -13,7 +13,8 @@ app.controller('DashboardCtrl', ['ServiceDashboard', '$window', function (Servic self.request = {}; this.getDashboard = function () { - console.log('on veut récupérer le dashboard!!'); + console.log('Angular wanna get the dashboard'); + ServiceDashboard.get( function (data, goals, badges, challenges) { console.log('Result of dashboard : ', goals, badges, challenges); @@ -25,7 +26,8 @@ app.controller('DashboardCtrl', ['ServiceDashboard', '$window', function (Servic self.challenges = challenges; }, function (data) { - console.log('ERREUR MA GUEULE', data); + console.error("Redirection vers", data.redirectTo); + $location.path(data.redirectTo); }); }; @@ -59,7 +61,6 @@ app.controller('DashboardCtrl', ['ServiceDashboard', '$window', function (Servic }; - console.log('Le fichier dshb est bien chargé'); this.getDashboard(); }]); diff --git a/frontend/app/scripts/controllers/login.js b/frontend/app/scripts/controllers/login.js new file mode 100644 index 0000000..f53c956 --- /dev/null +++ b/frontend/app/scripts/controllers/login.js @@ -0,0 +1,25 @@ +'use strict'; + +var app = angular.module('ecoknowledgeApp'); + +app.controller('LoginCtrl', ['ServiceLogin', function (ServiceLogin) { + + var self = this; + + this.username = '' + this.password = ''; + this.debug = ''; + + this.connect = function () { + self.debug = 'ID:' + self.username + ', passwd:' + self.password; + ServiceLogin.login(self.username, + function (data) { + console.log('Login success: data received', data); + }, + function (data) { + console.log('Login fail: data received', data); + + }); + }; + +}]); diff --git a/frontend/app/styles/login.css b/frontend/app/styles/login.css new file mode 100644 index 0000000..e69de29 diff --git a/frontend/app/styles/main.css b/frontend/app/styles/main.css index 13010c8..fd2a465 100644 --- a/frontend/app/styles/main.css +++ b/frontend/app/styles/main.css @@ -1,3 +1,8 @@ +.navbar { + margin-bottom:0px; + border : 0px solid white; +} + .browsehappy { margin: 0.2em 0; background: #ccc; diff --git a/frontend/app/views/login.html b/frontend/app/views/login.html new file mode 100644 index 0000000..b8750b1 --- /dev/null +++ b/frontend/app/views/login.html @@ -0,0 +1,27 @@ + + +
+ + + {{loginCtrl.username}} + {{loginCtrl.password}} + {{loginCtrl.debug}} +
+
+
+
+ +
+
+
+ +
+
+ +
+
+ +
+