Ejemplo n.º 1
0
  @SuppressWarnings("unchecked")
  @ApiMethod(name = "userinfos.phone.test", path = "user_info_phone_test", httpMethod = "post")
  public UserInfo phoneTest(UserInfo userInfo) {
    // check if there is another user using same phone number
    PersistenceManager pm = PMF.getPersistenceManagerSQL();
    Query query = pm.newQuery(UserInfo.class);
    query.setFilter("phone == thePhone");
    query.declareParameters("String thePhone");
    List<UserInfo> userInfos = (List<UserInfo>) pm.newQuery(query).execute(userInfo.getPhone());

    // phone number already taken
    if (!userInfos.isEmpty()) return userInfo;

    try {
      String verNumber = getVerNumberString();
      sendVerNumber(userInfo.getPhone(), verNumber);

      // save verification code and phone number in verCode field together
      userInfo.setVerificationCode(verNumber + userInfo.getPhone());
      userInfo.setPhone("");
      update(userInfo);

      // erase verCode field before send back to the user
      userInfo.setVerificationCode("");
    } catch (TwilioRestException e) { // failed to send code message
    }

    return userInfo;
  }
Ejemplo n.º 2
0
  @ApiMethod(name = "userinfos.get", path = "user_info", httpMethod = "get")
  public UserInfo get(@Nullable @Named("userId") long userId) {
    PersistenceManager pm = PMF.getPersistenceManagerSQL();
    UserInfo userInfo = null;

    try {
      userInfo = pm.getObjectById(UserInfo.class, userId);
    } catch (JDOObjectNotFoundException e) {
    }

    return userInfo;
  }
Ejemplo n.º 3
0
  @ApiMethod(name = "userInfos.update", path = "user_info", httpMethod = "put")
  public UserInfo update(UserInfo userInfo) {
    PersistenceManager pm = PMF.getPersistenceManagerSQL();
    UserInfo target = null;

    // test
    if (userInfo.getPushToken() != null) {
      log.warning("user id : " + userInfo.getUserId());
      log.warning("push token : " + userInfo.getPushToken());
    }

    try {
      target = pm.getObjectById(UserInfo.class, userInfo.getUserId());
      target.update(userInfo);
    } catch (JDOObjectNotFoundException e) {
      return target;
    } finally {
      pm.close();
    }

    return target;
  }
Ejemplo n.º 4
0
  @ApiMethod(name = "userinfos.phone.insert", path = "user_info_phone_insert", httpMethod = "post")
  public UserInfo phoneInsert(UserInfo userInfo) {
    PersistenceManager pm = PMF.getPersistenceManagerSQL();
    UserInfo target = null;

    try {
      target = pm.getObjectById(UserInfo.class, userInfo.getUserId());

      if (target.verifyCode(userInfo.getPhone())) {
        target.setPhone(
            target.getVerificationCode().substring(target.getVerificationCode().indexOf("+")));
        target.setVerificationCode("");
      } else return null;
    } catch (JDOObjectNotFoundException e) {
      return null;
    } catch (StringIndexOutOfBoundsException e) {
      return null;
    } finally {
      pm.close();
    }

    return target;
  }