use of com.luoxiao.model.User in project ssm_shiro_blog by Mandelo.
the class MainController method updateRoles.
/**
* 修改角色roles,并保存
*
* @param userId
* @return
*/
@ResponseBody
@RequestMapping(value = "/updateRoles", method = RequestMethod.GET)
public UserRoleTemp updateRoles(@RequestParam(value = "userId") Integer userId, @RequestParam(value = "roleStr") String roleStr) {
UserRoleTemp u = new UserRoleTemp();
/* System.out.println(roleStr); */
// 根据用户userId删除所有RoleId
userRoleService.deleteById(userId);
// 遍历角色名
String[] roleNames = roleStr.split(",");
for (int i = 0; i < roleNames.length; i++) {
Integer roleId = (roleService.getIdByRoleName(roleNames[i]));
// 插入新的数据到UserRole表
UserRole userRole = new UserRole();
userRole.setUserId(userId);
userRole.setRoleId(roleId);
userRoleService.insert(userRole);
}
// 重新获取结果
User user = userService.selectById(userId);
List<String> roles = userExtendService.getRoles(user.getUsername());
u.setId(userId);
u.setRoles(roles);
u.setUsername(user.getUsername());
return u;
}
use of com.luoxiao.model.User in project ssm_shiro_blog by Mandelo.
the class MainController method submitBlog.
// 提交博客
@RequestMapping(value = "/user/submitBlog", method = RequestMethod.POST)
public ModelAndView submitBlog(Blog blog, HttpSession session) {
ModelAndView mv = new ModelAndView();
try {
blog.setCreateTime(new Date());
User loginUser = (User) session.getAttribute("loginUser");
blog.setUserId(loginUser.getId());
blog.setAuthor(loginUser.getUsername());
blogService.insert(blog);
mv.setViewName("success/blogSubmitSuccess");
} catch (Exception e) {
mv.setViewName("error/errorPage");
e.printStackTrace();
}
return mv;
}
use of com.luoxiao.model.User in project ssm_shiro_blog by Mandelo.
the class MainController method roleManage.
/**
* 用户角色管理
*
* @param userId
* @return
*/
@ResponseBody
@RequestMapping(value = "/getRoles")
public UserRoleTemp roleManage(@RequestParam(value = "userId") Integer userId) {
// System.out.println(userId);
UserRoleTemp u = new UserRoleTemp();
User user = userService.selectById(userId);
List<String> roles = userExtendService.getRoles(user.getUsername());
u.setId(userId);
u.setRoles(roles);
u.setUsername(user.getUsername());
return u;
}
use of com.luoxiao.model.User in project ssm_shiro_blog by Mandelo.
the class MainController method validateUser.
/**
* ajax验证用户名密码
*
* @return
*/
@ResponseBody
@RequestMapping(value = "/validatePassword")
public String validateUser(String username) {
User _user = userService.selectByUsername(username);
String _password = _user.getPassword();
if (_password == null) {
return "";
} else {
return _password;
}
}
use of com.luoxiao.model.User in project ssm_shiro_blog by Mandelo.
the class MainController method login.
/**
* 登录功能
*
* @param user
* @param model
* @return
*/
@RequestMapping(value = "/user/login", method = RequestMethod.POST)
public String login(User user, HttpSession session, Model model) {
UsernamePasswordToken token = new UsernamePasswordToken(user.getUsername(), user.getPassword());
Subject subject = SecurityUtils.getSubject();
subject.login(token);
User loginUser = userService.selectByUsername(user.getUsername());
session.setAttribute("loginUser", loginUser);
// System.out.println(loginUser);
return "/loginSuccess";
}
Aggregations