Skip to content

Commit 8a32f64

Browse files
author
Frand
committed
wait to deal error
1 parent 612b988 commit 8a32f64

File tree

9 files changed

+82
-33
lines changed

9 files changed

+82
-33
lines changed

app.js

+14
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,14 @@ app
3131
.use(less('public', {
3232
dest: publicPath
3333
}))
34+
.use(function* (next){
35+
try{
36+
yield* next;
37+
}catch(err){
38+
console.log('err happen', err);
39+
this.body = err;
40+
}
41+
})
3442
.use(koabody())
3543
.use(mount(routes))
3644
.use(mount(router.allowedMethods()))
@@ -40,6 +48,12 @@ app
4048
});
4149
});
4250

51+
// app.on('error', function(err){
52+
// this.status = '200';
53+
// this.body = err;
54+
// // this.render('registry', {config: err});
55+
// });
56+
4357
// listen on port 3000
4458
app.listen(3000);
4559

common/logger.js

-17
This file was deleted.

controller/user.js

+10-4
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,14 @@ exports.registry = function* (){
1717
pass = req.password,
1818
signature = req.signature;
1919

20-
yield this.render('registry', {
21-
config: config,
22-
user: {name:'Frand'}
23-
});
20+
let user = new User();
21+
22+
user.name = uname;
23+
user.loginname = loginname;
24+
user.password = pass;
25+
user.email = email;
26+
user.signature = signature;
27+
28+
yield user
29+
.save();
2430
};

models/mongodb/index.js

+6-7
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
'use strict';
22

33
let mongoose = require('mongoose'),
4-
config = require('../../config'),
5-
logger = require('../../common/logger');
4+
config = require('../../config');
65

76
/**
87
* mongodb connect by mongoose
@@ -14,16 +13,16 @@ mongoose.connect(config.mongodb.db, {
1413
}
1514
}, (err) => {
1615
if (err) {
17-
logger.error('connect to %s error: ', config.mongodb.db, err.message);
16+
console.error('connect to %s error: ', config.mongodb.db, err.message);
1817
process.exit(1);
1918
}
2019
});
2120

2221
// models
23-
require('./mongodb/user');
24-
require('./mongodb/topic');
25-
require('./mongodb/reply');
26-
require('./mongodb/message');
22+
require('./user');
23+
require('./topic');
24+
require('./reply');
25+
require('./message');
2726

2827
exports.User = mongoose.model('User');
2928
exports.Topic = mongoose.model('Topic');

models/mongodb/topic.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
'use strict';
22

33
let mongoose = require('mongoose'),
4-
ObjectId = Schema.ObjectId,
5-
Schema = mongoose.Schema;
4+
Schema = mongoose.Schema,
5+
ObjectId = Schema.ObjectId;
66

77
let topicSchema = new Schema({
88
title: String,

models/mongodb/user.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@ let userSchema = new Schema({
88
loginname: String,
99
password: String,
1010
createAt: {type: Date, default: Date.now},
11+
signature: String,
1112
email: String,
12-
isBlock: Boolean
13+
isBlock: {type: Boolean, default: false}
1314
});
1415

1516
// define user schema index

public/css/_partial/content.less

+4
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,8 @@
5252
width: 80px;
5353
font-size: inherit;
5454
}
55+
56+
.notEmpty{
57+
border: #ee5f5b solid 1px;
58+
}
5559
}

public/css/style.css

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/scripts/registry.js

+43-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,45 @@
11
define(['jquery'], function($){
2-
console.log('enter registry');
2+
// list all registry forms
3+
var $username = $('input[name=username]'),
4+
$loginname = $('input[name=loginname]'),
5+
$email = $('input[name=email]'),
6+
$password = $('input[name=password]'),
7+
$confirmpass = $('input[name=confirmpass]'),
8+
$signature = $('input[name=signature]');
9+
10+
var validateEmpty = function(val, ctx){
11+
if(!$.trim(val)){
12+
$(ctx).addClass('notEmpty');
13+
}else{
14+
$(ctx).removeClass('notEmpty');
15+
}
16+
};
17+
18+
var blurs = [$username, $loginname, $email, $password, $confirmpass],
19+
len = blurs.length;
20+
21+
for(var i = 0; i < len; i++){
22+
blurs[i].blur(function(){
23+
validateEmpty($(this).val(), this);
24+
});
25+
}
26+
27+
// 验证确认密码
28+
$confirmpass.blur(function(){
29+
var val = $(this).val(),
30+
confirmpass = $password.val();
31+
32+
if($.trim(val) !== $.trim(confirmpass)){
33+
alert('两次输入密码不一致');
34+
$(this).val('');
35+
}
36+
});
37+
38+
// submit form
39+
$('.registryUser').click(function(){
40+
var hasError = $('.notEmpty').length;
41+
if(!hasError){
42+
$(this).parent().submit();
43+
}
44+
});
345
});

0 commit comments

Comments
 (0)