Skip to content

Commit

Permalink
add: 新用户发帖/回帖要先打赏一次
Browse files Browse the repository at this point in the history
remove: geetest的验证码不靠谱,事实证明会被破解
  • Loading branch information
wendal committed Jul 7, 2018
1 parent 6f9e078 commit ea14854
Show file tree
Hide file tree
Showing 14 changed files with 87 additions and 364 deletions.
Expand Up @@ -61,15 +61,15 @@
<li class="dropdown user user-menu">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">
<img src="${base}/user/avatar/me" class="user-image" alt="User Image">
<span class="hidden-xs">${profile.nickname}</span>
<span class="hidden-xs">${profile.nickname!}</span>
</a>
<ul class="dropdown-menu">
<!-- User image -->
<li class="user-header">
<img src="${base}/assets/adminlte/dist/img/user2-160x160.jpg" class="img-circle" alt="User Image">

<p>
${profile.nickname} - ${profile.loginname}
${profile.nickname!} - ${profile.loginname!}
<small>Member since Nov. 2012</small>
</p>
</li>
Expand Down Expand Up @@ -117,7 +117,7 @@
<img src="${base}/user/avatar/me" class="img-circle" alt="User Image">
</div>
<div class="pull-left info">
<p>${profile.nickname}</p>
<p>${profile.nickname!}</p>
<a href="#"><i class="fa fa-circle text-success"></i> Online</a>
</div>
</div>
Expand Down
Expand Up @@ -105,15 +105,15 @@ public Object create(@Param("to")int toUserId,
@Param("title")String title,
@Param("amount")int amount,
@ReqHeader("Referer")String referer) {
if (amount == 0) {
amount = R.random(88, 1088);
}
else if (amount < 88)
amount = 188;
if (amount < 38)
amount = 38;
String id = R.UU32();
if (Strings.isBlank(title)) {
UserProfile profile = dao.fetch(UserProfile.class, toUserId);
title = String.format("打赏给%s %s", profile.getDisplayName(), id);
if (profile == null)
title = String.format("打赏给%s %s", "管理员", id);
else
title = String.format("打赏给%s %s", profile.getDisplayName(), id);
if (title.length() > 16)
title = title.substring(0, 16);
}
Expand Down
Expand Up @@ -116,6 +116,7 @@ public void init(NutConfig nc) {
if (admin == null) {
admin = us.add("admin", "123456");
}
us.getUserProfile(admin.getId(), false);
// 初始化游客用户
User guest = dao.fetch(User.class, "guest");
if (guest == null) {
Expand All @@ -124,6 +125,7 @@ public void init(NutConfig nc) {
profile.setNickname("游客");
dao.update(profile, "nickname");
}
us.getUserProfile(guest.getId(), false);

// 获取NutQuartzCronJobFactory从而触发计划任务的初始化与启动
ioc.get(NutQuartzCronJobFactory.class);
Expand Down
Expand Up @@ -101,8 +101,20 @@ public int getUserScore(long userId) {
}
}
public UserProfile getUserProfile(long uid, boolean avatar) {
UserProfile profile = null;
if (avatar)
return dao().fetch(UserProfile.class, uid);
return Daos.ext(dao(), FieldFilter.locked(UserProfile.class, "avatar")).fetch(UserProfile.class, uid);
profile = dao().fetch(UserProfile.class, uid);
profile = Daos.ext(dao(), FieldFilter.locked(UserProfile.class, "avatar")).fetch(UserProfile.class, uid);
if (profile == null) {
User user = dao().fetch(User.class, uid);
if (user == null)
return null;
profile = new UserProfile();
profile.setUserId(user.getId());
profile.setLoginname(user.getName());
profile.setNickname(user.getName());
dao().insert(profile);
}
return profile;
}
}
3 changes: 0 additions & 3 deletions nutzcn-webapp/src/main/resources/doc/about.md
Expand Up @@ -21,10 +21,7 @@ iOS客户端 [ios客户端](https://itunes.apple.com/us/app/nutz-she-qu/id108219

* [Nutz官网](https://www.nutzam.com)
* [NutzBook Nutz入门指南](http://nutzbook.wendal.net)
* [查找网](http://www.chazhao.me)
* [七牛云存储 移动时代的云存储服务商](http://www.qiniu.com/)
* [一米阳光(大鲨鱼的个人博客)](http://www.wizzer.cn/)
* [邓华锋](http://www.denghuafeng.com/)

### 有爱的公众号

Expand Down
Expand Up @@ -12,7 +12,6 @@
import java.util.Map;
import java.util.Set;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

Expand Down Expand Up @@ -57,7 +56,6 @@
import net.wendal.nutzbook.core.bean.UserProfile;
import net.wendal.nutzbook.core.module.BaseModule;
import net.wendal.nutzbook.core.service.AppPushService;
import net.wendal.nutzbook.core.service.GtService;
import net.wendal.nutzbook.core.service.RedisDao;
import net.wendal.nutzbook.yvr.bean.SubForum;
import net.wendal.nutzbook.yvr.bean.Topic;
Expand Down Expand Up @@ -101,9 +99,6 @@ public void index() {

@Inject
protected AppPushService appPushService;

@Inject
protected GtService gtService;

@GET
@At
Expand All @@ -112,12 +107,12 @@ public void index() {
public Object add(HttpSession session) {
NutMap re = new NutMap();
re.put("types", TopicType.values());

String csrf = R.UU32();
jedis().setex("csrf:"+csrf, 900, "1");
long userId = Toolkit.uid();
re.put("current_user", fetch_userprofile(userId));
re.put("sub_forums", dao.query(SubForum.class, Cnd.NEW().asc("tagname")));
re.put("need_user_active", yvrService.needUserActive(userId, session));
return re;
}

Expand All @@ -126,19 +121,8 @@ public Object add(HttpSession session) {
@Ok("json")
@Filters(@By(type = CsrfActionFilter.class))
@AdaptBy(type=WhaleAdaptor.class)
public CResult add(@Param("..")Topic topic, @Param("_tags")String tags,
HttpServletRequest req,
@Param("challenge")String challenge,
@Param("validate")String validate,
@Param("seccode")String seccode) {
if (Strings.isBlank(challenge) || Strings.isBlank(validate) || Strings.isBlank(seccode)) {
return CResult._fail("未提供校验参数,请刷新页面后重试");
}
public CResult add(@Param("..")Topic topic, @Param("_tags")String tags) {
long userId = Toolkit.uid();
String msg = gtService.verify(challenge, validate, seccode, userId+"", Lang.getIP(req));
if (msg != null) {
return CResult._fail(msg);
}
if (!Strings.isBlank(tags)) {
topic.setTags(new HashSet<>(Lang.list(Strings.splitIgnoreBlank(tags))));
}
Expand Down Expand Up @@ -302,6 +286,7 @@ public Object topic(String id, @ReqHeader("If-None-Match")String _etag, HttpSer
re.put("next_topic_id", redisDao.znext(RKEY_TOPIC_UPDATE+topic.getType(), topic.getId()));
re.put("prev_topic_id", redisDao.zprev(RKEY_TOPIC_UPDATE+topic.getType(), topic.getId()));
re.put("user_topic_marked", topic.getCollectors().contains(""+Toolkit.uid()));
re.put("need_user_active", yvrService.needUserActive(userId, null));
//re.put("top_tags", yvrService.fetchTopTags());
return re;
}
Expand Down Expand Up @@ -329,7 +314,7 @@ public Object image(String p, String p2) throws IOException {
@Filters(@By(type = CsrfActionFilter.class))
@At("/t/?/reply")
@Ok("json")
public Object addReply(String topicId, @Param("..") TopicReply reply) {
public Object addReply(String topicId, @Param("..") TopicReply reply, HttpSession session) {
long userId = Toolkit.uid();
return yvrService.addReply(topicId, reply, userId);
}
Expand Down
Expand Up @@ -16,6 +16,8 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import javax.servlet.http.HttpSession;

import org.apache.commons.lang.StringEscapeUtils;
import org.nutz.aop.interceptor.async.Async;
import org.nutz.dao.Cnd;
Expand All @@ -26,6 +28,7 @@
import org.nutz.integration.jedis.pubsub.PubSub;
import org.nutz.integration.jedis.pubsub.PubSubService;
import org.nutz.ioc.aop.Aop;
import org.nutz.ioc.impl.PropertiesProxy;
import org.nutz.ioc.loader.annotation.Inject;
import org.nutz.ioc.loader.annotation.IocBean;
import org.nutz.json.Json;
Expand Down Expand Up @@ -79,6 +82,9 @@ public class YvrService implements RedisKey, PubSub {

@Inject("java:$conf.get('topic.global.watchers')")
protected String topicGlobalWatchers;

@Inject
PropertiesProxy conf;

protected Set<Long> globalWatcherIds = new HashSet<>();

Expand Down Expand Up @@ -174,6 +180,9 @@ public CResult add(Topic topic, long userId) {
if (0 != dao.count(Topic.class, Cnd.where("title", "=", topic.getTitle().trim()))) {
return _fail("相同标题已经发过了");
}
if (!needUserActive(userId, null)) {
return CResult._fail("用户未激活,请前往打赏页激活");
}
// 检查关键字
Set<String> tags = topic.getTags();
topic.setTags(new HashSet<>());
Expand Down Expand Up @@ -254,6 +263,9 @@ public CResult addReply(final String topicId, final TopicReply reply, final long
if (topic.isLock()) {
return _fail("该帖子已经锁定,不能回复");
}
if (!needUserActive(userId, null)) {
return CResult._fail("用户未激活,请前往打赏页激活");
}
reply.setTopicId(topicId);
reply.setUserId(userId);
reply.setContent(Toolkit.filteContent(reply.getContent()));
Expand Down Expand Up @@ -459,7 +471,7 @@ public boolean updateTags(String topicId, @Param("tags")Set<String> tags) {
Set<String> newTags = new HashSet<>(tags);
newTags.removeAll(oldTags);
Set<String> removeTags = new HashSet<>(oldTags);;
removeTags.remove(tags);
removeTags.removeAll(tags);
fillTopic(topic, null);
Date lastReplyTime = topic.getCreateTime();
if (topic.getLastComment() != null)
Expand Down Expand Up @@ -622,4 +634,24 @@ public NutMap topicDelete(String topicId) {
public void rebuildRedisUpdateList() {

}

public boolean needUserActive(long userId, HttpSession session) {
if (!conf.getBoolean("yvr.pay_before_first_topic", true)) {
return false;
}
User user = dao.fetch(User.class, userId);
if (user == null)
return true;
if (user.isLocked()) {
if (session != null)
session.invalidate();
return true;
}
// 2018-07-06 00:00:00 之后注册的用户,要先打赏才能发帖或评论
if (user.getCreateTime().getTime() < 1530806400000L) {
return false;
}
int sum = dao.func("t_bee_payment", "sum", "transaction_fee", Cnd.where("trade_success", "=", true).and("from_user", "=", userId));
return sum < 38;
}
}
Expand Up @@ -8,7 +8,8 @@ var config_map = {
"yvr.keywords" : "默认关键字",
//"yvr.long_description" : "网站完整描述",
"yvr.tips_of_add" : "发帖提示语",
"yvr.allow_image_upload" : "是否允许上传图片"
"yvr.allow_image_upload" : "是否允许上传图片",
"yvr.pay_before_first_topic" : "是否先打赏才能发帖"
};
var vueBasicConfigList = new Vue({
el : "#yvr_config_div",
Expand Down
10 changes: 8 additions & 2 deletions nutzcn-yvr/src/main/resources/assets/yvr/js/base.js
Expand Up @@ -87,10 +87,16 @@ function startGuide(){

// 支付功能

function pay_tips(toUser) {
function pay_tips(toUser, tips) {
if (!tips) {
tips = '' + Math.round(Math.random()*800 + 500);
}
else {
tips = '' + tips;
}
layer.prompt({
formType: 0,
value: '' + Math.round(Math.random()*800 + 500),
value: tips,
title: '请输入金额,单位是分,按确定后将出现微信二维码'
}, function(value, index, elem){
layer.close(index);
Expand Down
4 changes: 2 additions & 2 deletions nutzcn-yvr/src/main/resources/assets/yvr/js/bc/index.js
Expand Up @@ -41,8 +41,8 @@ var bcListVue = new Vue({
}
});
},
do_pay: function(uid) {
pay_tips(uid);
do_pay: function(uid, tips) {
pay_tips(uid, tips);
},
jump: function(to) {
this.pageNumber = to;
Expand Down

0 comments on commit ea14854

Please sign in to comment.