mirror of
https://github.com/arnaucube/openworktime.git
synced 2026-02-06 19:26:41 +01:00
users system more implemented
This commit is contained in:
@@ -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'
|
||||
});
|
||||
}
|
||||
|
||||
});
|
||||
};
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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;
|
||||
});
|
||||
|
||||
};
|
||||
/* </DASHBOARD initialization */
|
||||
|
||||
|
||||
$scope.user={};
|
||||
if(localStorage.getItem("owt_user")){
|
||||
$scope.user=JSON.parse(localStorage.getItem("owt_user"));
|
||||
$scope.currentInclude="dashboard.html";
|
||||
$scope.dashboardInit();
|
||||
}else{
|
||||
//window.location="index.html";
|
||||
$scope.currentInclude="login.html";
|
||||
}
|
||||
|
||||
/* LOGIN SIGNUP */
|
||||
$scope.showSignup = function(){
|
||||
|
||||
$scope.currentInclude="signup.html";
|
||||
};
|
||||
$scope.hideSignup = function(){
|
||||
$scope.currentInclude="login.html";
|
||||
};
|
||||
$scope.onBtnSignup = function(){
|
||||
$scope.user.projects=[];
|
||||
@@ -25,10 +56,11 @@ angular.module('workApp', ['chart.js'])
|
||||
method: "POST",
|
||||
data: $scope.user
|
||||
}).then(function(response) {
|
||||
window.location="index.html";
|
||||
$scope.currentInclude="login.html";
|
||||
},
|
||||
function(response) {// failed
|
||||
});
|
||||
|
||||
};
|
||||
|
||||
$scope.onBtnLogin = function(){
|
||||
@@ -37,26 +69,43 @@ angular.module('workApp', ['chart.js'])
|
||||
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_token", response.data.token);
|
||||
localStorage.setItem("owt_user", angular.toJson(response.data.user));
|
||||
window.location="dashboard.html";
|
||||
$scope.user=JSON.parse(localStorage.getItem("owt_user"));
|
||||
|
||||
$scope.currentInclude="dashboard.html";
|
||||
$scope.dashboardInit();
|
||||
var intervalGetData;
|
||||
intervalGetData = $interval(function(){
|
||||
$scope.dashboardInit();
|
||||
}, 10000);
|
||||
}else{
|
||||
toastr.error("login error", response.data.message);
|
||||
toastr.error(response.data.message);
|
||||
}
|
||||
},
|
||||
function(response) {// failed
|
||||
});
|
||||
};
|
||||
$scope.onBtnLogout = function(){
|
||||
$http({
|
||||
url: urlapi + 'logout',
|
||||
method: "POST",
|
||||
data: $scope.user
|
||||
}).then(function(response) {
|
||||
localStorage.removeItem("owt_token");
|
||||
localStorage.removeItem("owt_user");
|
||||
//window.location.reload();
|
||||
$scope.currentInclude="login.html";
|
||||
},
|
||||
function(response) {// failed
|
||||
});
|
||||
};
|
||||
/* </ LOGIN SIGNUP */
|
||||
|
||||
|
||||
|
||||
|
||||
//localStorage.clear();
|
||||
$scope.working=false;
|
||||
$scope.projects=[];
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
|
||||
|
||||
|
||||
<nav>
|
||||
<nav>
|
||||
<div class="nav-wrapper blue-grey darken-4">
|
||||
<a href="#" class="brand-logo">Open Work Time <small>- v0.1</small></a>
|
||||
<ul id="nav-mobile" class="right">
|
||||
@@ -22,9 +22,9 @@
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</nav>
|
||||
</nav>
|
||||
|
||||
<div class="row">
|
||||
<div class="row">
|
||||
<div class="col s12 m4 l2 blue-grey darken-3 white-text">
|
||||
<!-- Grey navigation panel -->
|
||||
<br>
|
||||
@@ -45,13 +45,17 @@
|
||||
<p>
|
||||
<a ng-href="http://{{user.web}}" target="_blank">{{user.web}}</a>
|
||||
</p>
|
||||
<p>
|
||||
<!--<p>
|
||||
Total worked time: {{user.totalWorkedTime | secondsToDateTime | date:'HH:mm'}}h
|
||||
</p>
|
||||
<br/><br/><br/><br/><br/><br/><br/><br/>
|
||||
<br/><br/><br/><br/><br/><br/><br/><br/>
|
||||
<br/><br/><br/><br/><br/><br/><br/><br/>
|
||||
<br/><br/><br/><br/><br/><br/><br/><br/>
|
||||
</p>-->
|
||||
<ul class="collection">
|
||||
<li ng-repeat="user in users" class="collection-item avatar blue-grey darken-3">
|
||||
<img ng-src="img/avatars/{{user.avatar}}.png" class="circle">
|
||||
<span class="title">{{user.username}}</span>
|
||||
<span ng-show="user.connected" class="new badge" data-badge-caption="online"></span>
|
||||
<p>{{user.description}}</p>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -139,4 +143,4 @@
|
||||
|
||||
</div><!-- </row -->
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -1,33 +1,5 @@
|
||||
|
||||
<!DOCTYPE html>
|
||||
<html ng-app="workApp">
|
||||
<head>
|
||||
<!--Import Google Icon Font-->
|
||||
<link href="fonts/icons.css" rel="stylesheet">
|
||||
<!--Import materialize.css-->
|
||||
<link type="text/css" rel="stylesheet" href="css/materialize.min.css" media="screen,projection"/>
|
||||
|
||||
|
||||
<link type="text/css" rel="stylesheet" href="own.css"/>
|
||||
|
||||
<!--Let browser know website is optimized for mobile-->
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
|
||||
<title>Open Work Time - online version</title>
|
||||
|
||||
|
||||
<style>
|
||||
body{
|
||||
background: #ffffff; /* fallback for old browsers */
|
||||
background: -webkit-linear-gradient(to left, #ffffff , #37474f); /* Chrome 10-25, Safari 5.1-6 */
|
||||
background: linear-gradient(to left, #ffffff , #37474f); /* W3C, IE 10+/ Edge, Firefox 16+, Chrome 26+, Opera 12+, Safari 7+ */
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body ng-controller="loginController as login" class="grey lighten-2">
|
||||
|
||||
|
||||
<div class="row">
|
||||
<div class="row">
|
||||
<div class="col s0 m2 l3">
|
||||
</div>
|
||||
<div class="col s12 m8 l6">
|
||||
@@ -78,7 +50,7 @@
|
||||
</div>
|
||||
</div>
|
||||
<div class="card-action">
|
||||
<a href="index.html" class="waves-effect waves-light btn red lighten-2">
|
||||
<a ng-click="hideSignup()" class="waves-effect waves-light btn red lighten-2">
|
||||
<i class="material-icons left">not_interested</i>Cancel
|
||||
</a>
|
||||
<a ng-click="onBtnSignup()" class="waves-effect waves-light btn green lighten-2 right">
|
||||
@@ -87,29 +59,4 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
|
||||
<!-- ANGULAR -->
|
||||
<script src="libraries/angular.min.js"></script>
|
||||
|
||||
<!-- ANGULAR CHART JS -->
|
||||
<script src="node_modules/chart.js/dist/Chart.min.js"></script>
|
||||
<script src="node_modules/angular-chart.js/dist/angular-chart.min.js"></script>
|
||||
|
||||
|
||||
<!--Import jQuery before materialize.js-->
|
||||
<script type="text/javascript" src="js/jquery-2.1.1.min.js"></script>
|
||||
<script type="text/javascript" src="js/materialize.min.js"></script>
|
||||
|
||||
<script src="controllers.js"></script>
|
||||
|
||||
<script src="libraries/toastr.js"></script>
|
||||
<link type="text/css" rel="stylesheet" href="libraries/toastr.css"/>
|
||||
|
||||
|
||||
|
||||
</body>
|
||||
</html>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user