Exemple #1
0
  @Override
  public void validate() throws Exception {
    RequestContext ctx = getContext();
    User user = UserStore.getInstance().load(ctx.getUserID());

    if (isParameter("enter")) {
      validateParameterPhone("number");
      //			String phone = validateParameterPhone("number");
      //			if (phone.equals(user.getPhone()))
      //			{
      //				throw new WebFormException("number", getString("profile:Phone.NoChange"));
      //			}
    }

    if (isParameter("verify")) {
      String code =
          validateParameterString("code", CODE_LEN, CODE_LEN)
              + ":"
              + getParameterString("fullnumber");
      if (code.equals(user.getPhoneVerificationCode()) == false) {
        // Wrong code
        throw new WebFormException("code", getString("profile:Phone.IncorrectCode"));
      }
    }
  }
Exemple #2
0
  @Override
  public void commit() throws Exception {
    RequestContext ctx = getContext();
    final User user = UserStore.getInstance().open(ctx.getUserID());

    if (isParameter("send")) {
      Random r = new Random();
      String code = "";
      while (code.length() < CODE_LEN) {
        code += String.valueOf(r.nextInt(10));
      }
      user.setPhoneVerificationCode(code + ":" + getParameterString("fullnumber"));
      UserStore.getInstance().save(user);

      // Initiate call to phone number with verification code
      new Thread() {
        @Override
        public void run() {
          try {
            //						if (Setup.isDebug())
            {
              Debug.logln("Verification code: " + user.getPhoneVerificationCode());
            }
            //						else
            {
              VoiceServer.startOutboundCall(
                  user.getID(), getParameterString("fullnumber"), COMMAND, null);
            }
          } catch (Exception e) {
          }
        }
      }.start();
    } else if (isParameter("verify")) {
      // Verified!
      user.setPhone(getParameterString("fullnumber"));
      user.setPhoneVerificationCode(null);
      UserStore.getInstance().save(user);

      // Support guided setup
      progressGuidedSetup();

      // Go back to the contact info page
      throw new AfterCommitRedirectException();
    } else if (isParameter("clear")) {
      user.setPhone(null);
      user.setPhoneVerificationCode(null);
      UserStore.getInstance().save(user);

      // Support guided setup
      progressGuidedSetup();

      // Go back to the contact info page
      throw new AfterCommitRedirectException();
    }
  }
Exemple #3
0
  private void renderEnterPhone() throws Exception {
    RequestContext ctx = getContext();
    User user = UserStore.getInstance().load(ctx.getUserID());
    Server fed = ServerStore.getInstance().loadFederation();

    writeFormOpen();

    TwoColFormControl twoCol = new TwoColFormControl(this);

    twoCol.writeTextRow(getString("profile:Phone.EnterHelp"));
    twoCol.writeSpaceRow();

    twoCol.writeRow(getString("profile:Phone.Number"));
    new PhoneInputControl(twoCol, "number")
        .limitCountries(fed.getVoiceCountries())
        .setInitialValue(user.getPhone())
        .render();

    twoCol.render();

    write("<br>");
    writeButton("enter", getString("controls:Button.Next"));
    write(" ");
    if (ctx.getCommand(1).equals(UrlGenerator.COMMAND_SETUP)) {
      new ButtonInputControl(this, "clear")
          .setSubdued(true)
          .setValue(getString("profile:Phone.Skip"))
          .render();
    } else if (!Util.isEmpty(user.getPhone())) {
      new ButtonInputControl(this, "clear")
          .setStrong(true)
          .setValue(getString("profile:Phone.Clear"))
          .render();
    }

    writeFormClose();
  }