예제 #1
0
  public ShopMember memberLogin(
      HttpServletRequest request, HttpServletResponse response, String username)
      throws UsernameNotFoundException, BadCredentialsException, UserNotInWebsiteException,
          UserNotAcitveException {
    //		Long webId = web.getId();
    // 先退出登录
    logout(request, response);
    User user = userMng.getByUsername(username);
    ShopMember member = shopMemberMng.getByUsername(username);
    if (member == null) {

      throw new UserNotInWebsiteException("user '" + user.getUsername());

    } else {
      if (!member.getMember().getActive()) {
        throw new UserNotAcitveException("user '" + user.getUsername());
      }
    }
    userMng.updateLoginInfo(user.getId(), request.getRemoteAddr());
    rememberMeService.loginSuccess(request, response, member.getMember());
    session.setAttribute(request, response, SESSION_USER_ID_KEY, user.getId());
    session.setAttribute(request, response, SESSION_MEMBER_ID_KEY, member.getId());
    addUsernameCookie(member.getUsername(), null, null, request, response);
    shoppingSvc.addCookie(member, request, response);
    return member;
  }
예제 #2
0
 private ShopMember getMemberFromSession(
     HttpServletRequest request, HttpServletResponse response, Website web) {
   Long memberId = (Long) session.getAttribute(request, SESSION_MEMBER_ID_KEY);
   System.out.println(session.getSessionId(request, response));
   ShopMember member = null;
   Long webId = web.getId();
   if (memberId != null) {
     member = shopMemberMng.findById(memberId);
     // 本站会员
     /*if (member != null && member.getWebsite().getId().equals(webId)) {
     	return member;
     }*/
     // 全站会员
     if (member != null) {
       return member;
     }
   }
   Long userId = (Long) session.getAttribute(request, SESSION_USER_ID_KEY);
   if (userId != null) {
     member = shopMemberMng.getByUserId(webId, userId);
     if (member == null) {
       ShopConfig config = shopConfigMng.findById(webId);
       // 自动注册
       if (config.getRegisterAuto()) {
         member = shopMemberMng.join(userId, webId, config.getRegisterGroup());
       }
     }
     if (member != null) {
       session.setAttribute(request, response, SESSION_MEMBER_ID_KEY, member.getId());
     }
   }
   return member;
 }
예제 #3
0
 private ShopMember getMemberFromCookie(
     HttpServletRequest request, HttpServletResponse response, Website web) {
   Member coreMember;
   try {
     coreMember = (Member) rememberMeService.autoLogin(request, response);
     if (coreMember == null) {
       return null;
     }
   } catch (CookieTheftException e) {
     log.warn("remember me cookie theft: {}", e.getMessage());
     return null;
   }
   // 无法自动登录
   if (coreMember == null) {
     return null;
   }
   Long webId = web.getId();
   Long userId = coreMember.getUser().getId();
   ShopMember member = null;
   // 改变站点
   boolean change = false;
   // 其他站点会员
   if (!coreMember.getWebsite().getId().equals(webId)) {
     coreMember = memberMng.getByUserId(webId, userId);
     change = true;
   }
   if (coreMember == null) {
     // 考虑自动注册
     ShopConfig config = shopConfigMng.findById(webId);
     if (config.getRegisterAuto()) {
       member = shopMemberMng.join(userId, webId, config.getRegisterGroup());
       log.debug("shop member auto login. username= {}", member.getUsername());
     } else {
       log.debug("shop member not allow auto login.");
     }
   } else {
     member = shopMemberMng.findById(coreMember.getId());
     // 不应该为null,可能在某些地方有错误。
     if (member == null) {
       throw new IllegalStateException(
           "This is JspGou's BUG, ShopMember here should not be null.");
     }
   }
   if (member != null) {
     userMng.updateLoginInfo(userId, request.getRemoteAddr());
     session.setAttribute(
         request, response, SESSION_USER_ID_KEY, member.getMember().getUser().getId());
     session.setAttribute(request, response, SESSION_MEMBER_ID_KEY, member.getMember().getId());
     //			addUsernameCookie(member.getUsername(), member.getFirstname(),
     //					member.getLastname(), request, response);
     addUsernameCookie(member.getUsername(), null, null, request, response);
     if (change) {
       // 不用实现的这么复杂
       // rememberMeService.loginChange(request, response, member
       // .getMember());
     }
   }
   return member;
 }
