Exemplo n.º 1
0
  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;
    }
  }
Exemplo n.º 2
0
 public static boolean authMe(String uid) {
   try {
     Account account = new Account();
     account.setUid(uid);
     account.setStatus(Account.STATUS_NORMAL);
     account.setUpdateTime(System.currentTimeMillis());
     getAdapter().update(account);
     return true;
   } catch (Exception e) {
     e.printStackTrace();
     return false;
   }
 }