Package com.skyline.user.model

Examples of com.skyline.user.model.EmailToken


  @Autowired
  private EmailTokenDao emailTokenDao;

  private EmailToken genToken(long userId, String email, EmailTokenType type) {
    EmailToken token = new EmailToken();
    Date now = new Date();
    String tokenStr = genTokenStr(userId, email, type, now);
    token.setCheckTime(now);
    token.setEmail(email);
    token.setToken(tokenStr);
    token.setType(type);
    token.setUserId(userId);
    return token;
  }
View Full Code Here


  public EmailToken addToken(long userId, String email, EmailTokenType type) {
    List<EmailToken> uncheckedTokens = emailTokenDao.queryTokenByEmailAndTypeAndChecked(email, type, false);
    for (EmailToken ut : uncheckedTokens) {
      emailTokenDao.updateTokenChecked(ut.getId(), true);
    }
    EmailToken token = genToken(userId, email, type);
    emailTokenDao.insertToken(token);
    return token;

  }
View Full Code Here

  }

  @Override
  public EmailToken checkToken(String tokenStr) {
    EmailToken token = emailTokenDao.queryToken(tokenStr);
    if (token == null) {
      return null;
    }
    Date now = new Date();
    if (token.getCheckTime().getTime() - now.getTime() > (long) (24 * 3600 * 1000)) {
      return null;
    }
    if (token.isChecked()) {
      return null;
    }
    // 在这里出错了,所以我把它注释掉了
    // String generatedTokenStr=genTokenStr(token.getUserId(),
    // token.getEmail(), token.getType(), token.getCheckTime());
View Full Code Here

    return MAPPER;
  }

  @Override
  public EmailToken mapRow(ResultSet rs, int arg1) throws SQLException {
    EmailToken t = new EmailToken();
    t.setChecked(rs.getBoolean("checked"));
    try {
      t.setCheckTime(rs.getTimestamp("checkTime"));
    } catch (Exception e) {
    }
    t.setEmail(rs.getString("email"));
    t.setId(rs.getLong("id"));
    t.setToken(rs.getString("token"));
    t.setType(EmailTokenType.valueOf(rs.getString("type")));
    t.setUserId(rs.getLong("userId"));
    return t;
  }
View Full Code Here

        } else {
          toSendEmail = email;
          mav.addObject("message", "成功发送到您的E-mail(" + toSendEmail + ")。");
        }
        mav.addObject("email", email);
        EmailToken token = emailTokenService.addToken(user.getId(), email, EmailTokenType.PASSWORD_FIND);
        String emailTitle = FreeMarkerUtils.getForgetPasswordMailTitle(email);
        String emailContent = FreeMarkerUtils.getForgetPasswordMailContent(email, token.getToken());
        // emailTitle,emailContent输出已经测试过了
        MailUtils.sendHtmlMail(toSendEmail, emailTitle, emailContent);
        WebHelper.setSessionAttribute(null, Constant.SESSION_FIND_PSWD_STAT, FindPswdStat.FINISHED);
        mav.setViewName(ViewPaths.USER_FINDPSWDBYEMAIL);
      }
View Full Code Here

   * @return
   */
  @RequestMapping(value = "/password/check/{tokenStr}", method = RequestMethod.GET)
  public ModelAndView checkFindPswdToken(@PathVariable String tokenStr) {
    ModelAndView mav = new ModelAndView();
    EmailToken token = emailTokenService.checkToken(tokenStr);
    if (token != null) {
      WebHelper.setSessionAttribute(null, Constant.SESSION_FIND_PSWD_STAT, FindPswdStat.CHECKED_TOKEN);
      User user = accountInfoService.getAccountInfoByUserID(token.getUserId());
      WebHelper.setSessionAttribute(null, Constant.SESSION_FIND_PSWD_USER, user);
      WebHelper.setSessionAttribute(null, Constant.SESSION_FIND_PSWD_CHECKED_TOKEN_ID, token.getId());
      mav.setViewName(ViewPaths.USER_RESETPASSWORD);
    } else {
      // 验证出错
      mav.addObject("errorMessage","验证出错<br>可能由以下几个原因:<br>1.验证码输入出错;<br>2.验证码已经过期(24小时);<br>请重试,谢谢!<br>");
      mav.setViewName(ViewPaths.USER_FINDPSWDREQUEST);
View Full Code Here

    }
  }

  //@Test
  public void insertToken() {
    EmailToken t=new EmailToken();
    t.setEmail("burningcl@gmail.com1");
    t.setToken("this is token4");
    t.setType(EmailTokenType.PASSWORD_FIND);
    t.setUserId(2);
    emailTokenDao.insertToken(t);
  }
View Full Code Here

  }
 
  @Test
  public void testQueryToken (){
    String tokenStr="032ea1486ed8f5266589d8c9b6e7411d";
    EmailToken token=emailTokenDao.queryToken(tokenStr);
    System.out.println(token.getEmail());
  }
View Full Code Here

TOP

Related Classes of com.skyline.user.model.EmailToken

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.