예제 #4
0
 /** 会员中心优惠劵 */
 @RequestMapping(value = "/myCoupon.jspx", method = RequestMethod.GET)
 public String pay1(HttpServletRequest request, ModelMap model) {
   Website web = SiteUtils.getWeb(request);
   ShopMember member = MemberThread.get();
   List<MemberCoupon> list = memberCouponMng.getList(member.getId());
   model.addAttribute("couList", list);
   model.addAttribute("historyProductIds", getHistoryProductIds(request));
   ShopFrontHelper.setCommonData(request, model, web, 1);
   return web.getTplSys("member", MessageResolver.getMessage(request, "tpl.myCoupon"));
 }
예제 #5
0
  // 选择收货地址、付款方式、配送方式
  @RequestMapping(value = "/cart/checkout_shipping.jspx")
  public String shippingInput(
      Long[] cart2Checkbox,
      HttpServletRequest request,
      HttpServletResponse response,
      ModelMap model) {
    Website web = SiteUtils.getWeb(request);
    ShopMember member = MemberThread.get();
    if (member == null) {
      return "redirect:../login.jspx";
    }
    Cart cart = shoppingSvc.getCart(member.getId());
    if (cart == null) {
      return "redirect:shopping_cart.jspx";
    }
    List<PopularityItem> popularityItems = null;
    Double popularityPrice = 0.0;
    if (cart != null) {
      popularityItems = popularityItemMng.getlist(cart.getId(), null);
      for (PopularityItem popularityItem : popularityItems) {
        popularityPrice +=
            popularityItem.getPopularityGroup().getPrivilege() * popularityItem.getCount();
      }
    }

    Set<CartItem> items = getItems(cart2Checkbox, cart);
    Double price = getPrice(items);
    // 配送方式
    List<Shipping> splist = shippingMng.getList(web.getId(), true);
    // 会员地址
    List<ShopMemberAddress> smalist = shopMemberAddressMng.getList(member.getId());
    // 所处省份
    List<Address> plist = addressMng.getListById(null);
    // 付款方式
    List<Payment> paylist = paymentMng.getList((long) 1, true);
    model.addAttribute(
        "memberCouponlist", memberCouponMng.getList(member.getId(), new BigDecimal(price)));
    model.addAttribute("items", getItems(cart2Checkbox, cart));
    model.addAttribute("smalist", smalist);
    model.addAttribute("plist", plist);
    model.addAttribute("paylist", paylist);
    model.addAttribute("splist", splist);
    model.addAttribute("popularityPrice", popularityPrice);
    ShopFrontHelper.setCommonData(request, model, web, 1);
    return web.getTplSys(MEMBER_SYS, MessageResolver.getMessage(request, CHECKOUT_SHIPPING));
  }
예제 #6
0
 public ShopMember memberLogin(
     HttpServletRequest request,
     HttpServletResponse response,
     Website web,
     String username,
     String password)
     throws UsernameNotFoundException, BadCredentialsException, UserNotInWebsiteException,
         UserNotAcitveException {
   Long webId = web.getId();
   // 先退出登录
   logout(request, response);
   User user = login(username, password);
   ShopMember member = shopMemberMng.getByUserId(webId, user.getId());
   if (member == null) {
     ShopConfig config = shopConfigMng.findById(webId);
     if (config.getRegisterAuto()) {
       // 自动注册
       member = shopMemberMng.join(user, webId, config.getRegisterGroup());
     } else {
       throw new UserNotInWebsiteException(
           "user '" + user.getUsername() + "' not in Website '" + webId + "'");
     }
   } else {
     if (!member.getMember().getActive()) {
       throw new UserNotAcitveException(
           "user '" + user.getUsername() + "' not Active '" + webId + "'");
     }
   }
   userMng.updateLoginInfo(user.getId(), request.getRemoteAddr());
   rememberMeService.loginSuccess(request, response, member.getMember());
   session.setAttribute(request, response, SESSION_USER_ID_KEY, user.getId());
   session.setAttribute(request, response, SESSION_MEMBER_ID_KEY, member.getId());
   addUsernameCookie(member.getUsername(), null, null, request, response);
   shoppingSvc.addCookie(member, request, response);
   return member;
 }