diff --git a/app.js b/app.js index df9cbe1..e2cb1ac 100644 --- a/app.js +++ b/app.js @@ -4,6 +4,7 @@ var favicon = require('serve-favicon'); var logger = require('morgan'); var cookieParser = require('cookie-parser'); var bodyParser = require('body-parser'); +var session = require('express-session'); var routes = require('./routes/index'); var users = require('./routes/users'); @@ -22,11 +23,14 @@ app.use(bodyParser.json()); app.use(bodyParser.urlencoded({ extended: false })); -app.use(cookieParser()); +app.use(cookieParser('Wilson')); +app.use(session({ + secret: 'wilson' +})); app.use(express.static(path.join(__dirname, 'public'))); -app.use('/api', api); app.use('/', routes); +app.use('/api', api); app.use('/users', users); // catch 404 and forward to error handler diff --git a/package.json b/package.json index df88dcd..e0e5384 100644 --- a/package.json +++ b/package.json @@ -11,6 +11,7 @@ "debug": "~2.2.0", "ejs": "~2.4.1", "express": "~4.13.4", + "express-session": "^1.14.1", "morgan": "~1.7.0", "mysql": "^2.11.1", "serve-favicon": "~2.3.0", diff --git a/public/index.html b/public/index.html index af88a76..f6d7293 100644 --- a/public/index.html +++ b/public/index.html @@ -1,45 +1,42 @@ - - - - - - - 我的书签 - - - - - - - - -
- - -
-
-
+ + + + + + 我的书签 + + + + + + +
+ + +
+
+
+
+
+ +
-
- - -
- - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + diff --git a/public/scripts/app-angular.js b/public/scripts/app-angular.js index a845b9a..7530e43 100644 --- a/public/scripts/app-angular.js +++ b/public/scripts/app-angular.js @@ -13,7 +13,6 @@ app.config(function($stateProvider, $urlRouterProvider) { bar: null }, controller: 'bookmarksCtr' - }) .state('addBookmark', { url: '/addBookmark', @@ -32,16 +31,13 @@ app.config(function($stateProvider, $urlRouterProvider) { url: '/settings', templateUrl: '/views/settings.html', }) - .state('register', { - url: '/register', - templateUrl: '/views/register.html' - }) - .state('intro', { - url: '/intro', - templateUrl: '/views/intro.html' + .state('login', { + url: '/login', + templateUrl: '/views/login.html' }) .state('/', { url: '/', - templateUrl: '/views/intro.html' + templateUrl: '/views/home.html', + controller: 'homeCtr' }); }); diff --git a/public/scripts/controllers/home-controller.js b/public/scripts/controllers/home-controller.js new file mode 100644 index 0000000..78850a2 --- /dev/null +++ b/public/scripts/controllers/home-controller.js @@ -0,0 +1,14 @@ +app.controller('homeCtr', ['$scope', '$stateParams', '$filter', '$window', 'bookmarkService', 'pubSubService', function($scope, $stateParams, $filter, $window, bookmarkService, pubSubService) { + console.log('Hello homeCtr......'); + var params = { + a: 1111 + }; + bookmarkService.autoLogin(params).then( + function(data) { + console.log(data); + }, + function(errorMsg) { + console.log(errorMsg); + } + ); +}]); diff --git a/public/scripts/controllers/menus-controller.js b/public/scripts/controllers/menus-controller.js index 1581e13..5ddab67 100644 --- a/public/scripts/controllers/menus-controller.js +++ b/public/scripts/controllers/menus-controller.js @@ -1,5 +1,5 @@ app.controller('menuCtr', ['$scope', '$state', 'pubSubService', function($scope, $state, pubSubService) { - $scope.login = true; /**< 是否登陆 */ + $scope.login = false; /**< 是否登陆 */ $scope.selectLoginIndex = 0; /**< 默认登陆之后的选择的菜单索引,下表从 0 开始 */ $scope.selectNotLoginIndex = 0; /**< 默认未登陆之后的选择的菜单索引,下表从 0 开始 */ $scope.keyword = ''; /**< 搜索关键字 */ @@ -8,14 +8,14 @@ app.controller('menuCtr', ['$scope', '$state', 'pubSubService', function($scope, /** * @todo http://stackoverflow.com/questions/31449948/ui-router-state-go-not-working */ - if ($scope.login) { - setTimeout(() => { - $state.go('bookmarks', { - foo: 'i love you', - bar: 'hello world' - }) - }, 0); - } + // if ($scope.login) { + // setTimeout(() => { + // $state.go('bookmarks', { + // foo: 'i love you', + // bar: 'hello world' + // }) + // }, 0); + // } // 登陆之后显示的菜单数据。uiSerf:内部跳转链接。 $scope.loginMenus = [{ @@ -37,11 +37,11 @@ app.controller('menuCtr', ['$scope', '$state', 'pubSubService', function($scope, // 未登陆显示的菜单数据 $scope.notLoginMenus = [{ - uiSref: 'intro', - title: '说明' + uiSref: '/', + title: '首页' }, { - uiSref: 'register', - title: '注册' + uiSref: 'login', + title: '登陆' }]; /** diff --git a/public/scripts/services/bookmark-service.js b/public/scripts/services/bookmark-service.js index 0ad537b..9355e8a 100644 --- a/public/scripts/services/bookmark-service.js +++ b/public/scripts/services/bookmark-service.js @@ -1,12 +1,26 @@ app.factory('bookmarkService', ['$http', '$q', function($http, $q) { // service interface var service = { + autoLogin: function(params) { + var def = $q.defer(); + $http.get('/api/autoLogin/', { + params: params + }) + .success(function(data) { + def.resolve(data); + }) + .error(function(data) { + console.log('Error: ' + data); + def.reject('Failed to get todos'); + }); + return def.promise; + }, /** * @func * @desc 根据显示页数的索引,获取书签的数据 * @param {object} params - 参数 */ - getBookmarks: function getBookmarks(params) { + getBookmarks: function(params) { var def = $q.defer(); $http.get('/api/bookmarks/', { diff --git a/public/views/intro.html b/public/views/home.html similarity index 100% rename from public/views/intro.html rename to public/views/home.html diff --git a/public/views/login.html b/public/views/login.html new file mode 100644 index 0000000..433a032 --- /dev/null +++ b/public/views/login.html @@ -0,0 +1,3 @@ +

+ 这是登陆界面 +

diff --git a/public/views/menus.html b/public/views/menus.html index 29c1ad3..bbd2dbe 100644 --- a/public/views/menus.html +++ b/public/views/menus.html @@ -1,6 +1,6 @@
-
添加书签
@@ -57,10 +54,5 @@
diff --git a/public/views/register.html b/public/views/register.html deleted file mode 100644 index ef30dad..0000000 --- a/public/views/register.html +++ /dev/null @@ -1 +0,0 @@ -

这是注册界面

diff --git a/routes/api.js b/routes/api.js index a01361d..e89f38c 100644 --- a/routes/api.js +++ b/routes/api.js @@ -18,6 +18,13 @@ var client = mysql.createConnection({ }); client.connect(); +api.get('/autoLogin', function(req, res) { + console.log('autoLogin......'); + res.json({ + data: "autoLogin reply", + }); +}); + api.get('/bookmarks', function(req, res) { console.log('hello bookmarks', JSON.stringify(req.query)); if (req.query.show === 'navigate') { diff --git a/routes/index.js b/routes/index.js index ecca96a..0834099 100644 --- a/routes/index.js +++ b/routes/index.js @@ -3,7 +3,10 @@ var router = express.Router(); /* GET home page. */ router.get('/', function(req, res, next) { - res.render('index', { title: 'Express' }); + console.log('Hello , i enter index'); + // res.render('index', { + // title: 'Express' + // }); }); module.exports = router;