This commit is contained in:
2018-04-05 21:08:30 +08:00
parent c3f5a5f5be
commit 976c62197a
6 changed files with 69 additions and 14 deletions

View File

@@ -1,6 +1,8 @@
package com.lxyer.bbs.base;
import java.text.SimpleDateFormat;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* Created by Lxy at 2017/11/29 15:17.
@@ -30,4 +32,39 @@ public final class LxyKit {
return new SimpleDateFormat("yyyy-MM-dd").format(time);
}
public static String delHTMLTag(String htmlStr){
String regEx_script="<script[^>]*?>[\\s\\S]*?<\\/script>"; //定义script的正则表达式
String regEx_style="<style[^>]*?>[\\s\\S]*?<\\/style>"; //定义style的正则表达式
String regEx_html="<[^>]+>"; //定义HTML标签的正则表达式
Pattern p_script=Pattern.compile(regEx_script,Pattern.CASE_INSENSITIVE);
Matcher m_script=p_script.matcher(htmlStr);
htmlStr=m_script.replaceAll(""); //过滤script标签
Pattern p_style=Pattern.compile(regEx_style,Pattern.CASE_INSENSITIVE);
Matcher m_style=p_style.matcher(htmlStr);
htmlStr=m_style.replaceAll(""); //过滤style标签
Pattern p_html=Pattern.compile(regEx_html,Pattern.CASE_INSENSITIVE);
Matcher m_html=p_html.matcher(htmlStr);
htmlStr=m_html.replaceAll(""); //过滤html标签
return htmlStr.trim(); //返回文本字符串
}
public static void main(String[] args) {
Pattern p = Pattern.compile("@*&nbsp;");
Matcher matcher = p.matcher("@nick&nbsp;[污]&nbsp;");
int count = 0;
while (matcher.find()) {
count++;
}
}
}

View File

@@ -39,6 +39,12 @@ public abstract class RetCodes {
@RetLabel("邮箱无效")
public static final int RET_USER_EMAIL_ILLEGAL = 3002_0009;
@RetLabel("昵称无效")
public static final int RET_USER_NICKNAME_ILLEGAL = 3002_0010;
@RetLabel("昵称已存在")
public static final int RET_USER_NICKNAME_EXISTS = 3002_0011;
//------------------------------------- 内容模块 -----------------------------------------
//------------------------------------- 评论模块 -----------------------------------------

View File

@@ -1,6 +1,5 @@
package com.lxyer.bbs.base.user;
import com.jfinal.kit.Kv;
import com.lxyer.bbs.base.BaseService;
import com.lxyer.bbs.base.LxyKit;
import com.lxyer.bbs.base.RetCodes;
@@ -16,7 +15,6 @@ import org.redkalex.cache.RedisCacheSource;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Map;
import java.util.Objects;
import java.util.Random;
@@ -62,6 +60,7 @@ public class UserService extends BaseService {
}
@RestMapping(name = "userid")
public int currentUserId(String sessionid){
if (sessionid == null) return 0;
Integer userid = sessions.getAndRefresh(sessionid, sessionExpireSeconds);
return userid == null ? 0 : userid;
}
@@ -125,6 +124,16 @@ public class UserService extends BaseService {
@RestMapping(name = "update", comment = "用户信息修改")
public RetResult userUpdate(@RestSessionid String sessionid, @RestParam(name = "bean") User user, String[] columns){
String nickname = user.getNickname();
if (nickname == null && nickname.isEmpty())
return RetCodes.retResult(RET_USER_NICKNAME_ILLEGAL, "昵称无效");
nickname = nickname.replace(" ", "");
User _user = source.find(User.class, FilterNode.create("nickname", nickname));
if (_user != null && _user.getUserId() != currentUserId(sessionid))
return RetCodes.retResult(RET_USER_NICKNAME_EXISTS, "昵称已存在");
user.setNickname(nickname);//去除昵称中的空格
source.updateColumn(user
,FilterNode.create("userId", currentUserId(sessionid))
,SelectColumn.createIncludes(columns)
@@ -154,11 +163,16 @@ public class UserService extends BaseService {
return infos;
}
@RestMapping(name = "stat", auth = false, comment = "用户数据统计")
/*@RestMapping(name = "stat", auth = false, comment = "用户数据统计")
public Map userStat(){
Number count = source.getNumberResult(User.class, FilterFunc.COUNT, "userId", FilterNode.create("status", FilterExpress.NOTEQUAL, -1));
return Kv.by("count", count);
}*/
@RestMapping(name = "usercount", auth = false, comment = "用户数据统计")
public Number userCount() {
return source.getNumberResult(User.class, FilterFunc.COUNT, "userId", FilterNode.create("status", FilterExpress.NOTEQUAL, -1));
}
}

View File

@@ -64,7 +64,10 @@ public class IndexServlet extends BaseServlet {
//最新加入
Sheet<UserInfo> lastReg = userService.lastReg();
Kv kv = Kv.by("top", top).set("contents", contents).set("hotReply", hotReply).set("lastReg", lastReg);
//用户统计
Number userCount = userService.userCount();
Kv kv = Kv.by("top", top).set("contents", contents).set("hotReply", hotReply).set("lastReg", lastReg).set("userCount", userCount);
finish("index.html", kv);
}