コード例 #1
0
ファイル: AccountManager.java プロジェクト: tomliau33/iMyApps
  public static boolean putAccount(Account account) {
    try {
      if (StringUtils.isEmpty(account.getUid())) {
        account.setCreateTime(System.currentTimeMillis());
        account.setUpdateTime(account.getCreateTime());
        account.setRole(Account.ROLE_USER);
        account.setStatus(Account.STATUS_CREATED);

        for (int i = 0; i < 10; i++) {
          String uid;

          uid =
              String.valueOf(System.currentTimeMillis())
                  + String.valueOf(Math.abs(InstanceUtils.random.nextInt(1000)));

          synchronized (Runtime.getRuntime()) {
            if (getAdapter().get(uid) != null) continue;
            account.setUid(uid);
            getAdapter().put(account);
            break;
          }
        }
      } else {
        account.setUpdateTime(System.currentTimeMillis());
        getAdapter().update(account);
      }

      return true;
    } catch (Exception e) {
      e.printStackTrace();
      return false;
    }
  }
コード例 #2
0
ファイル: AccountManager.java プロジェクト: tomliau33/iMyApps
  public static boolean sendAuthMail(String uid) {
    try {
      Account account = getAccountByUid(uid);

      if (account == null) {
        return false;
      }

      String authCode = getAuthCode(uid);
      String authUrl =
          Configure.HomeURL
              + "/authme?uid="
              + uid
              + "&authcode="
              + URLEncoder.encode(authCode, "UTF-8");
      StringBuilder sb = new StringBuilder();
      sb.append("Hello ")
          .append(account.getLoginName())
          .append(
              ",\n\n"
                  + "Welcome to register iMyApps account.\n"
                  + "If you had registered iMyApps account, please click below link:\n\n");
      sb.append(authUrl)
          .append(
              "\n\n" + "If you didn't register iMyApps account, please do not click the link.\n");
      sb.append("Thank you!\n\n" + "iMyApps\n\n" + "Website: ")
          .append(Configure.HomeURL)
          .append("\n");

      MailUtils.mailTo(
          Configure.MailFrom,
          account.getEmail(),
          Messages.msg.getString("authmail_title"),
          sb.toString());
      logger.info(
          "Send auth mail to "
              + account.getUid()
              + " / "
              + account.getLoginName()
              + " / "
              + account.getEmail()
              + " - "
              + authUrl);
      // logger.info(sb.toString());

      return true;
    } catch (Exception e) {
      e.printStackTrace();
      logger.info("Send auth mail to " + uid + " failed!");
      return false;
    }
  }