From 4602ace2bc470475f2092d027f663f042587a3e3 Mon Sep 17 00:00:00 2001 From: nau Date: Wed, 7 Sep 2016 19:23:48 +0200 Subject: [PATCH] signup and login system added, making the webapp online --- config.js | 2 +- controllers/userController.js | 10 +-- models/userModel.js | 7 +- server.js | 45 ++++++----- webapp/controllers.js | 61 ++++++++++++-- webapp/dashboard.html | 142 ++++++++++++++++++++++++++++++++ webapp/index.html | 148 +--------------------------------- webapp/login.html | 31 +++++++ webapp/signup.html | 115 ++++++++++++++++++++++++++ 9 files changed, 380 insertions(+), 181 deletions(-) create mode 100644 webapp/dashboard.html create mode 100644 webapp/login.html create mode 100644 webapp/signup.html diff --git a/config.js b/config.js index e83b101..f1decc4 100644 --- a/config.js +++ b/config.js @@ -3,7 +3,7 @@ module.exports = { /*'secret': process.env.SECRET, 'database': process.env.MONGO_DSN,*/ 'secret': 'secretfortoken', - 'database': 'mongodb://localhost/comunalcar', + 'database': 'mongodb://localhost/openworktime', "port" : process.env.PORT || 3000 }; diff --git a/controllers/userController.js b/controllers/userController.js index 9846848..f7e9624 100644 --- a/controllers/userController.js +++ b/controllers/userController.js @@ -71,10 +71,10 @@ exports.addUser = function(req, res) { username: req.body.username, password: req.body.password, description: req.body.description, - avatar: req.body.avatar, mail: req.body.mail, - phone: req.body.phone, - telegram: req.body.telegram + avatar: req.body.avatar, + github: req.body.github, + web: req.body.web }); user.save(function(err, user) { @@ -138,13 +138,13 @@ exports.login = function(req, res) { //expiresInMinutes: 1440 // expires in 24 hours expiresIn: '60m' }); -console.log(user); + //console.log(user); // return the information including token as JSON res.json({ success: true, message: 'Enjoy your token!', token: token, - avatar: user.avatar + user: user }); } diff --git a/models/userModel.js b/models/userModel.js index 1f9e36d..bf0fa7f 100644 --- a/models/userModel.js +++ b/models/userModel.js @@ -6,9 +6,10 @@ var userSchema = new Schema({ username: { type: String }, password: { type: String }, description: { type: String }, - avatar: { type: String }, mail: { type: String }, - phone: { type: String }, - telegram: { type: String } + avatar: { type: String }, + github: { type: String }, + web: { type: String }, + projects: { type: String } }) module.exports = mongoose.model('userModel', userSchema); diff --git a/server.js b/server.js index bb88fa4..f7f7437 100755 --- a/server.js +++ b/server.js @@ -29,8 +29,8 @@ app.use(morgan('dev')); var userMdl = require('./models/userModel')(app, mongoose); var userCtrl = require('./controllers/userController'); -var travelMdl = require('./models/travelModel')(app, mongoose); -var travelCtrl = require('./controllers/travelController'); +/*var projectMdl = require('./models/projectModel')(app, mongoose); +var projectCtrl = require('./controllers/projectController');*/ /*// Example Route var router = express.Router(); @@ -53,24 +53,10 @@ app.use(function(req, res, next) { var apiRoutes = express.Router(); apiRoutes.route('/users') - .get(userCtrl.findAllUsers) .post(userCtrl.addUser); -apiRoutes.route('/users/:id') - .get(userCtrl.findById); -apiRoutes.route('/users/byusername/:username') - .get(userCtrl.findUserByUsername); -apiRoutes.route('/travels/user/:username') - .get(travelCtrl.findAllTravelsFromUsername); - apiRoutes.route('/auth') .post(userCtrl.login); -apiRoutes.route('/travels') - .get(travelCtrl.findAllTravels); - -apiRoutes.route('/travels/:id') -.get(travelCtrl.findById) - // OJU AQUÏ TREC la verificació de token temporalment, per fer les proves des de l'app // route middleware to verify a token apiRoutes.use(function(req, res, next) { @@ -104,18 +90,35 @@ apiRoutes.use(function(req, res, next) { } }); //fi verificació de token +apiRoutes.route('/users') + .get(userCtrl.findAllUsers); + + +apiRoutes.route('/users/:id') + .get(userCtrl.findById); +apiRoutes.route('/users/byusername/:username') + .get(userCtrl.findUserByUsername); +/*apiRoutes.route('/projects/user/:username') + .get(projectCtrl.findAllprojectsFromUsername); + + +apiRoutes.route('/projects') + .get(projectCtrl.findAllprojects); + +apiRoutes.route('/projects/:id') + .get(projectCtrl.findById); apiRoutes.route('/users/:id') .put(userCtrl.updateUser) .delete(userCtrl.deleteUser); -apiRoutes.route('/travels') - .post(travelCtrl.addTravel); +apiRoutes.route('/projects') + .post(projectCtrl.addproject); -apiRoutes.route('/travels/:id') - .put(travelCtrl.updateTravel) - .delete(travelCtrl.deleteTravel); +apiRoutes.route('/projects/:id') + .put(projectCtrl.updateproject) + .delete(projectCtrl.deleteproject);*/ app.use('/api', apiRoutes); // end of API routes ------------------------------------- diff --git a/webapp/controllers.js b/webapp/controllers.js index 14cbc52..3be61f6 100644 --- a/webapp/controllers.js +++ b/webapp/controllers.js @@ -1,16 +1,62 @@ +var urlapi = "http://localhost:3000/api/"; angular.module('workApp', ['chart.js']) .controller('workController', function( $scope, - $interval + $interval, + $http ) { - $scope.user={ - username: "idoctnef", - avatar: "toucan", - github: ["github.com/idoctnef", "https://github.com/idoctnef"], - taiga: ["project page", "https://projects.primustech.io"], - totalWorkedTime: 4520 + $scope.currentInclude='login.html'; + if(localStorage.getItem("owt_user")){ + $scope.user=JSON.parse(localStorage.getItem("owt_user")); + $scope.currentInclude="dashboard.html"; + }else{ + //window.location="index.html"; + } + + /* LOGIN SIGNUP */ + $scope.showSignup = function(){ + + }; + $scope.onBtnSignup = function(){ + $scope.user.projects=[]; + $http({ + url: urlapi + 'users', + method: "POST", + data: $scope.user + }).then(function(response) { + window.location="index.html"; + }, + function(response) {// failed + }); }; + + $scope.onBtnLogin = function(){ + $http({ + url: urlapi + 'auth', + method: "POST", + data: $scope.user + }).then(function(response) { + console.log(response); + if(response.data.success) + { + localStorage.setItem("owt_token", angular.toJson(response.data.token)); + localStorage.setItem("owt_user", angular.toJson(response.data.user)); + window.location="dashboard.html"; + }else{ + toastr.error("login error", response.data.message); + } + }, + function(response) {// failed + }); + }; + $scope.onBtnLogout = function(){ + localStorage.removeItem("owt_token"); + localStorage.removeItem("owt_user"); + //window.location.reload(); + }; + /* + + + +
+
+ +
+
+
+ +
+
+
{{user.username}}
+
+
+

+ {{user.description}} +

+

+ {{user.github}} +

+

+ {{user.web}} +

+

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

+







+







+







+







+
+ + +
+
+
+ +
+
+ + +
+
+ + +
+ 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'}} +

+ +
+
+ Work! + Stop! + + +
+
+
+ + + + +
+
+
+ + Select a project + +
+ + +
+
+
diff --git a/webapp/index.html b/webapp/index.html index fc9f6bd..35e66a2 100644 --- a/webapp/index.html +++ b/webapp/index.html @@ -21,147 +21,10 @@ - - -
-
- -
-
-
- -
-
-
{{user.username}}
-
-
-

- {{user.github[0]}} -

-

- {{user.taiga[0]}} -

-

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

-







-







-







-







-
- - -
-
-
- -
-
- - -
-
- - -
- 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'}} -

- -
-
- Work! - Stop! - - -
-
-
- - - - -
-
-
- - Select a project - -
- - -
-
-
- - - + + + + @@ -180,9 +43,6 @@ Works for both browser and electron with the same code --> - - diff --git a/webapp/login.html b/webapp/login.html new file mode 100644 index 0000000..3086848 --- /dev/null +++ b/webapp/login.html @@ -0,0 +1,31 @@ +
+
+
+
+
+
+ Login +
+
+ + +
+
+
+
+ + +
+
+
+ +
+
+
diff --git a/webapp/signup.html b/webapp/signup.html new file mode 100644 index 0000000..f35ccc6 --- /dev/null +++ b/webapp/signup.html @@ -0,0 +1,115 @@ + + + + + + + + + + + + + + + Open Work Time - online version + + + + + + + + +
+
+
+
+
+
+ Signup +
+
+ + +
+
+
+
+ + +
+
+ + +
+
+
+
+ + +
+
+
+
+ + +
+
+ + +
+
+
+
+ + +
+
+ + +
+
+
+ +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + +