新增用户注册/登录
This commit is contained in:
@@ -1,9 +0,0 @@
|
||||
package com.lxyer.controller;
|
||||
|
||||
/**
|
||||
* Created by JUECHENG at 2018/1/7 16:48.
|
||||
*/
|
||||
public class ContentController extends IController{
|
||||
|
||||
|
||||
}
|
@@ -58,25 +58,5 @@ public class HomeController extends IController {
|
||||
render("jie/index.html");
|
||||
}
|
||||
|
||||
/**
|
||||
* 帖子详情
|
||||
*/
|
||||
public void jie(){
|
||||
int contentId = getParaToInt(0);
|
||||
|
||||
//ContentInfo content = contentService.contentInfo(sessionid, contentid);
|
||||
//Sheet<CommentInfo> comments = commentService.commentQuery(request.getSessionid(false) ,contentid, new Flipper().limit(30));
|
||||
|
||||
Record content = Content.dao.findFirst(Kv.by("contentId", contentId));
|
||||
|
||||
//热议
|
||||
List<Content> hotReply = Content.dao.findPage(1, 8, Kv.by("order", "replyNum DESC")).getList();
|
||||
|
||||
setAttr("bean", content);
|
||||
setAttr("hotReply", hotReply);
|
||||
|
||||
render("jie/detail.html");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@@ -6,6 +6,7 @@ import com.jfinal.plugin.activerecord.*;
|
||||
import com.jfinal.plugin.redis.Cache;
|
||||
import com.jfinal.plugin.redis.Redis;
|
||||
import com.lxyer.config.E;
|
||||
import com.lxyer.model.User;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
@@ -19,6 +20,22 @@ public class IController extends Controller {
|
||||
|
||||
public static final Cache cache = Redis.use();
|
||||
|
||||
public void index(){
|
||||
String para = getPara(0, "index");
|
||||
|
||||
render(para + ".html");
|
||||
}
|
||||
|
||||
|
||||
public Integer getUserId() {
|
||||
User user = getUser();
|
||||
return user == null ? null : user.getUserId();
|
||||
}
|
||||
|
||||
public User getUser(){
|
||||
return getSessionAttr("user");
|
||||
}
|
||||
|
||||
public Kv getParams(String... key) {
|
||||
Kv kv = Kv.create();
|
||||
for (String k : key) {
|
||||
|
62
src/main/java/com/lxyer/controller/JieController.java
Normal file
62
src/main/java/com/lxyer/controller/JieController.java
Normal file
@@ -0,0 +1,62 @@
|
||||
package com.lxyer.controller;
|
||||
|
||||
import com.jfinal.aop.Before;
|
||||
import com.jfinal.kit.Kv;
|
||||
import com.lxyer.config.JsonBean;
|
||||
import com.lxyer.config.interceptor.LoginInterceptor;
|
||||
import com.lxyer.model.Content;
|
||||
import com.lxyer.service.ContentService;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by JUECHENG at 2018/1/7 16:48.
|
||||
*/
|
||||
public class JieController extends IController{
|
||||
|
||||
private ContentService contentService = ContentService.me;
|
||||
private int userId;
|
||||
|
||||
/**
|
||||
* 帖子详情
|
||||
*/
|
||||
public void index(){
|
||||
int contentId = getParaToInt(0);
|
||||
|
||||
//ContentInfo content = contentService.contentInfo(sessionid, contentid);
|
||||
//Sheet<CommentInfo> comments = commentService.commentQuery(request.getSessionid(false) ,contentid, new Flipper().limit(30));
|
||||
|
||||
Content content = Content.dao.findFirst(Kv.by("contentId", contentId));
|
||||
|
||||
//热议
|
||||
List<Content> hotReply = Content.dao.findPage(1, 8, Kv.by("order", "replyNum DESC")).getList();
|
||||
|
||||
setAttr("bean", content);
|
||||
setAttr("hotReply", hotReply);
|
||||
|
||||
render("detail.html");
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加/修改帖子
|
||||
*/
|
||||
@Before(LoginInterceptor.class)
|
||||
public void add(){
|
||||
setAttr("bean", Content.dao.findById(getParaToInt()));
|
||||
|
||||
render("add.html");
|
||||
}
|
||||
|
||||
/**
|
||||
* 帖子保存
|
||||
*/
|
||||
@Before(LoginInterceptor.class)
|
||||
public void save() {
|
||||
Content content = getModel(Content.class);
|
||||
|
||||
contentService.save(content, getUserId());
|
||||
|
||||
renderJson(JsonBean.success());
|
||||
}
|
||||
|
||||
}
|
@@ -1,28 +1,88 @@
|
||||
package com.lxyer.controller;
|
||||
|
||||
import com.lxyer.config.JsonBean;
|
||||
import com.lxyer.model.User;
|
||||
import com.lxyer.service.UserService;
|
||||
|
||||
/**
|
||||
* Created by JUECHENG at 2018/1/7 16:40.
|
||||
*/
|
||||
public class UserController extends IController {
|
||||
|
||||
private UserService userService = UserService.me;
|
||||
|
||||
/**
|
||||
* 注册
|
||||
*/
|
||||
public void create(){
|
||||
JsonBean bean = new JsonBean(1);
|
||||
String email = getPara("email");
|
||||
String pwd = getPara("pwd");
|
||||
String nickname = getPara("nickname");
|
||||
|
||||
try {
|
||||
userService.create(email, pwd, nickname);
|
||||
} catch (Exception e) {
|
||||
bean.setCode(-1, e.getMessage());
|
||||
}
|
||||
|
||||
renderJson(bean);
|
||||
}
|
||||
|
||||
/**
|
||||
* 登录
|
||||
*/
|
||||
public void login(){
|
||||
String para = getPara();
|
||||
if (para == null) {
|
||||
render("login.html");
|
||||
return;
|
||||
}else if ("out".equals(para)){
|
||||
removeSessionAttr("user");
|
||||
renderJson(JsonBean.success());
|
||||
return;
|
||||
}
|
||||
JsonBean bean = new JsonBean(1);
|
||||
String username = getPara("username");
|
||||
String pwd = getPara("pwd");
|
||||
|
||||
try {
|
||||
User user = userService.login(username, pwd);
|
||||
/*未来源app端
|
||||
String token = userService.updateToken(user);
|
||||
bean.set("user", user);
|
||||
bean.set("token", token);*/
|
||||
|
||||
setSessionAttr("user", user);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
bean.setCode(-1, e.getMessage());
|
||||
}
|
||||
|
||||
renderJson(bean);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改
|
||||
* todo:用户修改资料
|
||||
*/
|
||||
public void update(){
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改密码
|
||||
*/
|
||||
public void repwd(){
|
||||
JsonBean bean = new JsonBean(1);
|
||||
String pwd = getPara("pwd");
|
||||
|
||||
try {
|
||||
userService.updatePwd(getUserId(), pwd);
|
||||
} catch (Exception e) {
|
||||
bean.setCode(-1, e.getMessage());
|
||||
}
|
||||
|
||||
renderJson(bean);
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user