|
|
@@ -1,10 +1,12 @@
|
|
|
package xyz.luxnk.lproject.module;
|
|
|
|
|
|
+import org.apache.shiro.SecurityUtils;
|
|
|
import org.nutz.aop.interceptor.ioc.TransAop;
|
|
|
import org.nutz.dao.Cnd;
|
|
|
import org.nutz.dao.Dao;
|
|
|
import org.nutz.dao.QueryResult;
|
|
|
import org.nutz.dao.pager.Pager;
|
|
|
+import org.nutz.integration.shiro.SimpleShiroToken;
|
|
|
import org.nutz.ioc.aop.Aop;
|
|
|
import org.nutz.ioc.loader.annotation.Inject;
|
|
|
import org.nutz.ioc.loader.annotation.IocBean;
|
|
|
@@ -15,6 +17,7 @@ import org.nutz.mvc.annotation.*;
|
|
|
import org.nutz.mvc.filter.CheckSession;
|
|
|
import xyz.luxnk.lproject.bean.UserInfo;
|
|
|
import xyz.luxnk.lproject.bean.UserProfile;
|
|
|
+import xyz.luxnk.lproject.service.UserService;
|
|
|
import xyz.luxnk.lproject.util.Toolkit;
|
|
|
|
|
|
import javax.servlet.http.HttpSession;
|
|
|
@@ -27,6 +30,9 @@ import java.util.Date;
|
|
|
@Filters(@By(type = CheckSession.class, args = {"me", "/"})) // 检查当前Session是否带me这个属性
|
|
|
public class UserModule extends BaseModule {
|
|
|
|
|
|
+ @Inject
|
|
|
+ protected UserService userService;
|
|
|
+
|
|
|
@At("/")
|
|
|
@Ok("jsp:jsp.user.list") // 真实路径是 /WEB-INF/jsp/user/list.jsp
|
|
|
public void index() {}
|
|
|
@@ -54,11 +60,13 @@ public class UserModule extends BaseModule {
|
|
|
if (!Toolkit.checkCaptcha(_captcha, captcha)) {
|
|
|
return re.setv("ok", false).setv("msg", "验证码错误");
|
|
|
}
|
|
|
- UserInfo userInfo = dao.fetch(UserInfo.class, Cnd.where("username", "=", username).and("password", "=", password));
|
|
|
- if (userInfo == null) {
|
|
|
+ String userId = userService.fetch(username, password);
|
|
|
+ //UserInfo userInfo = dao.fetch(UserInfo.class, Cnd.where("username", "=", username).and("password", "=", password));
|
|
|
+ if (userId.equals("")) {
|
|
|
return re.setv("ok", false).setv("msg", "用户名或密码错误");
|
|
|
} else {
|
|
|
- session.setAttribute("me", userInfo.getId());
|
|
|
+ session.setAttribute("me", userId);
|
|
|
+ //SecurityUtils.getSubject().login(new SimpleShiroToken(userId));
|
|
|
return re.setv("ok", true);
|
|
|
}
|
|
|
}
|
|
|
@@ -123,29 +131,24 @@ public class UserModule extends BaseModule {
|
|
|
if (msg != null) {
|
|
|
return re.setv("ok", false).setv("msg", msg);
|
|
|
}
|
|
|
- userInfo.setCreateTime(new Date());
|
|
|
- userInfo.setUpdateTime(new Date());
|
|
|
- userInfo = dao.insert(userInfo);
|
|
|
+ userInfo = userService.add(userInfo.getUsername(), userInfo.getPassword());
|
|
|
return re.setv("ok", true).setv("data", userInfo);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 更新用户
|
|
|
- * @param userInfo
|
|
|
+ * 更新用户密码
|
|
|
+ * @param password
|
|
|
+ * @param me
|
|
|
* @return
|
|
|
*/
|
|
|
@At
|
|
|
- public Object update(@Param("..")UserInfo userInfo) {
|
|
|
- NutMap re = new NutMap();
|
|
|
- String msg = checkUser(userInfo, false);
|
|
|
- if (msg != null) {
|
|
|
- return re.setv("ok", false).setv("msg", msg);
|
|
|
- }
|
|
|
- userInfo.setUsername(null); // 不允许更新用户名
|
|
|
- userInfo.setCreateTime(null); // 不允许更新创建时间
|
|
|
- userInfo.setUpdateTime(new Date()); // 设置正确的更新时间
|
|
|
- dao.updateIgnoreNull(userInfo); // 真正更新的其实只有password和salt
|
|
|
- return re.setv("ok", true);
|
|
|
+ public Object update(@Param("password")String password, @Attr("me")String me) {
|
|
|
+ NutMap re = new NutMap();
|
|
|
+ if (Strings.isBlank(password) || password.length() < 6) {
|
|
|
+ return re.setv("ok", false).setv("msg", "密码不符合要求");
|
|
|
+ }
|
|
|
+ userService.updatePassword(me, password);
|
|
|
+ return re.setv("ok", true);
|
|
|
}
|
|
|
|
|
|
/**
|