예제 #1
0
  public ShopAdmin getAdmin(HttpServletRequest request, HttpServletResponse response, Website web) {
    Long webId = web.getId();
    Long adminId = (Long) session.getAttribute(request, SESSION_ADMIN_ID_KEY);

    ShopAdmin admin;
    if (adminId != null) {
      admin = shopAdminMng.findById(adminId);
      if (admin != null && admin.getWebsite().getId().equals(webId)) {
        // 本站管理员
        return admin;
      } else {
        // 其他站点跳转而来
        Long userId = admin.getAdmin().getUser().getId();
        admin = shopAdminMng.getByUserId(userId, webId);
        return admin;
      }
    }
    return null;
  }
예제 #2
0
 public ShopAdmin adminLogin(
     HttpServletRequest request,
     HttpServletResponse response,
     Website web,
     String username,
     String password)
     throws UsernameNotFoundException, BadCredentialsException, UserNotInWebsiteException {
   Long webId = web.getId();
   // 先退出登录
   logout(request, response);
   User user = login(username, password);
   ShopAdmin admin = shopAdminMng.getByUserId(user.getId(), webId);
   if (admin == null) {
     throw new UserNotInWebsiteException(
         "user '" + user.getUsername() + "' not in Website '" + webId + "'");
   }
   userMng.updateLoginInfo(user.getId(), request.getRemoteAddr());
   session.setAttribute(request, response, SESSION_USER_ID_KEY, user.getId());
   session.setAttribute(request, response, SESSION_ADMIN_ID_KEY, admin.getId());
   addUsernameCookie(admin.getUsername(), null, null, request, response);
   return admin;
 }