1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-20 20:40:56 +01:00

Add a numeric input control for TOTP codes

Summary:
Fixes T11365. I tested these variants:

  - `<input type="number" />`
  - `<input type="text" pattern="\d*" />`

Of these, this one (using `pattern`) appears to have the best behavior: it shows the correct keyboard on iOS mobile and does nothing on desktops.

Using `type="number"` causes unwanted sub-controls to appear in desktop Safari, and a numbers + symbols keyboard to appear on iOS (presumably so users can type "." and "-" and maybe ",").

Test Plan: Tested variants in desktop browsers and iOS simulator, see here and T11365 for discussion.

Reviewers: chad

Reviewed By: chad

Maniphest Tasks: T11365

Differential Revision: https://secure.phabricator.com/D16323
This commit is contained in:
epriestley 2016-07-23 13:28:02 -07:00
parent b6bf0f6a3b
commit 020df6f5cb
3 changed files with 25 additions and 1 deletions

View file

@ -1626,6 +1626,7 @@ phutil_register_library_map(array(
'PHUIFormIconSetControl' => 'view/form/control/PHUIFormIconSetControl.php', 'PHUIFormIconSetControl' => 'view/form/control/PHUIFormIconSetControl.php',
'PHUIFormInsetView' => 'view/form/PHUIFormInsetView.php', 'PHUIFormInsetView' => 'view/form/PHUIFormInsetView.php',
'PHUIFormLayoutView' => 'view/form/PHUIFormLayoutView.php', 'PHUIFormLayoutView' => 'view/form/PHUIFormLayoutView.php',
'PHUIFormNumberControl' => 'view/form/control/PHUIFormNumberControl.php',
'PHUIHandleListView' => 'applications/phid/view/PHUIHandleListView.php', 'PHUIHandleListView' => 'applications/phid/view/PHUIHandleListView.php',
'PHUIHandleTagListView' => 'applications/phid/view/PHUIHandleTagListView.php', 'PHUIHandleTagListView' => 'applications/phid/view/PHUIHandleTagListView.php',
'PHUIHandleView' => 'applications/phid/view/PHUIHandleView.php', 'PHUIHandleView' => 'applications/phid/view/PHUIHandleView.php',
@ -6185,6 +6186,7 @@ phutil_register_library_map(array(
'PHUIFormIconSetControl' => 'AphrontFormControl', 'PHUIFormIconSetControl' => 'AphrontFormControl',
'PHUIFormInsetView' => 'AphrontView', 'PHUIFormInsetView' => 'AphrontView',
'PHUIFormLayoutView' => 'AphrontView', 'PHUIFormLayoutView' => 'AphrontView',
'PHUIFormNumberControl' => 'AphrontFormControl',
'PHUIHandleListView' => 'AphrontTagView', 'PHUIHandleListView' => 'AphrontTagView',
'PHUIHandleTagListView' => 'AphrontTagView', 'PHUIHandleTagListView' => 'AphrontTagView',
'PHUIHandleView' => 'AphrontView', 'PHUIHandleView' => 'AphrontView',

View file

@ -132,7 +132,7 @@ final class PhabricatorTOTPAuthFactor extends PhabricatorAuthFactor {
'the authenticator correctly:')); 'the authenticator correctly:'));
$form->appendChild( $form->appendChild(
id(new AphrontFormTextControl()) id(new PHUIFormNumberControl())
->setLabel(pht('TOTP Code')) ->setLabel(pht('TOTP Code'))
->setName('totpcode') ->setName('totpcode')
->setValue($code) ->setValue($code)

View file

@ -0,0 +1,22 @@
<?php
final class PHUIFormNumberControl extends AphrontFormControl {
protected function getCustomControlClass() {
return 'phui-form-number';
}
protected function renderInput() {
return javelin_tag(
'input',
array(
'type' => 'text',
'pattern' => '\d*',
'name' => $this->getName(),
'value' => $this->getValue(),
'disabled' => $this->getDisabled() ? 'disabled' : null,
'id' => $this->getID(),
));
}
}