// 激活账号
 @RequestMapping(value = "/active.jspx", method = RequestMethod.GET)
 public String active(
     String username,
     String key,
     HttpServletRequest request,
     HttpServletResponse response,
     ModelMap model)
     throws IOException {
   CmsSite site = CmsUtils.getSite(request);
   WebErrors errors = validateActive(username, key, request, response);
   if (errors.hasErrors()) {
     return FrontUtils.showError(request, response, model, errors);
   }
   UnifiedUser user = unifiedUserMng.active(username, key);
   BbsUser bbsUser = bbsUserMng.findById(user.getId());
   String ip = RequestUtils.getIpAddr(request);
   authMng.activeLogin(user, ip, request, response, session);
   // 登录记录
   BbsLoginLog loginLog = new BbsLoginLog();
   loginLog.setIp(RequestUtils.getIpAddr(request));
   Calendar calendar = Calendar.getInstance();
   loginLog.setLoginTime(calendar.getTime());
   loginLog.setUser(bbsUser);
   bbsLoginMng.save(loginLog);
   // 在线时长统计
   BbsUserOnline online = bbsUser.getUserOnline();
   // 首次登陆
   online = new BbsUserOnline();
   online.setUser(bbsUser);
   online.initial();
   userOnlineMng.save(online);
   FrontUtils.frontData(request, model, site);
   return FrontUtils.getTplPath(
       request, site.getSolutionPath(), TPLDIR_MEMBER, REGISTER_ACTIVE_SUCCESS);
 }
Esempio n. 2
0
 @RequestMapping(value = "/register.jspx", method = RequestMethod.POST)
 public String submit(
     String username,
     String email,
     String password,
     CmsUserExt userExt,
     String captcha,
     String nextUrl,
     HttpServletRequest request,
     HttpServletResponse response,
     ModelMap model)
     throws IOException {
   CmsSite site = CmsUtils.getSite(request);
   WebErrors errors = validateSubmit(username, email, password, captcha, site, request, response);
   if (errors.hasErrors()) {
     return FrontUtils.showError(request, response, model, errors);
   }
   String ip = RequestUtils.getIpAddr(request);
   cmsUserMng.registerMember(username, email, password, ip, null, userExt);
   log.info("member register success. username={}", username);
   if (!StringUtils.isBlank(nextUrl)) {
     response.sendRedirect(nextUrl);
     return null;
   } else {
     return FrontUtils.showMessage(request, model, "global.success");
   }
 }
Esempio n. 3
0
  @RequestMapping(value = "/vote.jspx", method = RequestMethod.POST)
  public String submit(
      Integer voteId,
      Integer[] subIds,
      String[] reply,
      HttpServletRequest request,
      HttpServletResponse response,
      ModelMap model) {
    CmsSite site = CmsUtils.getSite(request);
    CmsUser user = CmsUtils.getUser(request);
    String ip = RequestUtils.getIpAddr(request);
    String cookieName = VOTE_COOKIE_PREFIX + voteId;
    Cookie cookie = CookieUtils.getCookie(request, cookieName);
    String cookieValue;
    if (cookie != null && !StringUtils.isBlank(cookie.getValue())) {
      cookieValue = cookie.getValue();
    } else {
      cookieValue = null;
    }
    List<Integer[]> itemIds = getItemIdsParam(request, subIds);
    Integer[] subTxtIds = null;
    if (reply != null && reply.length > 0) {
      subTxtIds = new Integer[reply.length];
      List<Integer> subTxtIdList = new ArrayList<Integer>();
      for (int i = 0; i < itemIds.size(); i++) {
        if (itemIds.get(i) == null) {
          subTxtIdList.add(subIds[i]);
        }
      }
      // 投票文本选项和题目id数组对应相同大小
      subTxtIds = (Integer[]) subTxtIdList.toArray(subTxtIds);
    }
    if (!validateSubmit(voteId, subIds, itemIds, user, ip, cookieValue, model)) {
      if (cookieValue == null) {
        // 随机cookie
        cookieValue = StringUtils.remove(UUID.randomUUID().toString(), "-");
        // 写cookie
        CookieUtils.addCookie(request, response, cookieName, cookieValue, Integer.MAX_VALUE, null);
      }
      CmsVoteTopic vote =
          cmsVoteTopicMng.vote(voteId, subTxtIds, itemIds, reply, user, ip, cookieValue);
      model.addAttribute("status", 0);
      model.addAttribute("vote", vote);

      log.info("vote CmsVote id={}, name={}", vote.getId(), vote.getTitle());
    }
    FrontUtils.frontData(request, model, site);
    return FrontUtils.getTplPath(request, site.getSolutionPath(), TPLDIR_SPECIAL, VOTE_RESULT);
  }
  @RequestMapping(value = "/register.jspx", method = RequestMethod.POST)
  public String submit(
      String username,
      String email,
      String password,
      BbsUserExt userExt,
      String captcha,
      String nextUrl,
      HttpServletRequest request,
      HttpServletResponse response,
      ModelMap model)
      throws IOException {
    CmsSite site = CmsUtils.getSite(request);
    BbsConfig config = bbsConfigMng.findById(site.getId());
    WebErrors errors = validateSubmit(username, email, password, captcha, site, request, response);
    if (errors.hasErrors()) {
      return FrontUtils.showError(request, response, model, errors);
    }
    String ip = RequestUtils.getIpAddr(request);
    Integer groupId = null;
    BbsUserGroup group = bbsConfigMng.findById(site.getId()).getRegisterGroup();
    if (group != null) {
      groupId = group.getId();
    }
    BbsUser user = null;
    if (config.getEmailValidate()) {
      EmailSender sender = configMng.getEmailSender();
      MessageTemplate msgTpl = configMng.getRegisterMessageTemplate();
      if (sender == null) {
        // 邮件服务器没有设置好
        model.addAttribute("status", 4);
      } else if (msgTpl == null) {
        // 邮件模板没有设置好
        model.addAttribute("status", 5);
      } else {
        try {
          user =
              bbsUserMng.registerMember(
                  username, email, password, ip, groupId, userExt, false, sender, msgTpl);
          bbsConfigEhCache.setBbsConfigCache(0, 0, 0, 1, user, site.getId());
          model.addAttribute("status", 0);
        } catch (Exception e) {
          // 发送邮件异常
          model.addAttribute("status", 100);
          model.addAttribute("message", e.getMessage());
          log.error("send email exception.", e);
        }
      }
      log.info("member register success. username={}", username);
      if (!StringUtils.isBlank(nextUrl)) {
        response.sendRedirect(nextUrl);
        return null;
      } else {
        FrontUtils.frontData(request, model, site);
        FrontUtils.frontPageData(request, model);
        return FrontUtils.getTplPath(
            request, site.getSolutionPath(), TPLDIR_MEMBER, REGISTER_RESULT);
      }
    } else {
      user = bbsUserMng.registerMember(username, email, password, ip, groupId, userExt);
      bbsConfigEhCache.setBbsConfigCache(0, 0, 0, 1, user, site.getId());
      log.info("member register success. username={}", username);
      FrontUtils.frontData(request, model, site);
      FrontUtils.frontPageData(request, model);
      model.addAttribute("success", true);
      return FrontUtils.getTplPath(request, site.getSolutionPath(), TPLDIR_MEMBER, LOGIN_INPUT);
    }

    /*
     * BbsUser user = bbsUserMng.registerMember(username, email, password,
     * ip, groupId, userExt);
     */
  }