From 4255875f84a9d2f17fcd8c551dba14bff3685008 Mon Sep 17 00:00:00 2001 From: nau Date: Wed, 7 Sep 2016 21:50:28 +0200 Subject: [PATCH] users system more implemented --- controllers/userController.js | 38 ++++- models/userModel.js | 3 +- server.js | 4 + webapp/controllers.js | 69 +++++++-- webapp/dashboard.html | 256 +++++++++++++++++----------------- webapp/signup.html | 167 ++++++++-------------- 6 files changed, 289 insertions(+), 248 deletions(-) diff --git a/controllers/userController.js b/controllers/userController.js index f7e9624..c3958ef 100644 --- a/controllers/userController.js +++ b/controllers/userController.js @@ -74,7 +74,9 @@ exports.addUser = function(req, res) { mail: req.body.mail, avatar: req.body.avatar, github: req.body.github, - web: req.body.web + web: req.body.web, + projects: req.body.projects, + connected: req.body.connected }); user.save(function(err, user) { @@ -139,6 +141,12 @@ exports.login = function(req, res) { expiresIn: '60m' }); //console.log(user); + + //update connected=true + user.connected= true; + user.save(function(err) { + if(err) return res.send(500, err.message); + }); // return the information including token as JSON res.json({ success: true, @@ -152,3 +160,31 @@ exports.login = function(req, res) { }); }; + +exports.logout = function(req, res) { + // find the user + userModel.findOne({ + username: req.body.username + }, function(err, user) { + + if (err) throw err; + + if (!user) { + res.json({ success: false, message: 'Authentication failed. User not found.' }); + } else if (user) { + + + //update connected=true + user.connected= false; + user.save(function(err) { + if(err) return res.send(500, err.message); + }); + // return the information including token as JSON + res.json({ + success: true, + message: 'logged out' + }); + } + + }); +}; diff --git a/models/userModel.js b/models/userModel.js index bf0fa7f..9eb2892 100644 --- a/models/userModel.js +++ b/models/userModel.js @@ -10,6 +10,7 @@ var userSchema = new Schema({ avatar: { type: String }, github: { type: String }, web: { type: String }, - projects: { type: String } + projects: { type: String }, + connected: { type: Boolean } }) module.exports = mongoose.model('userModel', userSchema); diff --git a/server.js b/server.js index f7f7437..f8c3e63 100755 --- a/server.js +++ b/server.js @@ -90,6 +90,10 @@ apiRoutes.use(function(req, res, next) { } }); //fi verificació de token + +apiRoutes.route('/logout') + .post(userCtrl.logout); + apiRoutes.route('/users') .get(userCtrl.findAllUsers); diff --git a/webapp/controllers.js b/webapp/controllers.js index 3be61f6..a45d737 100644 --- a/webapp/controllers.js +++ b/webapp/controllers.js @@ -6,17 +6,48 @@ angular.module('workApp', ['chart.js']) $interval, $http ) { + $scope.currentInclude='login.html'; + /* DASHBOARD initialization */ + $scope.dashboardInit = function(){ + if(localStorage.getItem('owt_token')){// adding token to the headers + $http.defaults.headers.post['X-Access-Token'] = localStorage.getItem('owt_token'); + $http.defaults.headers.common['X-Access-Token'] = localStorage.getItem('owt_token'); + } + + //getting users + $http.get(urlapi + 'users') + .success(function(data, status, headers,config){ + console.log(data); + $scope.users=data; + }) + .error(function(data, status, headers,config){ + console.log('data error'); + $scope.$broadcast('scroll.refreshComplete');//refresher stop + }) + .then(function(result){ + users = result.data; + }); + + }; + /* - - + +
+
+ +
-
- -
-
-
- -
-
-
{{user.username}}
-
-
-

- {{user.description}} -

-

- {{user.github}} -

-

- {{user.web}} -

-

- Total worked time: {{user.totalWorkedTime | secondsToDateTime | date:'HH:mm'}}h -

-







-







-







-







+
+ +
+
+
{{user.username}}
+
+

+ {{user.description}} +

+

+ {{user.github}} +

+

+ {{user.web}} +

+ +
    +
  • + + {{user.username}} + +

    {{user.description}}

    +
  • +
+
-
-
-
- -
-
- - -
-
- - -
- Add new project -
-
-
- - -
-
- - +
+
+
+
+ Projects + + + {{project.title}} +

{{project.totaltime | secondsToDateTime | date:'HH:mm:ss'}}

+ +
+
+
+
+ + +
+
+ + +
+ Add new project +
+
+
+ +
+
+ + +
+ Cancel + Update project +
+
-
-
- - - {{currentproject.title}} - -

- Total time: {{currentproject.totaltime | secondsToDateTime | date:'HH:mm:ss'}} -

-

- Current strike time: {{currentStrike | secondsToDateTime | date:'HH:mm:ss'}} -

+
+
+ + + {{currentproject.title}} + +

+ Total time: {{currentproject.totaltime | secondsToDateTime | date:'HH:mm:ss'}} +

+

+ Current strike time: {{currentStrike | secondsToDateTime | date:'HH:mm:ss'}} +

-
-
- Work! - Stop! +
+
+ Work! + Stop! - -
-
-
- - - + +
+
+
+ + + -
-
-
- - Select a project - -
+
+
+
+ + Select a project + +
-
-
-
+
+
+
diff --git a/webapp/signup.html b/webapp/signup.html index f35ccc6..54dd8ce 100644 --- a/webapp/signup.html +++ b/webapp/signup.html @@ -1,115 +1,62 @@ - - - - - - - - - - - - - - Open Work Time - online version - - - - - - - - -
-
+
+
+
+
+
+
+ Signup +
+
+ + +
+
+
+
+ + +
+
+ + +
-
-
-
- Signup -
-
- - -
-
-
-
- - -
-
- - -
-
-
-
- - -
-
-
-
- - -
-
- - -
-
-
-
- - -
-
- - -
-
-
- +
+
+ + +
+
+
+
+ + +
+
+ + +
+
+
+
+ + +
+
+ +
- - - - - - - - - - - - - - - - - - - - - - - - - + +
+
+