use of com.hfut.entity.User in project Workload by amoxu.
the class FindPsw method getQuestion.
@RequestMapping(value = "/password/getQuestion", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE + ";charset=utf-8")
@ResponseBody
public String getQuestion(User user) throws Exception {
Subject currentUser = SecurityUtils.getSubject();
Session session = currentUser.getSession();
if (session.getAttribute("rand") == null || !session.getAttribute("rand").toString().equalsIgnoreCase(user.getMail())) {
return "{\"status\":1,\"msg\":\"请重新输入验证码!\"}";
}
User nUser = userService.findByName(user.getUser());
if (nUser != null) {
return "{\"status\":0,\"msg\":\"" + nUser.getQuestion() + "\"}";
} else {
return "{\"status\":1,\"msg\":\"请检查用户名!\"}";
}
}
use of com.hfut.entity.User in project Workload by amoxu.
the class FindPsw method resetPsw.
@RequestMapping(value = "/password/resetPsw", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE + ";charset=utf-8")
@ResponseBody
public String resetPsw(User user) throws Exception {
Subject currentUser = SecurityUtils.getSubject();
Session session = currentUser.getSession();
if (session.getAttribute("rand") == null || !session.getAttribute("rand").toString().equalsIgnoreCase(user.getMail())) {
return "{\"status\":1,\"msg\":\"请重新输入验证码!\"}";
}
String retErr = "{\"status\":1,\"msg\":\"请检查用户名!\"}";
User nUser = userService.findByName(user.getUser());
if (nUser != null) {
if (nUser.getQuestion() != user.getQuestion()) {
return retErr;
}
return "{\"status\":0,\"msg\":\"" + nUser.getQuestion() + "\"}";
} else {
return retErr;
}
}
use of com.hfut.entity.User in project Workload by amoxu.
the class RoleController method searchUser.
@RequestMapping(value = "/user/search", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE + ";charset=utf-8")
@ResponseBody
public String searchUser(@RequestParam(name = "s") String s, @RequestParam(name = "page") Integer page, @RequestParam(name = "limit") Integer limit) throws Exception {
AjaxResult result = new AjaxResult();
List<User> list = userService.selectLike(s, page, limit);
result.setData(list);
result.setCount(userService.countLike(s));
result.ok();
return result.toString();
}
use of com.hfut.entity.User in project Workload by amoxu.
the class UserController method password.
@RequestMapping(value = "/user/password", produces = MediaType.APPLICATION_JSON_VALUE + ";charset=utf-8", method = { RequestMethod.POST })
@ResponseBody
public // 修改密码
String password(@RequestParam(name = "name") String name, @RequestParam(name = "oldPsw") String old, @RequestParam(name = "newPsw") String newpsw) throws Exception {
Subject currentUser = SecurityUtils.getSubject();
old = ToolKit.psw2pwd(old);
newpsw = ToolKit.psw2pwd(newpsw);
AjaxResult result = new AjaxResult();
String username = currentUser.getPrincipal().toString();
User user = userService.findByName(username);
if (null == user || !username.equals(name)) {
result.failed();
result.setMsg("修改用户名与当前用户名不匹配。");
return JSON.toJSONString(result);
} else if (!user.getPassword().equals(old)) {
result.failed();
result.setMsg("旧密码不正确。");
return JSON.toJSONString(result);
}
try {
user.setPassword(newpsw);
System.out.println(user);
userService.alterPassword(user);
result.ok();
result.setMsg("修改成功,重新登录。");
return JSON.toJSONString(result);
} catch (Exception e) {
throw new CustomException("请检查数据是否正确");
}
}
use of com.hfut.entity.User in project Workload by amoxu.
the class loginRealm method doGetAuthorizationInfo.
/**
* 获取身份信息,我们可以在这个方法中,从数据库获取该用户的权限和角色信息
* 当调用权限验证时,就会调用此方法
*/
protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principalCollection) {
String teacherName = (String) getAvailablePrincipal(principalCollection);
com.hfut.entity.UserRole role = null;
try {
User userlogin = userService.findByName(teacherName);
// 获取角色对象
role = userRoleService.findByid(userlogin.getLevel());
} catch (Exception e) {
try {
throw new CustomException("用户不存在或密码错误");
} catch (CustomException e1) {
e1.printStackTrace();
}
}
// 通过用户名从数据库获取权限/角色信息
SimpleAuthorizationInfo info = new SimpleAuthorizationInfo();
Set<String> r = new HashSet<String>();
if (role != null) {
r.add(role.getName());
info.setRoles(r);
}
return info;
}
Aggregations