Skip to content

Commit

Permalink
Commit garbage - delete login because IT DOES NOT WORK.
Browse files Browse the repository at this point in the history
YES.
YOU READ RIGHT : THIS SIMPLE LITTLE THING JUST DOES NOT WORK AND IS
DRIVING ME MAD.

lol. 👎
  • Loading branch information
ttben committed Aug 26, 2015
1 parent 68df36c commit f403c7b
Show file tree
Hide file tree
Showing 13 changed files with 95 additions and 51 deletions.
3 changes: 1 addition & 2 deletions backend/src/Backend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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());

Expand All @@ -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) {
Expand Down
41 changes: 0 additions & 41 deletions backend/src/Server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,57 +67,16 @@ 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");
res.header("Access-Control-Allow-Methods", "POST, GET, DELETE");
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.
Expand Down
2 changes: 2 additions & 0 deletions backend/src/api/DashboardRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -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);
});

Expand Down
5 changes: 1 addition & 4 deletions backend/src/api/RouterItf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ var express:any = require("express");
*/
class RouterItf {

protected loginCheckFunc;

/**
* Router property.
*
Expand All @@ -25,8 +23,7 @@ class RouterItf {
/**
* Constructor.
*/
constructor(loginCheck = null) {
this.loginCheckFunc = loginCheck;
constructor() {
this.router = express.Router();

// middleware specific to this router
Expand Down
2 changes: 2 additions & 0 deletions frontend/app/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -106,13 +106,15 @@
<script src="scripts/controllers/home.js"></script>
<script src="scripts/controllers/badge.js"></script>
<script src="scripts/controllers/dashboard.js"></script>
<script src="scripts/controllers/login.js"></script>
<script src="scripts/controllers/ServiceGoal.js"></script>
<script src="scripts/controllers/ServiceChallenge.js"></script>
<script src="scripts/controllers/viewGoal.js"></script>
<script src="scripts/controllers/ServiceSensor.js"></script>
<script src="scripts/controllers/badgeV2.js"></script>
<script src="scripts/controllers/ServiceBadgeV2.js"></script>
<script src="scripts/controllers/ServiceDashboard.js"></script>
<script src="scripts/controllers/ServiceLogin.js"></script>
<!-- endbuild -->
</body>
</html>
5 changes: 5 additions & 0 deletions frontend/app/scripts/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ var app = angular
controller: 'DashboardCtrl',
controllerAs:'dashboard'
})
.when('/login', {
templateUrl: '../views/login.html',
controller: 'LoginCtrl',
controllerAs:'loginCtrl'
})
.otherwise({
redirectTo: '/'
});
Expand Down
1 change: 1 addition & 0 deletions frontend/app/scripts/controllers/ServiceDashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
};
Expand Down
21 changes: 21 additions & 0 deletions frontend/app/scripts/controllers/ServiceLogin.js
Original file line number Diff line number Diff line change
@@ -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);
});
};
}]);
9 changes: 5 additions & 4 deletions frontend/app/scripts/controllers/dashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {};
Expand All @@ -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);
Expand All @@ -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);
});
};

Expand Down Expand Up @@ -59,7 +61,6 @@ app.controller('DashboardCtrl', ['ServiceDashboard', '$window', function (Servic

};

console.log('Le fichier dshb est bien chargé');
this.getDashboard();
}]);

Expand Down
25 changes: 25 additions & 0 deletions frontend/app/scripts/controllers/login.js
Original file line number Diff line number Diff line change
@@ -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);

});
};

}]);
Empty file added frontend/app/styles/login.css
Empty file.
5 changes: 5 additions & 0 deletions frontend/app/styles/main.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
.navbar {
margin-bottom:0px;
border : 0px solid white;
}

.browsehappy {
margin: 0.2em 0;
background: #ccc;
Expand Down
27 changes: 27 additions & 0 deletions frontend/app/views/login.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<link rel="stylesheet" href="styles/login.css">

<div class="container jumbotron">

<div class="page-header text-center">
<h1>Connexion</h1>
</div>
{{loginCtrl.username}}
{{loginCtrl.password}}
{{loginCtrl.debug}}
<form name="loginForm" role="form" class="form-horizontal" accept-charset="utf-8" ng-submit="loginForm.$valid && loginCtrl.connect()" novalidate>
<div class="form-group">
<div class="col-md-8"><input placeholder="Idenfiant" class="form-control" type="text" ng-model="loginCtrl.username" required/></div>
</div>

<div class="form-group">
<div class="col-md-8"><input placeholder="Mot de passe" class="form-control" type="password" ng-model="loginCtrl.password" required/></div>
</div>

<div class="form-group">
<div class="col-md-offset-0 col-md-8">
<input type="submit" class="btn btn-success" ng-disabled="!loginForm.$valid" value="Connexion"/>
</div>
</div>

</form>
</div>

0 comments on commit f403c7b

Please sign in to comment.