mirror of
https://github.com/cnodejs/nodeclub.git
synced 2026-02-01 16:34:28 +00:00
Merge pull request #126 from cnodejs/updateSignFlow
Update sign flow and fixed bug
This commit is contained in:
commit
156d8bba7a
@ -22,45 +22,33 @@ exports.add = function (req, res, next) {
|
||||
return;
|
||||
}
|
||||
|
||||
var proxy = new EventProxy();
|
||||
proxy.assign('reply_saved', 'message_saved', 'score_saved', function () {
|
||||
res.redirect('/topic/' + topic_id);
|
||||
var ep = EventProxy.create('reply_saved', 'message_saved', 'score_saved', function (reply) {
|
||||
res.redirect('/topic/' + topic_id + '#' + reply._id);
|
||||
});
|
||||
ep.fail(next);
|
||||
|
||||
Reply.newAndSave(content, topic_id, req.session.user._id, function (err, reply) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
}
|
||||
Topic.updateLastReply(topic_id, reply._id, function (err) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
}
|
||||
proxy.emit('reply_saved');
|
||||
Reply.newAndSave(content, topic_id, req.session.user._id, ep.done(function (reply) {
|
||||
Topic.updateLastReply(topic_id, reply._id, ep.done(function () {
|
||||
ep.emit('reply_saved', reply);
|
||||
//发送at消息
|
||||
at.sendMessageToMentionUsers(content, topic_id, req.session.user._id);
|
||||
});
|
||||
});
|
||||
}));
|
||||
}));
|
||||
|
||||
Topic.getTopic(topic_id, function (err, topic) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
}
|
||||
Topic.getTopic(topic_id, ep.done(function (topic) {
|
||||
if (topic.author_id.toString() !== req.session.user._id.toString()) {
|
||||
message.sendReplyMessage(topic.author_id, req.session.user._id, topic._id);
|
||||
}
|
||||
proxy.emit('message_saved');
|
||||
});
|
||||
ep.emit('message_saved');
|
||||
}));
|
||||
|
||||
User.getUserById(req.session.user._id, function (err, user) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
}
|
||||
User.getUserById(req.session.user._id, ep.done(function (user) {
|
||||
user.score += 5;
|
||||
user.reply_count += 1;
|
||||
user.save();
|
||||
req.session.user.score += 5;
|
||||
proxy.emit('score_saved');
|
||||
});
|
||||
ep.emit('score_saved');
|
||||
}));
|
||||
};
|
||||
|
||||
/**
|
||||
@ -117,7 +105,11 @@ exports.add_reply2 = function (req, res, next) {
|
||||
*/
|
||||
exports.delete = function (req, res, next) {
|
||||
var reply_id = req.body.reply_id;
|
||||
exports.getReplyById(reply_id, function (err, reply) {
|
||||
Reply.getReplyById(reply_id, function (err, reply) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
}
|
||||
|
||||
if (!reply) {
|
||||
res.json({status: 'failed'});
|
||||
return;
|
||||
|
||||
@ -130,7 +130,9 @@ exports.login = function (req, res, next) {
|
||||
return res.render('sign/signin', { error: '密码错误。' });
|
||||
}
|
||||
if (!user.active) {
|
||||
return res.render('sign/signin', { error: '此帐号还没有被激活。' });
|
||||
// 从新发送激活邮件
|
||||
mail.sendActiveMail(user.email, md5(user.email + config.session_secret), user.name, user.email);
|
||||
return res.render('sign/signin', { error: '此帐号还没有被激活,激活链接已发送到 ' + user.email + ' 邮箱,请查收。' });
|
||||
}
|
||||
// store session cookie
|
||||
gen_session(user, res);
|
||||
@ -156,13 +158,12 @@ exports.signout = function (req, res, next) {
|
||||
exports.active_account = function (req, res, next) {
|
||||
var key = req.query.key;
|
||||
var name = req.query.name;
|
||||
var email = req.query.email;
|
||||
|
||||
User.getUserByName(name, function (err, user) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
}
|
||||
if (!user || md5(email + config.session_secret) !== key) {
|
||||
if (!user || md5(user.email + config.session_secret) !== key) {
|
||||
return res.render('notify/notify', {error: '信息有误,帐号无法被激活。'});
|
||||
}
|
||||
if (user.active) {
|
||||
@ -354,6 +355,7 @@ function md5(str) {
|
||||
str = md5sum.digest('hex');
|
||||
return str;
|
||||
}
|
||||
|
||||
function randomString(size) {
|
||||
size = size || 6;
|
||||
var code_string = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
|
||||
|
||||
@ -173,7 +173,7 @@ exports.put = function (req, res, next) {
|
||||
topic_tag.topic_id = topic._id;
|
||||
topic_tag.tag_id = tag;
|
||||
topic_tag.save(proxy.done('tag_saved'));
|
||||
tag_ctrl.get_tag_by_id(tag, proxy.done(function (tag) {
|
||||
Tag.getTagById(tag, proxy.done(function (tag) {
|
||||
tag.topic_count += 1;
|
||||
tag.save();
|
||||
}));
|
||||
@ -208,7 +208,7 @@ exports.showEdit = function (req, res, next) {
|
||||
res.render('notify/notify', {error: '此话题不存在或已被删除。'});
|
||||
return;
|
||||
}
|
||||
if (topic.author_id === req.session.user._id || req.session.user.is_admin) {
|
||||
if (String(topic.author_id) === req.session.user._id || req.session.user.is_admin) {
|
||||
Tag.getAllTags(function (err, all_tags) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
@ -246,7 +246,7 @@ exports.update = function (req, res, next) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (topic.author_id === req.session.user._id || req.session.user.is_admin) {
|
||||
if (String(topic.author_id) === req.session.user._id || req.session.user.is_admin) {
|
||||
var title = sanitize(req.body.title).trim();
|
||||
title = sanitize(title).xss();
|
||||
var content = req.body.t_content;
|
||||
@ -292,7 +292,7 @@ exports.update = function (req, res, next) {
|
||||
var tags_removed_done = function () {
|
||||
proxy.emit('tags_removed_done');
|
||||
};
|
||||
TopicTag.find({topic_id: topic._id}, function (err, docs) {
|
||||
TopicTag.getTopicTagByTopicId(topic._id, function (err, docs) {
|
||||
if (docs.length === 0) {
|
||||
proxy.emit('tags_removed_done');
|
||||
} else {
|
||||
@ -320,10 +320,7 @@ exports.update = function (req, res, next) {
|
||||
proxy.after('tag_saved', topic_tags.length, tags_saved_done);
|
||||
//save topic tags
|
||||
topic_tags.forEach(function (tag) {
|
||||
var topic_tag = new TopicTag();
|
||||
topic_tag.topic_id = topic._id;
|
||||
topic_tag.tag_id = tag;
|
||||
topic_tag.save(proxy.done('tag_saved'));
|
||||
TopicTag.newAndSave(topic._id, tag, proxy.done('tag_saved'));
|
||||
Tag.getTagById(tag, proxy.done(function (tag) {
|
||||
tag.topic_count += 1;
|
||||
tag.save();
|
||||
@ -331,7 +328,7 @@ exports.update = function (req, res, next) {
|
||||
});
|
||||
}
|
||||
//发送at消息
|
||||
at.sendAtMessage(content, topic._id, req.session.user._id);
|
||||
at.sendMessageToMentionUsers(content, topic._id, req.session.user._id);
|
||||
});
|
||||
}
|
||||
} else {
|
||||
|
||||
@ -5,6 +5,7 @@ var Reply = require('../proxy').Reply;
|
||||
var Relation = require('../proxy').Relation;
|
||||
var TopicCollect = require('../proxy').TopicCollect;
|
||||
var TagCollect = require('../proxy').TagCollect;
|
||||
var utility = require('utility');
|
||||
|
||||
var message = require('../services/message');
|
||||
var Util = require('../libs/util');
|
||||
@ -27,11 +28,17 @@ exports.index = function (req, res, next) {
|
||||
|
||||
var render = function (recent_topics, recent_replies, relation) {
|
||||
user.friendly_create_at = Util.format_date(user.create_at, true);
|
||||
// 如果用户没有激活,那么管理员可以帮忙激活
|
||||
var token = '';
|
||||
if (!user.active && req.session.user && req.session.user.is_admin) {
|
||||
token = utility.md5(user.email + config.session_secret);
|
||||
}
|
||||
res.render('user/index', {
|
||||
user: user,
|
||||
recent_topics: recent_topics,
|
||||
recent_replies: recent_replies,
|
||||
relation: relation
|
||||
relation: relation,
|
||||
token: token,
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
@ -13,6 +13,7 @@
|
||||
"ndir": "0.1.3",
|
||||
"nodemailer": "0.3.43",
|
||||
"data2xml": "0.4.0",
|
||||
"utility": "0.0.x",
|
||||
"xss": "0.0.3"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
||||
@ -173,6 +173,7 @@ exports.updateLastReply = function (topicId, replyId, callback) {
|
||||
topic.last_reply_at = new Date();
|
||||
topic.reply_count += 1;
|
||||
topic.save();
|
||||
callback(null, topic);
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
@ -90,7 +90,7 @@ module.exports = function (app) {
|
||||
// TODO: 如果创建文章的过程太长,导致session过期,界面的内容会丢失
|
||||
// FIXME: 采用前端来判断,不通过跳转的形式来解决
|
||||
app.post('/topic/create', auth.signinRequired, topic.put);
|
||||
app.post('/topic/:tid/edit', topic.edit);
|
||||
app.post('/topic/:tid/edit', topic.update);
|
||||
app.post('/topic/collect', auth.userRequired, topic.collect);
|
||||
app.post('/topic/de_collect', auth.userRequired, topic.de_collect);
|
||||
|
||||
|
||||
@ -52,7 +52,7 @@ exports.sendActiveMail = function (who, token, name, email) {
|
||||
var subject = config.name + '社区帐号激活';
|
||||
var html = '<p>您好:<p/>' +
|
||||
'<p>我们收到您在' + config.name + '社区的注册信息,请点击下面的链接来激活帐户:</p>' +
|
||||
'<a href="' + SITE_ROOT_URL + '/active_account?key=' + token + '&name=' + name + '&email=' + encodeURIComponent(email) + '">激活链接</a>' +
|
||||
'<a href="' + SITE_ROOT_URL + '/active_account?key=' + token + '&name=' + name + '">激活链接</a>' +
|
||||
'<p>若您没有在' + config.name + '社区填写过注册信息,说明有人滥用了您的电子邮箱,请删除此邮件,我们对给您造成的打扰感到抱歉。</p>' +
|
||||
'<p>' + config.name + '社区 谨上。</p>';
|
||||
|
||||
|
||||
@ -1,8 +1,7 @@
|
||||
var models = require('../models'),
|
||||
Message = models.Message;
|
||||
var models = require('../models');
|
||||
var Message = models.Message;
|
||||
var User = require('../proxy').User;
|
||||
var proxy = require('../proxy').Message;
|
||||
|
||||
var messageProxy = require('../proxy/message');
|
||||
var mail = require('./mail');
|
||||
|
||||
exports.sendReplyMessage = function (master_id, author_id, topic_id) {
|
||||
@ -18,7 +17,7 @@ exports.sendReplyMessage = function (master_id, author_id, topic_id) {
|
||||
if (master && master.receive_reply_mail) {
|
||||
message.has_read = true;
|
||||
message.save();
|
||||
proxy.getMessageById(message._id, function (err, msg) {
|
||||
messageProxy.getMessageById(message._id, function (err, msg) {
|
||||
// TODO: 异常处理
|
||||
mail.sendReplyMail(master.email, msg);
|
||||
});
|
||||
@ -40,7 +39,7 @@ exports.sendReply2Message = function (master_id, author_id, topic_id) {
|
||||
if (master && master.receive_reply_mail) {
|
||||
message.has_read = true;
|
||||
message.save();
|
||||
proxy.getMessageById(message._id, function (err, msg) {
|
||||
messageProxy.getMessageById(message._id, function (err, msg) {
|
||||
// TODO: 异常处理
|
||||
mail.sendReplyMail(master.email, msg);
|
||||
});
|
||||
@ -62,7 +61,7 @@ exports.sendAtMessage = function (master_id, author_id, topic_id, callback) {
|
||||
if (master && master.receive_at_mail) {
|
||||
message.has_read = true;
|
||||
message.save();
|
||||
proxy.getMessageById(message._id, function (err, msg) {
|
||||
messageProxy.getMessageById(message._id, function (err, msg) {
|
||||
// TODO: 异常处理
|
||||
mail.sendAtMail(master.email, msg);
|
||||
});
|
||||
|
||||
@ -6,6 +6,7 @@ var ndir = require('ndir');
|
||||
var exec = require('child_process').exec;
|
||||
var should = require('should');
|
||||
var rewire = require("rewire");
|
||||
fs.existsSync = fs.existsSync || path.existsSync;
|
||||
|
||||
describe('controllers/upload.js', function () {
|
||||
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
<div class='cell reply_area reply_item' id="reply<%= indexInCollection+1 %>" reply_id="<%= reply._id %>">
|
||||
<div class='cell reply_area reply_item' id="reply<%= indexInCollection+1 %>" reply_id="<%- reply._id %>">
|
||||
<a id="<%- reply._id %>"></a>
|
||||
<div class='user_avatar'>
|
||||
<a href="/user/<%= reply.author.name %>"><img src="<%= reply.author.avatar_url %>" title="<%= reply.author.name %>" /></a>
|
||||
</div>
|
||||
@ -14,7 +15,7 @@
|
||||
</span>
|
||||
<span class='reply_author'><a class='dark' href="/user/<%= reply.author.name %>"><%= reply.author.name %></a></span>
|
||||
<span class='col_fade'>
|
||||
在 <%= reply.friendly_create_at %>回复
|
||||
在 <a href="#<%- reply._id %>"><%= reply.friendly_create_at %></a> 回复
|
||||
<% if(locals.current_user && current_user._id.toString() == reply.author._id.toString()) { %>
|
||||
<span class='sp10'></span>
|
||||
<a href='javascript:void(0);' class='delete_reply_btn'><img class='user_icon' src="<%- config.site_static_host %>/images/trash_icon&16.png" title='删除' /></a>
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
<div class='cell reply2_item' reply_id='<%= reply._id %>'>
|
||||
<a id="<%- reply._id %>"></a>
|
||||
<div class='user_avatar'>
|
||||
<a href="/user/<%= reply.author.name %>"><img src="<%= reply.author.avatar_url %>" title="<%= reply.author.name %>" /></a>
|
||||
</div>
|
||||
@ -9,11 +10,12 @@
|
||||
<% } %>
|
||||
</span>
|
||||
<span class='col_fade'>
|
||||
在 <%= reply.friendly_create_at %>回复
|
||||
<% if (locals.current_user && current_user._id.toString() == reply.author._id.toString()) { %>
|
||||
在 <a href="#<%- reply._id %>"><%= reply.friendly_create_at %></a> 回复
|
||||
<% if (locals.current_user && current_user._id.toString() == reply.author._id.toString()) { %>
|
||||
<span class='sp10'></span>
|
||||
<a href='javascript:void(0)' class='delete_reply2_btn'><img class='user_icon' src="<%- config.site_static_host %>/images/trash_icon&16.png" title='删除' /></a>
|
||||
<% } %>
|
||||
<a href='javascript:void(0)' class='delete_reply2_btn'><img class='user_icon'
|
||||
src="<%- config.site_static_host %>/images/trash_icon&16.png" title='删除' /></a>
|
||||
<% } %>
|
||||
</span>
|
||||
<!-- <div class='sep5'></div> -->
|
||||
<div class='reply_content'>
|
||||
|
||||
@ -28,13 +28,17 @@
|
||||
<label class='control-label' for='pass'>密码</label>
|
||||
<div class='controls'>
|
||||
<input class='input-xlarge' id='pass' name='pass' size='30' type='password' />
|
||||
<p class='help-block'> <a href='/search_pass'>我忘记了密码</a></p>
|
||||
</div>
|
||||
</div>
|
||||
<input type='hidden' name='_csrf' value='<%= csrf %>' />
|
||||
<div class='form-actions'>
|
||||
<input type='submit' class='btn' value='登录' />
|
||||
</div>
|
||||
<div class='control-group'>
|
||||
<div class='controls'>
|
||||
<a href='/search_pass'>忘记密码了?</a>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@ -60,7 +60,10 @@
|
||||
<button class='btn' id='set_star_btn' action='cancel_star'>取消达人</button>
|
||||
<% } %>
|
||||
<br/><br/>
|
||||
Email (Seen by Administrator): <a href="email:<%= user.email %>"><%= user.email %></a>
|
||||
Email (Seen by Administrator): <a href="mailto:<%= user.email %>"><%= user.email %></a>
|
||||
<% if (!user.active) { %>
|
||||
<a class='btn' href="/active_account?key=<%- locals.token %>&name=<%= user.name %>" target="_blank">激活账号</a>
|
||||
<% } %>
|
||||
<% } %>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user