增加了登陆逻辑
This commit is contained in:
parent
f1fe08948c
commit
698ca52666
2
app.js
2
app.js
|
|
@ -30,7 +30,7 @@ app.use(session({
|
||||||
saveUninitialized: true, //添加这行
|
saveUninitialized: true, //添加这行
|
||||||
secret: 'ILoveYiJia', // 建议使用 128 个字符的随机字符串
|
secret: 'ILoveYiJia', // 建议使用 128 个字符的随机字符串
|
||||||
cookie: {
|
cookie: {
|
||||||
maxAge: 60 * 1000
|
maxAge: 3600 * 24 * 30
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"body-parser": "~1.15.1",
|
"body-parser": "~1.15.1",
|
||||||
"cookie-parser": "~1.4.3",
|
"cookie-parser": "~1.4.3",
|
||||||
|
"crypto": "0.0.3",
|
||||||
"debug": "~2.2.0",
|
"debug": "~2.2.0",
|
||||||
"ejs": "~2.4.1",
|
"ejs": "~2.4.1",
|
||||||
"express": "~4.13.4",
|
"express": "~4.13.4",
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html lang="en">
|
<html lang="en">
|
||||||
|
|
||||||
<head>
|
<head>
|
||||||
<meta charset="utf-8">
|
<meta charset="utf-8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
|
@ -11,6 +12,7 @@
|
||||||
<link href="/css/style.css " rel="stylesheet" />
|
<link href="/css/style.css " rel="stylesheet" />
|
||||||
<base href="/">
|
<base href="/">
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body ng-app="bookmarkApp">
|
<body ng-app="bookmarkApp">
|
||||||
<div class="ui container ">
|
<div class="ui container ">
|
||||||
<!-- directive:菜单 -->
|
<!-- directive:菜单 -->
|
||||||
|
|
@ -28,6 +30,7 @@
|
||||||
<script src="/scripts/externe/angular-ui-router.min.js"></script>
|
<script src="/scripts/externe/angular-ui-router.min.js"></script>
|
||||||
<script src="/scripts/app-angular.js"></script>
|
<script src="/scripts/app-angular.js"></script>
|
||||||
<script src="/scripts/services/bookmark-service.js"></script>
|
<script src="/scripts/services/bookmark-service.js"></script>
|
||||||
|
<script src="/scripts/services/data-service.js"></script>
|
||||||
<script src="/scripts/services/pub-sub-service.js"></script>
|
<script src="/scripts/services/pub-sub-service.js"></script>
|
||||||
<script src="/scripts/directives/edit-directive.js"></script>
|
<script src="/scripts/directives/edit-directive.js"></script>
|
||||||
<script src="/scripts/directives/menus-directive.js"></script>
|
<script src="/scripts/directives/menus-directive.js"></script>
|
||||||
|
|
@ -40,4 +43,5 @@
|
||||||
<script src="/scripts/externe/semantic.min.js"></script>
|
<script src="/scripts/externe/semantic.min.js"></script>
|
||||||
<script src="/scripts/externe/calendar.min.js"></script>
|
<script src="/scripts/externe/calendar.min.js"></script>
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
</html>
|
</html>
|
||||||
|
|
|
||||||
|
|
@ -48,3 +48,7 @@ app.config(function($stateProvider, $urlRouterProvider) {
|
||||||
controller: 'homeCtr'
|
controller: 'homeCtr'
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
app.config(function ($httpProvider) {
|
||||||
|
$httpProvider.interceptors.push('TokenInterceptor');
|
||||||
|
});
|
||||||
|
|
|
||||||
|
|
@ -1,19 +1,19 @@
|
||||||
app.controller('bookmarksCtr', ['$scope', '$stateParams', '$filter', '$window', 'bookmarkService', 'pubSubService', function($scope, $stateParams, $filter, $window, bookmarkService, pubSubService) {
|
app.controller('bookmarksCtr', ['$scope', '$state', '$stateParams', '$filter', '$window', 'bookmarkService', 'pubSubService', function($scope, $state, $stateParams, $filter, $window, bookmarkService, pubSubService) {
|
||||||
console.log("Hello bookmarksCtr...", $stateParams);
|
console.log("Hello bookmarksCtr...", $stateParams);
|
||||||
$scope.bookmarks = []; // 书签数据
|
$scope.bookmarks = []; // 书签数据
|
||||||
$scope.showSearch = false; // 书签数据
|
$scope.showSearch = false; // 书签数据
|
||||||
|
$scope.hoverItem = true;
|
||||||
$scope.showStyle = 'navigate'; // 显示风格'navigate', 'card', 'table'
|
$scope.showStyle = 'navigate'; // 显示风格'navigate', 'card', 'table'
|
||||||
semanticInit();
|
semanticInit();
|
||||||
|
|
||||||
var params = {
|
var params = {
|
||||||
show: $scope.showStyle,
|
show: $scope.showStyle,
|
||||||
}
|
}
|
||||||
getBookmarks(params);
|
|
||||||
$scope.jumpToUrl = function(url) {
|
$scope.jumpToUrl = function(url) {
|
||||||
console.log(url);
|
|
||||||
$window.open(url, '_blank');
|
$window.open(url, '_blank');
|
||||||
}
|
}
|
||||||
|
getBookmarks(params);
|
||||||
pubSubService.subscribe('MenuCtr.bookmarks', $scope, function(event, params) {
|
pubSubService.subscribe('MenuCtr.bookmarks', $scope, function(event, params) {
|
||||||
console.log('subscribe MenuCtr.bookmarks', params);
|
console.log('subscribe MenuCtr.bookmarks', params);
|
||||||
getBookmarks(params);
|
getBookmarks(params);
|
||||||
|
|
@ -33,9 +33,16 @@ app.controller('bookmarksCtr', ['$scope', '$stateParams', '$filter', '$window',
|
||||||
bookmarkService.getBookmarks(params).then(
|
bookmarkService.getBookmarks(params).then(
|
||||||
function(data) {
|
function(data) {
|
||||||
$scope.bookmarks = data;
|
$scope.bookmarks = data;
|
||||||
|
pubSubService.publish('loginCtr.login', {
|
||||||
|
'login': true,
|
||||||
|
});
|
||||||
},
|
},
|
||||||
function(errorMsg) {
|
function(data) {
|
||||||
console.log(errorMsg);
|
console.log(data);
|
||||||
|
$state.go('/');
|
||||||
|
pubSubService.publish('loginCtr.login', {
|
||||||
|
'login': false,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,10 @@
|
||||||
app.controller('editCtr', ['$scope', '$state', '$timeout', 'bookmarkService', 'pubSubService', function($scope, $state, $timeout, bookmarkService, pubSubService) {
|
app.controller('editCtr', ['$scope', '$state', '$timeout', 'bookmarkService', 'pubSubService', function($scope, $state, $timeout, bookmarkService, pubSubService) {
|
||||||
var maxSelections = 3;
|
var maxSelections = 3;
|
||||||
console.log("Hello , I enter editCtr...");
|
console.log("Hello , editCtr...");
|
||||||
init();
|
init();
|
||||||
semanticInit();
|
semanticInit();
|
||||||
|
|
||||||
$scope.$watch('url', function(newValue, oldValue, scope) {
|
$scope.$watch('url', function(newValue, oldValue, scope) {
|
||||||
console.log('url is changed', $('.ui.modal.js-add-bookmark').modal('is active'));
|
|
||||||
$timeout(function() {
|
$timeout(function() {
|
||||||
$scope.urlError = $scope.url == '' && $('.ui.modal.js-add-bookmark').modal('is active');
|
$scope.urlError = $scope.url == '' && $('.ui.modal.js-add-bookmark').modal('is active');
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,18 @@
|
||||||
app.controller('homeCtr', ['$scope', '$stateParams', '$filter', '$window', 'bookmarkService', 'pubSubService', function($scope, $stateParams, $filter, $window, bookmarkService, pubSubService) {
|
app.controller('homeCtr', ['$scope', '$stateParams', '$filter', '$state', '$window', 'bookmarkService', 'pubSubService', function($scope, $stateParams, $filter, $state, $window, bookmarkService, pubSubService) {
|
||||||
console.log('Hello homeCtr......');
|
console.log('Hello homeCtr......');
|
||||||
var params = {
|
bookmarkService.autoLogin().then(
|
||||||
userName: 'luchenqun',
|
|
||||||
pwd: '123456',
|
|
||||||
};
|
|
||||||
bookmarkService.autoLogin(params).then(
|
|
||||||
function(data) {
|
function(data) {
|
||||||
console.log(data);
|
console.log(data);
|
||||||
|
if (data.logined) {
|
||||||
|
pubSubService.publish('loginCtr.login', {
|
||||||
|
'login': data.logined,
|
||||||
|
});
|
||||||
|
$state.go('bookmarks', {
|
||||||
|
showStyle: 'navigate',
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
console.log('login failed......................')
|
||||||
|
}
|
||||||
},
|
},
|
||||||
function(errorMsg) {
|
function(errorMsg) {
|
||||||
console.log(errorMsg);
|
console.log(errorMsg);
|
||||||
|
|
|
||||||
|
|
@ -1,47 +1,43 @@
|
||||||
app.controller('loginCtr', ['$scope', '$filter', '$state', 'bookmarkService', 'pubSubService', function($scope, $filter, $state, bookmarkService, pubSubService) {
|
app.controller('loginCtr', ['$scope', '$filter', '$state', 'bookmarkService', 'pubSubService', function($scope, $filter, $state, bookmarkService, pubSubService) {
|
||||||
console.log("Hello loginCtr...");
|
console.log("Hello loginCtr...");
|
||||||
|
|
||||||
$scope.userName = "";
|
$scope.username = "luchenqun";
|
||||||
$scope.pwd = "";
|
$scope.password = "fendoubuxi";
|
||||||
$scope.showErr = false;
|
$scope.showErr = false;
|
||||||
$scope.errInfo = '';
|
$scope.errInfo = '';
|
||||||
|
|
||||||
$scope.login = function() {
|
$scope.login = function() {
|
||||||
var atuoLogin = $('.ui.checkbox.js-auto-login').checkbox('is checked');
|
var autoLogin = $('.ui.checkbox.js-auto-login').checkbox('is checked');
|
||||||
if (!$scope.userName || !$scope.pwd) {
|
if (!$scope.username || !$scope.password) {
|
||||||
$scope.showErr = true;
|
$scope.showErr = true;
|
||||||
$scope.errInfo = '用户明或者密码不能为空!';
|
$scope.errInfo = '用户明或者密码不能为空!';
|
||||||
} else {
|
} else {
|
||||||
$scope.showErr = false;
|
$scope.showErr = false;
|
||||||
$scope.errInfo = '';
|
$scope.errInfo = '';
|
||||||
console.log($scope.userName, $scope.pwd, atuoLogin);
|
console.log($scope.username, $scope.password, autoLogin);
|
||||||
|
var params = {
|
||||||
|
username: $scope.username,
|
||||||
|
password:$scope.password,
|
||||||
|
autoLogin:autoLogin,
|
||||||
|
};
|
||||||
|
bookmarkService.login(params).then(
|
||||||
|
function(data) {
|
||||||
|
console.log(data);
|
||||||
|
if (data.logined) {
|
||||||
|
pubSubService.publish('loginCtr.login', {
|
||||||
|
'login': data.logined,
|
||||||
|
});
|
||||||
|
$state.go('bookmarks', {
|
||||||
|
showStyle: 'navigate',
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
console.log('login failed......................')
|
||||||
|
}
|
||||||
|
},
|
||||||
|
function(errorMsg) {
|
||||||
|
console.log(errorMsg);
|
||||||
|
}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// login({
|
|
||||||
// userName: 'luchenqun',
|
|
||||||
// pwd: '123456',
|
|
||||||
// });
|
|
||||||
//
|
|
||||||
// function login(params) {
|
|
||||||
// bookmarkService.login(params).then(
|
|
||||||
// function(data) {
|
|
||||||
// console.log(data);
|
|
||||||
// if (data.logined) {
|
|
||||||
// pubSubService.publish('loginCtr.login', {
|
|
||||||
// 'login': data.logined,
|
|
||||||
// });
|
|
||||||
// $state.go('bookmarks', {
|
|
||||||
// showStyle: 'navigate',
|
|
||||||
// })
|
|
||||||
// } else {
|
|
||||||
// console.log('login failed......................')
|
|
||||||
// }
|
|
||||||
// },
|
|
||||||
// function(errorMsg) {
|
|
||||||
// console.log(errorMsg);
|
|
||||||
// }
|
|
||||||
// );
|
|
||||||
// }
|
|
||||||
|
|
||||||
}]);
|
}]);
|
||||||
|
|
|
||||||
|
|
@ -29,11 +29,9 @@ app.factory('bookmarkService', ['$http', '$q', function($http, $q) {
|
||||||
});
|
});
|
||||||
return def.promise;
|
return def.promise;
|
||||||
},
|
},
|
||||||
autoLogin: function(params) {
|
autoLogin: function() {
|
||||||
var def = $q.defer();
|
var def = $q.defer();
|
||||||
$http.get('/api/autoLogin/', {
|
$http.get('/api/autoLogin/')
|
||||||
params: params
|
|
||||||
})
|
|
||||||
.success(function(data) {
|
.success(function(data) {
|
||||||
def.resolve(data);
|
def.resolve(data);
|
||||||
})
|
})
|
||||||
|
|
@ -57,8 +55,8 @@ app.factory('bookmarkService', ['$http', '$q', function($http, $q) {
|
||||||
.success(function(data) {
|
.success(function(data) {
|
||||||
def.resolve(data);
|
def.resolve(data);
|
||||||
})
|
})
|
||||||
.error(function(data) {
|
.error(function(data, status) {
|
||||||
console.log('Error: ' + data);
|
console.log('Error: ' + data, status);
|
||||||
def.reject('Failed to get todos');
|
def.reject('Failed to get todos');
|
||||||
});
|
});
|
||||||
return def.promise;
|
return def.promise;
|
||||||
|
|
@ -120,3 +118,48 @@ app.factory('bookmarkService', ['$http', '$q', function($http, $q) {
|
||||||
|
|
||||||
return service;
|
return service;
|
||||||
}]);
|
}]);
|
||||||
|
|
||||||
|
app.factory('AuthenticationService', function() {
|
||||||
|
var auth = {
|
||||||
|
isAuthenticated: false,
|
||||||
|
isAdmin: false
|
||||||
|
}
|
||||||
|
|
||||||
|
return auth;
|
||||||
|
});
|
||||||
|
|
||||||
|
app.factory('TokenInterceptor', function ($q, $window, $location, AuthenticationService) {
|
||||||
|
return {
|
||||||
|
request: function (config) {
|
||||||
|
config.headers = config.headers || {};
|
||||||
|
if ($window.sessionStorage.token) {
|
||||||
|
config.headers.Authorization = 'Bearer ' + $window.sessionStorage.token;
|
||||||
|
}
|
||||||
|
return config;
|
||||||
|
},
|
||||||
|
|
||||||
|
requestError: function(rejection) {
|
||||||
|
return $q.reject(rejection);
|
||||||
|
},
|
||||||
|
|
||||||
|
/* Set Authentication.isAuthenticated to true if 200 received */
|
||||||
|
response: function (response) {
|
||||||
|
if (response != null && response.status == 200 && $window.sessionStorage.token && !AuthenticationService.isAuthenticated) {
|
||||||
|
AuthenticationService.isAuthenticated = true;
|
||||||
|
}
|
||||||
|
return response || $q.when(response);
|
||||||
|
},
|
||||||
|
|
||||||
|
/* Revoke client authentication if 401 is received */
|
||||||
|
responseError: function(rejection) {
|
||||||
|
if (rejection != null && rejection.status === 401 && ($window.sessionStorage.token || AuthenticationService.isAuthenticated)) {
|
||||||
|
delete $window.sessionStorage.token;
|
||||||
|
AuthenticationService.isAuthenticated = false;
|
||||||
|
// $location.path("/admin/login");
|
||||||
|
console.log('responseError')
|
||||||
|
}
|
||||||
|
|
||||||
|
return $q.reject(rejection);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,13 @@
|
||||||
|
app.factory('dataService', [function() {
|
||||||
|
var service = {
|
||||||
|
loginParams: function() {
|
||||||
|
return {
|
||||||
|
username:'',
|
||||||
|
password:'',
|
||||||
|
autoLogin:true,
|
||||||
|
};
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
return service;
|
||||||
|
}]);
|
||||||
|
|
@ -21,9 +21,10 @@
|
||||||
<div class="ui grid container">
|
<div class="ui grid container">
|
||||||
<div class="two wide column">
|
<div class="two wide column">
|
||||||
<i class="bookmark icon"></i><span>{{ tag.name }} </span>
|
<i class="bookmark icon"></i><span>{{ tag.name }} </span>
|
||||||
|
<span>{{ hoverItem }}</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="two wide column js-navigate-bookmark" ng-repeat="bookmark in tag.bookmarks" ng-click="jumpToUrl(bookmark.url)">
|
<div class="two wide column js-navigate-bookmark" ng-class="{div-hover:hoverItem}" ng-mouseover="hoverItem=true" ng-mouseleave="hoverItem=false" ng-repeat="bookmark in tag.bookmarks" ng-click="jumpToUrl(bookmark.url)">
|
||||||
<img class="ui ui middle aligned tiny image" src="http://api.byi.pw/favicon/?url={{ bookmark.url }}" style="width:16px;height:16px">
|
<img class="ui ui middle aligned tiny image" src="http://api.byi.pw/favicon/?url={{ bookmark.url }}" style="width:16px;height:16px">
|
||||||
<span>{{ bookmark.title}}</span>
|
<span>{{ bookmark.title}}</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -7,14 +7,14 @@
|
||||||
<div class="required field">
|
<div class="required field">
|
||||||
<label>用户名</label>
|
<label>用户名</label>
|
||||||
<div class="ui icon input">
|
<div class="ui icon input">
|
||||||
<input type="text" ng-model="userName">
|
<input type="text" ng-model="username">
|
||||||
<i class="user icon"></i>
|
<i class="user icon"></i>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="required field">
|
<div class="required field">
|
||||||
<label>密码</label>
|
<label>密码</label>
|
||||||
<div class="ui icon input">
|
<div class="ui icon input">
|
||||||
<input type="password" ng-model="pwd">
|
<input type="password" ng-model="password">
|
||||||
<i class="lock icon"></i>
|
<i class="lock icon"></i>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -1,77 +1,87 @@
|
||||||
var api = require('express').Router();
|
var api = require('express').Router();
|
||||||
var mysql = require('mysql');
|
var mysql = require('mysql');
|
||||||
// var client = mysql.createConnection({
|
var crypto = require('crypto');
|
||||||
// host: '172.24.13.5',
|
|
||||||
// user: 'root',
|
|
||||||
// password: 'root123',
|
|
||||||
// database: 'mybookmarks',
|
|
||||||
// multipleStatements: true,
|
|
||||||
// port: 3306
|
|
||||||
// });
|
|
||||||
var client = mysql.createConnection({
|
var client = mysql.createConnection({
|
||||||
host: '127.0.0.1',
|
host: '172.24.13.5',
|
||||||
user: 'lcq',
|
user: 'root',
|
||||||
password: '123456',
|
password: 'root123',
|
||||||
database: 'mybookmarks',
|
database: 'mybookmarks',
|
||||||
multipleStatements: true,
|
multipleStatements: true,
|
||||||
port: 3306
|
port: 3306
|
||||||
});
|
});
|
||||||
|
// var client = mysql.createConnection({
|
||||||
|
// host: '127.0.0.1',
|
||||||
|
// user: 'lcq',
|
||||||
|
// password: '123456',
|
||||||
|
// database: 'mybookmarks',
|
||||||
|
// multipleStatements: true,
|
||||||
|
// port: 3306
|
||||||
|
// });
|
||||||
client.connect();
|
client.connect();
|
||||||
|
|
||||||
api.post('/logout', function(req, res) {
|
api.post('/logout', function(req, res) {
|
||||||
var params = req.body.params;
|
var params = req.body.params;
|
||||||
console.log('logout......', params);
|
console.log('logout......', params);
|
||||||
var userName = params.userName;
|
req.session.destroy();
|
||||||
req.session.destroy(function(err) {
|
|
||||||
|
|
||||||
});
|
|
||||||
res.json({
|
res.json({
|
||||||
data: "logout success",
|
data: "logout success",
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
api.post('/login', function(req, res) {
|
api.post('/login', function(req, res) {
|
||||||
var params = req.body.params;
|
var params = req.body.params;
|
||||||
console.log('login......', params);
|
var username = params.username;
|
||||||
var userName = params.userName;
|
var password = md5(params.password);
|
||||||
var pwd = params.pwd;
|
console.log('login......', params, password);
|
||||||
var logined = Math.random() > 0.5;
|
|
||||||
if (logined) {
|
|
||||||
res.cookie('isLogin', userName, {
|
|
||||||
maxAge: 60000
|
|
||||||
});
|
|
||||||
req.session.userName = userName;
|
|
||||||
console.log(req.session.userName);
|
|
||||||
} else {
|
|
||||||
|
|
||||||
|
var sql = "SELECT * FROM `users` WHERE `username` = '"+ username +"'";
|
||||||
|
client.query(sql, function(error, result, fields) {
|
||||||
|
var id = '';
|
||||||
|
var logined = false;
|
||||||
|
console.log(password, result[0].password)
|
||||||
|
if (!error && result.length === 1 && password === result[0].password) {
|
||||||
|
req.session.username = username;
|
||||||
|
logined = true;
|
||||||
|
id = result[0].id;
|
||||||
}
|
}
|
||||||
res.json({
|
res.json({
|
||||||
logined: logined,
|
logined: logined,
|
||||||
|
userId:id
|
||||||
});
|
});
|
||||||
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
api.get('/autoLogin', function(req, res) {
|
api.get('/autoLogin', function(req, res) {
|
||||||
console.log('autoLogin......', req.body.params);
|
if (req.session.username) {
|
||||||
// if (req.cookies.isLogin) {
|
console.log('session:' + req.session.username);
|
||||||
// console.log('cookies:' + req.cookies.isLogin);
|
var sql = "SELECT * FROM `users` WHERE `username` = '"+ req.session.username +"'";
|
||||||
// req.session.userName = req.cookies.isLogin;
|
client.query(sql, function(error, result, fields) {
|
||||||
// }
|
var id = '';
|
||||||
|
var logined = false;
|
||||||
if (req.session.userName) {
|
if (!error && result.length === 1) {
|
||||||
console.log('session:' + req.session.userName);
|
req.session.username = result[0].username;
|
||||||
|
req.session.id = result[0].id;
|
||||||
|
logined = true;
|
||||||
|
id = result[0].id;
|
||||||
|
}
|
||||||
res.json({
|
res.json({
|
||||||
data: "you have auto login",
|
logined: logined,
|
||||||
|
userId:id,
|
||||||
});
|
});
|
||||||
|
})
|
||||||
} else {
|
} else {
|
||||||
res.json({
|
res.json({
|
||||||
data: "Please Login",
|
logined: false,
|
||||||
|
userId:'',
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
api.get('/bookmarks', function(req, res) {
|
api.get('/bookmarks', function(req, res) {
|
||||||
console.log('hello bookmarks', JSON.stringify(req.query));
|
console.log('hello bookmarks', JSON.stringify(req.query));
|
||||||
|
if (!req.session.username) {
|
||||||
|
res.send(401);
|
||||||
|
}
|
||||||
if (req.query.show === 'navigate') {
|
if (req.query.show === 'navigate') {
|
||||||
var sql = "SELECT t.id as tag_id, t.name as tag_name, b.* FROM `tags` as t LEFT OUTER JOIN tags_bookmarks as tb ON t.id = tb.tag_id LEFT OUTER JOIN bookmarks as b ON tb.bookmark_id = b.id ORDER BY t.id ASC, b.click_count DESC";
|
var sql = "SELECT t.id as tag_id, t.name as tag_name, b.* FROM `tags` as t LEFT OUTER JOIN tags_bookmarks as tb ON t.id = tb.tag_id LEFT OUTER JOIN bookmarks as b ON tb.bookmark_id = b.id ORDER BY t.id ASC, b.click_count DESC";
|
||||||
client.query(sql, function(error, result, fields) {
|
client.query(sql, function(error, result, fields) {
|
||||||
|
|
@ -296,4 +306,11 @@ api.post('/addTags', function(req, res) {
|
||||||
});
|
});
|
||||||
// client.end();
|
// client.end();
|
||||||
|
|
||||||
|
function md5(str) {
|
||||||
|
return crypto
|
||||||
|
.createHash('md5')
|
||||||
|
.update(str)
|
||||||
|
.digest('hex');
|
||||||
|
};
|
||||||
|
|
||||||
module.exports = api;
|
module.exports = api;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue