| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -107,4 +107,9 @@ public Integer getUid() { | |||
| 107 | 107 | return null != user ? user.getUid() : null; | |
| 108 | 108 | } | |
| 109 | 109 | ||
| 110 | + public String getUsername() { | ||
| 111 | + LoginUser user = getLoginUser(); | ||
| 112 | + return null != user ? user.getUsername() : null; | ||
| 113 | + } | ||
| 114 | + | ||
| 110 | 115 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -64,29 +64,44 @@ public class MemberController extends BaseController { | |||
| 64 | 64 | @Inject | |
| 65 | 65 | private FavoriteService favoriteService; | |
| 66 | 66 | ||
| 67 | + @Inject | ||
| 68 | + private RemindService remindService; | ||
| 69 | + | ||
| 67 | 70 | private Patchca patchca = new DefaultPatchca(); | |
| 68 | 71 | ||
| 69 | 72 | /** | |
| 70 | 73 | * 通知列表 | |
| 71 | 74 | */ | |
| 72 | - @Route(value = "/notices", method = HttpMethod.GET) | ||
| 73 | - public ModelAndView notices(Request request, Response response, | ||
| 75 | + @Route(value = "/reminds", method = HttpMethod.GET) | ||
| 76 | + @Access | ||
| 77 | + public ModelAndView reminds(Request request, | ||
| 74 | 78 | @QueryParam(defaultValue = "1", value = "page") Integer page, | |
| 75 | 79 | @QueryParam(defaultValue = "15", value = "limit") Integer limit) { | |
| 76 | 80 | ||
| 77 | - LoginUser user = SessionKit.getLoginUser(); | ||
| 78 | - if (null == user) { | ||
| 79 | - response.go("/signin"); | ||
| 80 | - return null; | ||
| 81 | - } | ||
| 81 | + Paginator<Remind> remindPaginator = remindService.getReminds(getUsername(), page, limit); | ||
| 82 | + request.attribute("remindPage", remindPaginator); | ||
| 83 | + | ||
| 84 | + return this.getView("reminds"); | ||
| 85 | + } | ||
| 82 | 86 | ||
| 83 | - return this.getView("notices"); | ||
| 87 | + /** | ||
| 88 | + * 清除我的未读 | ||
| 89 | + * | ||
| 90 | + * @return | ||
| 91 | + */ | ||
| 92 | + @Route(value = "/reminds/clean", method = HttpMethod.POST) | ||
| 93 | + @JSON | ||
| 94 | + @Access | ||
| 95 | + public RestResponse cleanReminds() { | ||
| 96 | + remindService.readReminds(getUsername()); | ||
| 97 | + return RestResponse.ok(); | ||
| 84 | 98 | } | |
| 85 | 99 | ||
| 86 | 100 | /** | |
| 87 | 101 | * 修改新密码 | |
| 88 | 102 | */ | |
| 89 | 103 | @Route(value = "/reset_pwd", method = HttpMethod.POST) | |
| 104 | + @Access | ||
| 90 | 105 | public ModelAndView reset_pwd(Request request, @QueryParam String code, | |
| 91 | 106 | @QueryParam String password, | |
| 92 | 107 | @QueryParam String re_password) { | |
@@ -156,7 +171,7 @@ public ModelAndView member(@PathParam("username") String username, | |||
| 156 | 171 | Request request, Response response) { | |
| 157 | 172 | ||
| 158 | 173 | Take up = new Take(User.class); | |
| 159 | - up.eq("status", 1).eq("login_name", username); | ||
| 174 | + up.eq("status", 1).eq("username", username); | ||
| 160 | 175 | ||
| 161 | 176 | User user = userService.getUserByTake(up); | |
| 162 | 177 | if (null == user) { | |
@@ -180,14 +195,14 @@ public ModelAndView member(@PathParam("username") String username, | |||
| 180 | 195 | ||
| 181 | 196 | // 最新创建的主题 | |
| 182 | 197 | Take tp = new Take(Topic.class); | |
| 183 | - tp.eq("status", 1).eq("uid", user.getUid()).orderby("created desc, updated desc").page(1, 10); | ||
| 198 | + tp.eq("status", 1).eq("username", user.getUsername()).orderby("created desc, updated desc").page(1, 10); | ||
| 184 | 199 | Paginator<Map<String, Object>> topicPage = topicService.getPageList(tp); | |
| 185 | 200 | request.attribute("topicPage", topicPage); | |
| 186 | 201 | ||
| 187 | 202 | // 最新发布的回复 | |
| 188 | 203 | Take cp = new Take(Comment.class); | |
| 189 | - cp.eq("uid", user.getUid()).orderby("created desc").page(1, 10); | ||
| 190 | - Paginator<Map<String, Object>> commentPage = null;//commentService.getPageListMap(cp); | ||
| 204 | + cp.eq("author", user.getUsername()).orderby("created desc").page(1, 10); | ||
| 205 | + Paginator<Map<String, Object>> commentPage = commentService.getPages(cp); | ||
| 191 | 206 | request.attribute("commentPage", commentPage); | |
| 192 | 207 | ||
| 193 | 208 | return this.getView("member_detail"); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -86,7 +86,7 @@ public ModelAndView githubCall(Request request, Response response) { | |||
| 86 | 86 | Openid openid = openIdService.getOpenid(EventType.GITHUB, open_id); | |
| 87 | 87 | if (null == openid) { | |
| 88 | 88 | Map<String, String> githubInfo = new HashMap<String, String>(3); | |
| 89 | - githubInfo.put("login_name", login); | ||
| 89 | + githubInfo.put("username", login); | ||
| 90 | 90 | githubInfo.put("open_id", open_id.toString()); | |
| 91 | 91 | ||
| 92 | 92 | SessionKit.set(request.session(), EventType.GITHUB, githubInfo); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -79,7 +79,7 @@ public ModelAndView show_ediot_topic(@PathParam("tid") String tid, Request reque | |||
| 79 | 79 | return this.getView("info"); | |
| 80 | 80 | } | |
| 81 | 81 | ||
| 82 | - if (!topic.getUid().equals(getUid())) { | ||
| 82 | + if (!topic.getUsername().equals(getLoginUser().getUsername())) { | ||
| 83 | 83 | request.attribute(this.ERROR, "您无权限编辑该帖"); | |
| 84 | 84 | return this.getView("info"); | |
| 85 | 85 | } | |
@@ -119,7 +119,7 @@ public RestResponse edit_topic(Request request, Response response) { | |||
| 119 | 119 | } | |
| 120 | 120 | ||
| 121 | 121 | // 无权限操作 | |
| 122 | - if (!topic.getUid().equals(getUid())) { | ||
| 122 | + if (!topic.getUsername().equals(getLoginUser().getUsername())) { | ||
| 123 | 123 | return RestResponse.fail("无权限操作该帖"); | |
| 124 | 124 | } | |
| 125 | 125 | ||
@@ -144,7 +144,7 @@ public RestResponse edit_topic(Request request, Response response) { | |||
| 144 | 144 | return RestResponse.fail("内容太长了,试试少吐点口水"); | |
| 145 | 145 | } | |
| 146 | 146 | ||
| 147 | - Integer last_time = topicService.getLastUpdateTime(getUid()); | ||
| 147 | + Integer last_time = topicService.getLastUpdateTime(getUsername()); | ||
| 148 | 148 | if (null != last_time && (DateKit.getCurrentUnixTime() - last_time) < 10) { | |
| 149 | 149 | return RestResponse.fail("您操作频率太快,过一会儿操作吧!"); | |
| 150 | 150 | } | |
@@ -192,7 +192,7 @@ public RestResponse publish(@QueryParam String title, | |||
| 192 | 192 | ||
| 193 | 193 | Integer uid = getUid(); | |
| 194 | 194 | ||
| 195 | - Integer last_time = topicService.getLastCreateTime(uid); | ||
| 195 | + Integer last_time = topicService.getLastCreateTime(getUsername()); | ||
| 196 | 196 | if (null != last_time && (DateKit.getCurrentUnixTime() - last_time) < 10) { | |
| 197 | 197 | return RestResponse.fail("您操作频率太快,过一会儿操作吧!"); | |
| 198 | 198 | } | |
@@ -203,7 +203,7 @@ public RestResponse publish(@QueryParam String title, | |||
| 203 | 203 | // 发布帖子 | |
| 204 | 204 | try { | |
| 205 | 205 | Topic topic = new Topic(); | |
| 206 | - topic.setUid(uid); | ||
| 206 | + topic.setUsername(getLoginUser().getUsername()); | ||
| 207 | 207 | topic.setNid(nid); | |
| 208 | 208 | topic.setTitle(title); | |
| 209 | 209 | topic.setContent(content); | |
@@ -262,8 +262,8 @@ private void putDetail(Request request, Integer uid, Topic topic) { | |||
| 262 | 262 | request.attribute("is_love", is_love); | |
| 263 | 263 | ||
| 264 | 264 | Take cp = new Take(Comment.class); | |
| 265 | - cp.and("tid", topic.getTid()).asc("cid").page(page, 20); | ||
| 266 | - Paginator<Map<String, Object>> commentPage = null;//commentService.getPageListMap(cp); | ||
| 265 | + cp.eq("tid", topic.getTid()).asc("cid").page(page, 20); | ||
| 266 | + Paginator<Map<String, Object>> commentPage = commentService.getPages(cp); | ||
| 267 | 267 | request.attribute("commentPage", commentPage); | |
| 268 | 268 | } | |
| 269 | 269 | ||
@@ -294,9 +294,12 @@ public RestResponse comment(Request request, Response response, | |||
| 294 | 294 | ||
| 295 | 295 | Integer uid = getUid(); | |
| 296 | 296 | ||
| 297 | - Comment comment = Comment.builder().author_id(uid).author(getLoginUser().getUsername()) | ||
| 298 | - .owner_id(topic.getUid()) | ||
| 299 | - .content(content).agent(request.userAgent()).build(); | ||
| 297 | + Comment comment = Comment.builder() | ||
| 298 | + .tid(tid) | ||
| 299 | + .author(getLoginUser().getUsername()) | ||
| 300 | + .owner(topic.getUsername()) | ||
| 301 | + .content(content) | ||
| 302 | + .agent(request.userAgent()).ip(request.address()).build(); | ||
| 300 | 303 | ||
| 301 | 304 | topicService.comment(comment, topic.getTitle()); | |
| 302 | 305 | Constant.SYS_INFO = optionsService.getSystemInfo(); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,10 +1,20 @@ | |||
| 1 | 1 | package com.javachina.ext; | |
| 2 | 2 | ||
| 3 | + import com.blade.jdbc.ActiveRecord; | ||
| 3 | 4 | import com.blade.kit.DateKit; | |
| 4 | 5 | import com.blade.kit.StringKit; | |
| 5 | 6 | import com.javachina.constants.Constant; | |
| 7 | + import com.javachina.dto.LoginUser; | ||
| 8 | + import com.javachina.kit.SessionKit; | ||
| 9 | + import com.javachina.model.Remind; | ||
| 6 | 10 | ||
| 7 | - public class Funcs { | ||
| 11 | + public class TplFunctions { | ||
| 12 | + | ||
| 13 | + private static ActiveRecord activeRecord; | ||
| 14 | + | ||
| 15 | + public static void setActiveRecord(ActiveRecord ar) { | ||
| 16 | + activeRecord = ar; | ||
| 17 | + } | ||
| 8 | 18 | ||
| 9 | 19 | /** | |
| 10 | 20 | * 获取相对路径 | |
@@ -122,4 +132,16 @@ public static String timespan(Integer ctime) { | |||
| 122 | 132 | return r; | |
| 123 | 133 | } | |
| 124 | 134 | ||
| 135 | + /** | ||
| 136 | + * 读取我的未读 | ||
| 137 | + * | ||
| 138 | + * @return | ||
| 139 | + */ | ||
| 140 | + public static int unreads() { | ||
| 141 | + LoginUser loginUser = SessionKit.getLoginUser(); | ||
| 142 | + if (null != loginUser) { | ||
| 143 | + return activeRecord.count(Remind.builder().to_user(loginUser.getUsername()).is_read(false).build()); | ||
| 144 | + } | ||
| 145 | + return 0; | ||
| 146 | + } | ||
| 125 | 147 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -11,12 +11,10 @@ | |||
| 11 | 11 | import com.blade.mvc.view.ViewSettings; | |
| 12 | 12 | import com.blade.mvc.view.template.JetbrickTemplateEngine; | |
| 13 | 13 | import com.javachina.constants.Constant; | |
| 14 | - import com.javachina.ext.Funcs; | ||
| 14 | + import com.javachina.ext.TplFunctions; | ||
| 15 | 15 | import jetbrick.template.JetGlobalContext; | |
| 16 | 16 | import jetbrick.template.resolver.GlobalResolver; | |
| 17 | 17 | import lombok.extern.slf4j.Slf4j; | |
| 18 | - import org.slf4j.Logger; | ||
| 19 | - import org.slf4j.LoggerFactory; | ||
| 20 | 18 | ||
| 21 | 19 | import javax.servlet.ServletContext; | |
| 22 | 20 | import javax.sql.DataSource; | |
@@ -34,7 +32,7 @@ public void init(BConfig bConfig, ServletContext sec) { | |||
| 34 | 32 | JetbrickTemplateEngine templateEngine = new JetbrickTemplateEngine(); | |
| 35 | 33 | JetGlobalContext context = templateEngine.getGlobalContext(); | |
| 36 | 34 | GlobalResolver resolver = templateEngine.getGlobalResolver(); | |
| 37 | - resolver.registerFunctions(Funcs.class); | ||
| 35 | + resolver.registerFunctions(TplFunctions.class); | ||
| 38 | 36 | ||
| 39 | 37 | Config config = bConfig.config(); | |
| 40 | 38 | String version = config.get("app.version", "1.0"); | |
@@ -77,6 +75,7 @@ public void register(Ioc ioc) { | |||
| 77 | 75 | DataSource dataSource = DruidDataSourceFactory.createDataSource(props); | |
| 78 | 76 | ActiveRecord activeRecord = new SampleActiveRecord(dataSource); | |
| 79 | 77 | ioc.addBean(activeRecord); | |
| 78 | + TplFunctions.setActiveRecord(activeRecord); | ||
| 80 | 79 | } catch (Exception ex) { | |
| 81 | 80 | log.error("初始化数据库配置失败", ex); | |
| 82 | 81 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -13,14 +13,14 @@ public class MailKit { | |||
| 13 | 13 | ||
| 14 | 14 | private static ExecutorService executorService = Executors.newFixedThreadPool(3); | |
| 15 | 15 | ||
| 16 | - public static void sendForgot(String login_name, String email, String code) { | ||
| 16 | + public static void sendForgot(String username, String email, String code) { | ||
| 17 | 17 | ||
| 18 | 18 | } | |
| 19 | 19 | ||
| 20 | - public static void sendSignup(String login_name, String to_addr, String code) { | ||
| 20 | + public static void sendSignup(String username, String to_addr, String code) { | ||
| 21 | 21 | String url = Constant.SITE_URL + "/active/" + code; | |
| 22 | 22 | String content = "您的激活链接是:<a href='" + url + "'>" + url + "</a> 点击链接激活账号!"; | |
| 23 | - send(login_name + ", 欢迎你加入" + Constant.MAIL_USERNAME, to_addr, content); | ||
| 23 | + send(username + ", 欢迎你加入" + Constant.MAIL_USERNAME, to_addr, content); | ||
| 24 | 24 | } | |
| 25 | 25 | ||
| 26 | 26 | public static void send(final String subject, final String to_addr, final String content) { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -7,7 +7,7 @@ | |||
| 7 | 7 | import com.blade.mvc.http.Request; | |
| 8 | 8 | import com.javachina.constants.Constant; | |
| 9 | 9 | import com.javachina.ext.Commons; | |
| 10 | - import com.javachina.ext.Funcs; | ||
| 10 | + import com.javachina.ext.TplFunctions; | ||
| 11 | 11 | import org.commonmark.Extension; | |
| 12 | 12 | import org.commonmark.ext.gfm.tables.TablesExtension; | |
| 13 | 13 | import org.commonmark.node.Node; | |
@@ -154,7 +154,7 @@ public static String markdown2html(String markdown) { | |||
| 154 | 154 | HtmlRenderer renderer = HtmlRenderer.builder().extensions(extensions).build(); | |
| 155 | 155 | String content = renderer.render(document); | |
| 156 | 156 | ||
| 157 | - String member = Funcs.base_url("/member/"); | ||
| 157 | + String member = TplFunctions.base_url("/member/"); | ||
| 158 | 158 | content = content.replaceAll("@([a-zA-Z_0-9-]+)\\s", "<a href='" + member + "$1'>@$1</a> "); | |
| 159 | 159 | ||
| 160 | 160 | content = Commons.emoji(content); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,6 +1,7 @@ | |||
| 1 | 1 | package com.javachina.model; | |
| 2 | 2 | ||
| 3 | 3 | import com.blade.jdbc.annotation.Table; | |
| 4 | + import lombok.AllArgsConstructor; | ||
| 4 | 5 | import lombok.Builder; | |
| 5 | 6 | import lombok.Data; | |
| 6 | 7 | import lombok.NoArgsConstructor; | |
@@ -14,13 +15,13 @@ | |||
| 14 | 15 | @Data | |
| 15 | 16 | @Builder | |
| 16 | 17 | @NoArgsConstructor | |
| 18 | + @AllArgsConstructor | ||
| 17 | 19 | public class Comment implements Serializable { | |
| 18 | 20 | ||
| 19 | 21 | private Integer cid; | |
| 20 | - private Integer author_id; | ||
| 21 | - private Integer owner_id; | ||
| 22 | 22 | private String tid; | |
| 23 | 23 | private String author; | |
| 24 | + private String owner; | ||
| 24 | 25 | private String content; | |
| 25 | 26 | private String ip; | |
| 26 | 27 | private String agent; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,6 +1,7 @@ | |||
| 1 | 1 | package com.javachina.model; | |
| 2 | 2 | ||
| 3 | 3 | import com.blade.jdbc.annotation.Table; | |
| 4 | + import com.blade.kit.StringKit; | ||
| 4 | 5 | import lombok.AllArgsConstructor; | |
| 5 | 6 | import lombok.Builder; | |
| 6 | 7 | import lombok.Data; | |
@@ -20,7 +21,7 @@ public class Remind implements Serializable { | |||
| 20 | 21 | ||
| 21 | 22 | private Integer id; | |
| 22 | 23 | private String from_user; | |
| 23 | - private Integer to_uid; | ||
| 24 | + private String to_user; | ||
| 24 | 25 | private String event_id; | |
| 25 | 26 | private String title; | |
| 26 | 27 | private String content; | |
| Back | FazBrowse Home | New Git URL |
0 commit comments