diff options
author | Christoph Wurst <christoph@winzerhof-wurst.at> | 2018-05-07 11:31:13 +0300 |
---|---|---|
committer | Christoph Wurst <christoph@winzerhof-wurst.at> | 2018-05-07 11:31:13 +0300 |
commit | a23a7ea370af88bc51627f2a82ff9fe8ed837c73 (patch) | |
tree | 13cfe0eb8d21a643431747fe1ef08e70c89d5503 /lib/Provider | |
parent | 677968dc76a12d3347c2fe173eb6020733f77cdc (diff) |
Finish basic impl
Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
Diffstat (limited to 'lib/Provider')
-rw-r--r-- | lib/Provider/SmsProvider.php | 16 | ||||
-rw-r--r-- | lib/Provider/State.php | 49 |
2 files changed, 54 insertions, 11 deletions
diff --git a/lib/Provider/SmsProvider.php b/lib/Provider/SmsProvider.php index a0dfcba..f5dc0ce 100644 --- a/lib/Provider/SmsProvider.php +++ b/lib/Provider/SmsProvider.php @@ -25,6 +25,7 @@ namespace OCA\TwoFactorSms\Provider; use OCA\TwoFactorSms\Exception\PhoneNumberMismatchException; use OCA\TwoFactorSms\Exception\SmsTransmissionException; +use OCA\TwoFactorSms\PhoneNumberMask; use OCA\TwoFactorSms\Service\ISmsService; use OCA\TwoFactorSms\Service\SetupService; use OCP\Authentication\TwoFactorAuth\IProvider; @@ -37,6 +38,9 @@ use OCP\Template; class SmsProvider implements IProvider { + const STATE_DISABLED = 0; + const STATE_VERIFYING = 1; + const STATE_ENABLED = 2; const SESSION_KEY = 'twofactor_sms_secret'; /** @var ISmsService */ @@ -115,7 +119,7 @@ class SmsProvider implements IProvider { } $tmpl = new Template('twofactor_sms', 'challenge'); - $tmpl->assign('phone', $this->protectPhoneNumber($phoneNumber)); + $tmpl->assign('phone', PhoneNumberMask::maskNumber($phoneNumber)); if ($this->config->getSystemValue('debug', false)) { $tmpl->assign('secret', $secret); } @@ -123,16 +127,6 @@ class SmsProvider implements IProvider { } /** - * convert 123456789 to ******789 - */ - private function protectPhoneNumber(string $number): string { - $length = strlen($number); - $start = $length - 3; - - return str_repeat('*', $start) . substr($number, $start); - } - - /** * Verify the given challenge */ public function verifyChallenge(IUser $user, string $challenge): bool { diff --git a/lib/Provider/State.php b/lib/Provider/State.php new file mode 100644 index 0000000..c7467b0 --- /dev/null +++ b/lib/Provider/State.php @@ -0,0 +1,49 @@ +<?php + +/** + * @copyright 2018 Christoph Wurst <christoph@winzerhof-wurst.at> + * + * @author 2018 Christoph Wurst <christoph@winzerhof-wurst.at> + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ + +namespace OCA\TwoFactorSms\Provider; + +use JsonSerializable; + +class State implements JsonSerializable { + + /** @var int */ + private $state; + + /** @var string */ + private $phoneNumber; + + public function __construct(int $state, string $phoneNumber = null) { + $this->state = $state; + $this->phoneNumber = $phoneNumber; + } + + public function jsonSerialize() { + return [ + 'state' => $this->state, + 'phoneNumber' => $this->phoneNumber, + ]; + } + +} |