Skip to content

Commit

Permalink
- User authorize;
Browse files Browse the repository at this point in the history
- Multiple images upload;
- Image hota(Inspired by https://github.com/jiguang/hota);
- Bugfix & code optimization.
  • Loading branch information
aNd1coder committed Dec 18, 2015
1 parent d1f9e27 commit d2e8906
Show file tree
Hide file tree
Showing 27 changed files with 1,159 additions and 98 deletions.
41 changes: 38 additions & 3 deletions app.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,59 @@
var express = require('express');
var path = require('path');
var favicon = require('serve-favicon');
//var favicon = require('serve-favicon');
var logger = require('morgan');
var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');

var expressValidator = require('express-validator');
var session = require('express-session');
var MongoStore = require('connect-mongo')(session);
var app = express();
var mongo = require('./config/database')['development'].mongo;

// view engine setup
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'jade');

// uncomment after placing your favicon in /public
//app.use(favicon(path.join(__dirname, 'public', 'favicon.ico')));
app.use(logger('dev'));
app.use(session({
secret: 'page_factory',
// 每次请求都刷新cookie过期时间
resave: true,
// 无论有没有session cookie,每次请求都设置个session cookie ,默认给个标示为 connect.sid
saveUninitialized: false,
cookie: {
secure: false, // https
maxAge: 1000 * 60 * 60 * 24 * 30 // 30 days
},
store: new MongoStore({
db: mongo.db.pageFactory,
host: mongo.host,
username: mongo.username,
password: mongo.password
})
}));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: false}));
app.use(expressValidator());
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));

app.use(function (req, res, next) {
var url = req.originalUrl, segments = url.split('?')[0].split('/');

res.locals.controllerName = segments[1];
res.locals.actionName = segments[2] || 'index';

if (url != "/authorize" && !req.session.user) {
return res.redirect("/authorize?next=" + encodeURIComponent(url));
} else {
res.locals.user = req.session.user;
}

next();
});

// routes
require('./routes')(app);

