Skip to content

Commit

Permalink
submit & add some feature to finish the end of project
Browse files Browse the repository at this point in the history
  • Loading branch information
lanseria committed Mar 23, 2017
1 parent 3932f90 commit 323a6cb
Show file tree
Hide file tree
Showing 47 changed files with 301 additions and 230 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,6 @@ node_modules

# Debug log from npm
npm-debug.log

# csv
*.csv
12 changes: 10 additions & 2 deletions app/controllers/member.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ var Msgtemplate = require('../models/msgtemplate');
var Message = require('../models/message');
//exports importCSV
exports.importCSV = function(req, res){
Member.remove({}, function(err){
Member.remove({user: req.session.user._id}, function(err){
console.log('---clean db ---------------------------------------');
if (err) {
console.log('Member remove all occur a error:', err);
Expand Down Expand Up @@ -118,7 +118,11 @@ exports.beganMass = function(req, res){
}
})
})
return res.json({success:1});
var id = req.session.thekey._id;
Thekey.update({_id:id}, {$inc:{issue:1}}, function(err){
if (err) {console.log(err);}
return res.json({success:1});
})
})
})
})
Expand All @@ -131,6 +135,10 @@ exports.beganMassing = function(req, res){
req.session.message = '请先配置群发消息';
return res.redirect('/configMass');
}
if (req.session.thekey==null) {
req.session.message = '请先申请资格';
return res.redirect('/applyKey');
}
Member.find({user: userid}, function(err, members){
if (err) {
console.log(err);
Expand Down
75 changes: 75 additions & 0 deletions app/controllers/thekey.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
var Thekey = require('../models/thekey');
var uuid = require('node-uuid');

exports.setCancel = function(req, res){
var id = req.body.kid;
Thekey.update({_id:id}, {$inc:{issue:2}}, function(err){
if (err) {console.log(err);}
return res.json({success:1});
})
}

exports.setAccept = function(req, res){
var id = req.body.kid;
Thekey.update({_id:id}, {$inc:{issue:1}}, function(err){
if (err) {console.log(err);}
return res.json({success:1});
})
}

exports.keyList = function(req, res){
Thekey
.find({})
.populate('user', 'name')
.exec(function(err, thekeys){
console.log(thekeys);
res.render('keyList', {
isSub: true,
keylistjs: true,
baseurl: req.url,
thekeys: thekeys,
});
})
}

exports.applyKey = function(req, res){
Thekey.findOne({user: req.session.user._id}, function(err, thekey){
if (err) {console.log(err);}
console.log(thekey);
if (thekey==null) {
var thekey = {
newkey: '这里不要求您填入',
};
}
res.render('applyKey', {
isSub: true,
applykeyjs: true,
baseurl: req.url,
thekey: thekey,
});

})
}

exports.genUuid = function(req, res){
Thekey.remove({user: req.session.user._id}, function(err){
console.log('---clean db ---------------------------------------');
if (err) {
console.log('Thekey remove all occur a error:', err);
} else {
console.log('Thekey remove all success.');
}
})
var newkey = uuid.v1();
var uid = req.body.uid;
var _thekey = {
newkey: newkey,
user: uid,
issue: 0,
};
var thekey = new Thekey(_thekey);
thekey.save(function(err, thekey){
if (err) {console.log(err);}
return res.json({success:1});
})
}
16 changes: 9 additions & 7 deletions app/controllers/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,6 @@ exports.homePage = function(req, res){
});
}

exports.applyKey = function(req, res){
res.render('applyKey', {
isSub: true,
baseurl: req.url,
});
}

exports.showSignin = function(req, res){
res.render('signin', {
title: '管理员登录'
Expand Down Expand Up @@ -142,4 +135,13 @@ exports.signinRequired = function(req, res, next){
return res.redirect('/signin');
}
next();
}
// middleware for user
exports.adminRequired = function(req, res, next){
var user = req.session.user;
console.log(user);
if(user.role <= 10){
return res.redirect('/signin');
}
next();
}
5 changes: 5 additions & 0 deletions app/models/thekey.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
var mongoose = require('mongoose');
var thekeySchema = require('../schemas/thekey');
var thekey = mongoose.model('Thekey', thekeySchema);

module.exports = thekey
50 changes: 50 additions & 0 deletions app/schemas/thekey.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
var mongoose = require('mongoose');
var Schema = mongoose.Schema;
var ObjectId = Schema.Types.ObjectId;
var ThekeySchema = new Schema({
newkey: {
type: String,
},
issue: {
type: Number,
default: 0,
},
user:{
type: ObjectId,
ref:'User'
},
meta:{
createAt:{
type:Date,
default:Date.now()
},
updateAt:{
type:Date,
default:Date.now()
}
}
});
ThekeySchema.pre('save', function (next) {
if (this.isNew) {
this.meta.createAt = this.meta.updateAt = Date.now()
} else {
this.meta.updateAt = Date.now();
}
next()
})
ThekeySchema.statics = {
fetch:function(cb){
return this
.find({})
.sort('meta.updateAt')
.exec(cb);
},
findById:function(id, cb){
return this
.findOne({
_id:id
})
.exec(cb);
}
}
module.exports = ThekeySchema;
2 changes: 1 addition & 1 deletion app/views/includes/footer.pug
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
footer.site-footer
.text-center
| 2014 - 2017 redesigned by lanseria origin Alvarez.is
a.go-top(href='/index')
a.go-top(href='#')
i.fa.fa-angle-up
// footer end
4 changes: 4 additions & 0 deletions app/views/layout.pug
Original file line number Diff line number Diff line change
Expand Up @@ -155,4 +155,8 @@ html(lang='zh_CN')
script(src="/javascripts/configMass.js")
if massjs
script(src="/javascripts/began_ajax.js")
if applykeyjs
script(src="/javascripts/applyKey.js")
if keylistjs
script(src="/javascripts/keylist.js")

23 changes: 21 additions & 2 deletions app/views/pages/applyKey.pug
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ block content
.row.mt
.col-lg-12
.form-panel
if message
.alert.alert-warning.alert-dismissable
button.close(type='button', data-dismiss='alert', aria-hidden='true') &times;
strong #{message}
h4.mb
i.fa.fa-angle-right
| 申请KEY
Expand All @@ -24,6 +28,21 @@ block content
.form-group
label.col-sm-2.col-sm-2.control-label 原密钥KEY
.col-sm-10
input#disabledInput.form-control(type='text', placeholder='这里不要求您填入', disabled='')
input#disabledInput.form-control(type='text', placeholder=thekey.newkey, disabled='')
.form-group
button.btn.btn-info.btn-lg.col-sm-6.col-sm-offset-3(type='button') 申请
label.col-sm-2.col-sm-2.control-label 状态
.col-sm-10
case thekey.issue
when 0
span.label.label-warning 申请中
when 1
span.label.label-info 可使用
when 2
span.label.label-danger 失效
default
span.label.label-danger 失效
.form-group
if thekey.issue<=1
button.btn.btn-info.btn-lg.col-sm-6.col-sm-offset-3.apply(type='button', data-uid=user._id, disabled='disabled') 申请
else
button.btn.btn-info.btn-lg.col-sm-6.col-sm-offset-3.apply(type='button', data-uid=user._id) 申请
43 changes: 43 additions & 0 deletions app/views/pages/keyList.pug
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
extends ../layout

block content
.row
.col-md-12.mt
.content-panel
table.table.table-hover
h4
i.fa.fa-angle-right
| Keys
hr
thead
tr
th #
th NewKey
th Name
th Status
th 操作
tbody
each item, idx in thekeys
tr
td #{idx}
td #{item.newkey}
td #{item.user.name}
td
case item.issue
when 0
span.label.label-warning 申请中
when 1
span.label.label-info 可使用
when 2
span.label.label-danger 失效
default
span.label.label-danger 失效
td
if item.issue==0
button.btn.btn-info.btn-xs.accept(data-kid=item._id)
i.fa.fa-file-o
| Accept
button.btn.btn-danger.btn-xs.cancel(data-kid=item._id)
i.fa.fa-trash-o
| Cancel
// /col-md-12
3 changes: 3 additions & 0 deletions config.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ var config = {
},{
name: '申请key',
url: '/applyKey',
},{
name: 'keyList',
url: '/keyList',
}
],
}, //homePage
Expand Down
Empty file added db/msgweb/members.bson
Empty file.
1 change: 1 addition & 0 deletions db/msgweb/members.metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"options":{},"indexes":[{"v":2,"key":{"_id":1},"name":"_id_","ns":"msgweb.members"}]}
Empty file added db/msgweb/messages.bson
Empty file.
1 change: 1 addition & 0 deletions db/msgweb/messages.metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"options":{},"indexes":[{"v":2,"key":{"_id":1},"name":"_id_","ns":"msgweb.messages"},{"v":2,"unique":true,"key":{"groupid":1},"name":"groupid_1","ns":"msgweb.messages","background":true}]}
Empty file added db/msgweb/msgtemplates.bson
Empty file.
1 change: 1 addition & 0 deletions db/msgweb/msgtemplates.metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"options":{},"indexes":[{"v":2,"key":{"_id":1},"name":"_id_","ns":"msgweb.msgtemplates"}]}
Empty file added db/msgweb/sessions.bson
Empty file.
1 change: 1 addition & 0 deletions db/msgweb/sessions.metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"options":{},"indexes":[{"v":2,"key":{"_id":1},"name":"_id_","ns":"msgweb.sessions"},{"v":2,"key":{"expires":1},"name":"expires_1","ns":"msgweb.sessions","expireAfterSeconds":0}]}
Binary file added db/msgweb/smstemplates.bson
Binary file not shown.
1 change: 1 addition & 0 deletions db/msgweb/smstemplates.metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"options":{},"indexes":[{"v":2,"key":{"_id":1},"name":"_id_","ns":"msgweb.smstemplates"}]}
Empty file added db/msgweb/thekeys.bson
Empty file.
1 change: 1 addition & 0 deletions db/msgweb/thekeys.metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"options":{},"indexes":[{"v":2,"key":{"_id":1},"name":"_id_","ns":"msgweb.thekeys"}]}
Binary file added db/msgweb/users.bson
Binary file not shown.
1 change: 1 addition & 0 deletions db/msgweb/users.metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"options":{},"indexes":[{"v":2,"key":{"_id":1},"name":"_id_","ns":"msgweb.users"},{"v":2,"unique":true,"key":{"name":1},"name":"name_1","ns":"msgweb.users","background":true}]}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"mongoose": "^4.9.1",
"morgan": "^1.8.1",
"node-csv": "^0.1.2",
"node-uuid": "^1.4.8",
"pug": "^2.0.0-beta11",
"serve-favicon": "^2.4.1",
"trim": "0.0.1",
Expand Down
1 change: 0 additions & 1 deletion public/assets/css/bootstrap.css
Original file line number Diff line number Diff line change
Expand Up @@ -6200,4 +6200,3 @@ button.close {
display: none !important;
}
}
/*# sourceMappingURL=bootstrap.css.map */
17 changes: 17 additions & 0 deletions public/javascripts/applyKey.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
$(function(){
$('.apply').click(function(e){
var target = $(e.target);
var uid = target.data('uid');
var url = '/genUuid';
var data = {
uid: uid,
}
var success = function(res){
if (res.success === 1) {
alert('申请成功,请等待Root同意');
window.location.href="/applyKey ";
}
}
$.post( url, data, success, 'json');
})
})
4 changes: 1 addition & 3 deletions public/javascripts/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,10 @@ $(document).ready(function () {
text: '这里计价为0.05元/条短信,更多我的网站请来<a href="https://limonplayer.cn" target="_blank" style="color:#ffd777">limonplayer.cn</a>.',
// (string | optional) the image to display on the left
image: '/assets/img/ui-zac.jpg',
// (bool | optional) if you want it to fade out on its own or just sit there
sticky: true,
// (int | optional) the time you want it to be alive for before fading out
time: 3000,
// (string | optional) the class name you want to apply to that specific message
class_name: 'my-sticky-class'
class_name: 'gritter-light'
});
return false;
});
Loading

0 comments on commit 323a6cb

Please sign in to comment.