Esempio n. 1
0
  /**
   * 登录
   *
   * @return
   */
  @RequestMapping(value = "/action/login")
  public ModelAndView login(
      Member entity,
      RedirectAttributes attr,
      HttpServletRequest request,
      HttpServletResponse response) {

    ModelAndView mv = new ModelAndView();
    DetachedCriteria criteria = memberService.createDetachedCriteria();

    criteria.add(Restrictions.eq("username", entity.getUsername()));
    criteria.add(Restrictions.eq("password", entity.getPassword()));

    List<Member> list = memberService.findByCriteria(criteria);

    if (!list.isEmpty()) {
      // attr.addAttribute("loginMember", list.get(0).getId().toString());

      // DetachedCriteria criteria2 =
      // userService.createDetachedCriteria();
      // criteria2.add(Restrictions.eq("member", list.get(0)));
      //
      // List<User> list2 = userService.findByCriteria(criteria2);
      entity = list.get(0);
      WebUtils.setSessionAttribute(request, "member", list.get(0));
      // WebUtils.setSessionAttribute(request, "user", list2.get(0));

      // session.setAttribute("member", list.get(0));
      // session.setAttribute("user", list2.get(0));

      // save
      SessionUtil.getInstance().saveMemberCookie(entity);

      attr.addFlashAttribute("msg", "登录成功!");
      mv.setViewName("redirect:/member/index");
    } else {
      attr.addFlashAttribute("msg", "账号不存在!");
      mv.setViewName("redirect:/member/login");
    }

    return mv;
  }
Esempio n. 2
0
 /**
  * 注册
  *
  * @param entity
  * @return
  */
 @RequestMapping(value = "/action/reg")
 public ModelAndView reg(Member entity, RedirectAttributes attr, HttpServletRequest request) {
   ModelAndView mv = new ModelAndView();
   entity.setEmail(entity.getUsername());
   entity.setRegIp(HttpUtil.getIpAddr(request));
   entity.setRegTime(new Date());
   memberService.save(entity);
   attr.addFlashAttribute("msg", "帐号重复存在!");
   mv.setViewName("redirect:/member/login");
   return mv;
 }
Esempio n. 3
0
  @RequestMapping(value = "/list")
  public ModelAndView list(RedirectAttributes attr) {

    List<Member> list = memberService.loadAll();

    ModelAndView mv = new ModelAndView();
    mv.addObject("list", list);
    mv.addObject("loginMember", attr);
    mv.setViewName("member_list");

    return mv;
  }