Expand Down
2 changes: 1 addition & 1 deletion bs-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ module.exports = {
"port": 8080
}
},
"files": ['public/css/*.css,public/js/*.js'],
"files": ['**/*.css'],
"watchOptions": {},
"server": false,
"proxy": 'localhost:3000',
Expand Down
3 changes: 1 addition & 2 deletions config/database.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
// db 访问配置
module.exports = {
development: {
mongo: {
host: '127.0.0.1',
username: 'root',
password: '123456',
port: '27017',
database: {
db: {
pageFactory: 'page_factory'
}
}
Expand Down
2 changes: 1 addition & 1 deletion config/mongo.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ var env = process.env.NODE_ENV || 'development';
var config = require('./database')[env].mongo;
var mongoagent = mongoose.createConnection(util.format(
'mongodb://%s:%s@%s:%s/%s',
config.username, config.password, config.host, config.port, config.database.pageFactory
config.username, config.password, config.host, config.port, config.db.pageFactory
), {
server: {
poolSize: 4
Expand Down
8 changes: 8 additions & 0 deletions config/setting.sample.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
module.exports = {
api: {
authorize: {
app: 'app',
key: 'key',
url: '/path/to/authorize/api'
},
upload: '/path/to/upload/api'
},
ssiServer: {
dev: {
host: '127.0.0.1',
Expand Down
11 changes: 10 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,25 @@
},
"dependencies": {
"body-parser": "~1.13.2",
"connect-mongo": "^0.8.2",
"connect-multiparty": "^2.0.0",
"cookie-parser": "~1.3.5",
"debug": "~2.2.0",
"express": "~4.13.1",
"express-session": "^1.12.1",
"express-validator": "^2.18.0",
"jade": "~1.11.0",
"kerberos": "0.0.17",
"lodash": "^3.10.1",
"moment": "^2.10.6",
"mongoose": "^4.2.7",
"morgan": "~1.6.1",
"serve-favicon": "~2.3.0",
"ssh2": "^0.4.12",
"superagent": "^1.5.0"
"superagent": "^1.5.0",
"superagent-promise": "^1.0.3"
},
"devDependencies": {
"superagent-proxy": "^1.0.0"
}
}
156 changes: 144 additions & 12 deletions public/css/app.css
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
body {
font: 12px "Lucida Grande", Helvetica, Arial, sans-serif;
font: 12px "lucida grande", helvetica, arial, sans-serif;
background-color: #fff;
}

Expand Down Expand Up @@ -32,26 +32,59 @@ body {
padding: 10px;
}

.nav > li > a:hover,
.navbar-nav > li > a {
padding-left: 20px;
padding-right: 20px;
}

.navbar-nav .open > a,
.navbar-nav .open > a:focus,
.navbar-nav .open > a:hover,
.navbar-nav > li > a:hover,
.navbar-nav > li > a:focus,
.page-page .nav-page a,
.page-template .nav-template a,
.page-module .nav-module a {
.page-module .nav-module a,
.page-upload .nav-upload a,
.page-hota .nav-hota a {
color: #fff;
background-color: #222;
}

.navbar-brand {
background-color: #337ab7;
color: #fff;
.navbar-brand, .navbar-brand h1, .navbar-brand small {
font-size: 18px;
transition: all .2s ease-in;
}

.navbar-brand h1 {
display: inline-block;
margin: 0;
font-family: Monaco, Courier;
color: #4dc67e;
}

.navbar-brand:hover {
color: #fff;
background-color: #222;
}

.navbar-brand:hover h1 {
color: #6897bb;
}

.navbar-brand:hover small {
color: #4dc67e;
}

.navbar-brand small {
display: block;
font-size: 12px;
color: #6897bb;
margin-left: 10px;
}

.navbar-nav > li > .dropdown-menu {
min-width: 0;
width: 100%;
border-top: none;
text-shadow: none;
}

.table a {
Expand Down Expand Up @@ -117,7 +150,16 @@ input[type=checkbox] {
}

.form .btn {
margin-right: 20px;
margin-left: 10px;
}

.form-action {
text-align: right;
}

.form-action .btn {
width: 100px;
margin-left: 20px;
}

.pagination {
Expand Down Expand Up @@ -179,14 +221,18 @@ input[type=checkbox] {
width: 100%;
height: 300px;
text-align: center;
content: '点击此处编辑内容';
content: '点击编辑';
color: #fff;
font: bold 30px/300px 'Microsoft YaHei';
font: bold 30px/300px 'microsoft yahei';
background-color: rgba(0, 0, 0, .6);
border-radius: 4px;
cursor: pointer;
}

textarea.form-control, .html-editor:after {
border-top-left-radius: 0;
}

textarea.form-control {
height: 300px;
resize: none;
Expand All @@ -198,4 +244,90 @@ textarea.form-control {

.nav-tabs > li {
margin-bottom: 0;
}

.nav-tabs > li > a {
font-weight: 700;
color: #333;
}

.nav-tabs > li > a:hover {
border-color: #eee;
}

.form-authorize {
width: 350px;
margin: 100px auto;
}

.form-authorize .page-header {
margin-top: 10px;
}

.form-authorize .alert {
margin-bottom: 5px;
}

.form-authorize li {
margin-left: 15px;
}

.form-uploader {
margin-bottom: 20px;
padding: 50px 0;
text-align: center;
font-size: 20px;
border: 3px dashed #ccc;
color: #ddd;
}

.form-uploader .or {
margin: 10px 0;
font-size: 16px;
color: #e9e9e9;
}

.form-uploader .uploadify {
margin: 0 auto;
}

.form-uploader .uploadify-button {
line-height: 1.5em !important;
border: 1px solid #ccc;
color: #999;
border-radius: 3px;
text-shadow: none;
}

.form-uploader .uploadify-button {
background: #fff;
}

.form-uploader .uploadify:hover .uploadify-button {
background: #fff;
color: #888;
border-color: #888;
}

.form-uploader .glyphicon-upload {
top: 2px;
margin-right: 2px;
}

.form-uploader .uploadify-queue {
margin-top: 20px;
}

.form-uploader .uploadify-queue-item {
max-width: 100% !important;
margin: 5px 10px 0;
}

.list-files .btn {
margin-left: 5px;
padding: 1px 10px;
}

.list-files .list-group-item-heading {
margin-bottom: 0;
}
Loading

0 comments on commit d2e8906

Please sign in to comment.