Exemplo n.º 1
0
  @GET
  @Produces(MediaType.APPLICATION_JSON)
  @Path("resetpassword/webpage")
  public Response getPasswordResetWebPage(@QueryParam("mail") String mail)
      throws MessagingException, IOException {
    if ((mail == null || mail.trim().equals(""))) {
      return Response.ok(AuthenticationConstants.EMAILPROVIDEDISNOTCORRECT).build();
    }

    final EntityManager em = emf.createEntityManager();
    Query queryE = em.createNamedQuery("User.findByEmail");
    queryE.setParameter("email", mail);
    List<User> userList = queryE.getResultList();
    if (userList.isEmpty() || userList.size() > 1) {
      return Response.ok(AuthenticationConstants.EMAILPROVIDEDISNOTCORRECT).build();
    }

    ServletContext sc = servletConfig.getServletContext();
    Properties tzMediaProperties = PropertiesUtils.getProperties(sc);
    String subject = tzMediaProperties.getProperty("password.retrival.mail.subject");
    String tail = tzMediaProperties.getProperty("password.retrival.mail.tail");

    final User userEntity = userList.get(0);
    String tokeyGenerated = TokenGenerator.nextToken();

    // Put the stake that holds the user password reset.
    TokenHolder.userPasswordTokenMap.put(userEntity.getUserId(), tokeyGenerated);
    String body =
        "<p>亲爱的"
            + userEntity.getEmail()
            + ",</p><p>"
            + "重新设置嘟嘟囔囔密码请点击下面的链接:</p>"
            // 链接
            + "<p><a href="
            + uriInfo.getBaseUri().toString().replace("resources", "#")
            + "resetuserpassword>"
            + uriInfo.getBaseUri().toString().replace("resources", "#")
            + "resetuserpassword</a>"
            + "</p>"
            // mail last text
            + tail;
    SendCloudMail.send(mail, subject, body);
    // TZMediaMail.send(mail, subject, body, null, sc);
    return Response.ok(AuthenticationConstants.EMAILSUCCESSFULLYSEND).build();
  }
Exemplo n.º 2
0
  @GET
  @Path("registration/mail")
  @Produces(MediaType.APPLICATION_JSON)
  public Response sendVerifyMessageToEmail(@QueryParam("mail") String mail)
      throws MessagingException, IOException {
    ServletContext sc = servletConfig.getServletContext();
    Properties tzMediaProperties = PropertiesUtils.getProperties(sc);
    String verificationCode = String.valueOf(VerificationCodeGenerator.randInt(100000, 999999));

    String subject = tzMediaProperties.getProperty("validation.with.mail.subject");
    String tail = tzMediaProperties.getProperty("password.retrival.mail.tail");
    if (mail != null) {
      final EntityManager em = emf.createEntityManager();
      Query queryE = em.createNamedQuery("User.findByEmail");
      queryE.setParameter("email", mail);
      List<User> userList = queryE.getResultList();
      // User already registered
      if (userList.size() > 0) {
        return Response.ok(
                new PhoneVerifyResponse(
                    AuthenticationConstants.EMAILPROVIDEDISNOTCORRECT, mail, null))
            .build();
      }
      String body =
          "<p>亲爱的 " + mail + ",</p>" + "<p>您的嘟嘟囔囔邮箱注册验证码是:" + verificationCode + "</p>" + tail;
      //            TZMediaMail.send(mail, subject, body, null, sc);
      SendCloudMail.send(mail, subject, body);
      TokenHolder.verificationCodeMap.put(mail, verificationCode);
      return Response.ok(
              new PhoneVerifyResponse(
                  AuthenticationConstants.EMAILSUCCESSFULLYSEND, null, verificationCode))
          .build();
    } else {
      return Response.ok(
              new PhoneVerifyResponse(
                  AuthenticationConstants.EMAILPROVIDEDISNOTCORRECT, mail, null))
          .build();
    }
  }