Skip to content

Commit

Permalink
Merge pull request #29 from sai-gillingham/main
Browse files Browse the repository at this point in the history
  • Loading branch information
KenTanaka authored Mar 22, 2023
2 parents 91f26c7 + f15640a commit e80dcca
Show file tree
Hide file tree
Showing 32 changed files with 608 additions and 751 deletions.
65 changes: 33 additions & 32 deletions Controller/Admin/ConfigController.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use Plugin\TwoFactorAuthCustomer42\Form\Type\TwoFactorAuthConfigType;
use Plugin\TwoFactorAuthCustomer42\Repository\TwoFactorAuthConfigRepository;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Annotation\Route;

Expand All @@ -38,41 +39,41 @@ public function __construct(TwoFactorAuthConfigRepository $smsConfigRepository)
$this->smsConfigRepository = $smsConfigRepository;
}

/**
* @Route("/%eccube_admin_route%/two_factor_auth_customer42/config", name="two_factor_auth_customer42_admin_config", methods={"GET", "POST"})
* @Template("TwoFactorAuthCustomer42/Resource/template/admin/config.twig")
*
* @param Request $request
*
* @return array
*/
public function index(Request $request)
{
// 設定情報、フォーム情報を取得
$SmsConfig = $this->smsConfigRepository->findOne();
$form = $this->createForm(TwoFactorAuthConfigType::class, $SmsConfig);
$form->handleRequest($request);
/**
* @Route("/%eccube_admin_route%/two_factor_auth_customer42/config", name="two_factor_auth_customer42_admin_config", methods={"GET", "POST"})
* @Template("TwoFactorAuthCustomer42/Resource/template/admin/config.twig")
*
* @param Request $request
*
* @return RedirectResponse|array
*/
public function index(Request $request)
{
// 設定情報、フォーム情報を取得
$SmsConfig = $this->smsConfigRepository->findOne();
$form = $this->createForm(TwoFactorAuthConfigType::class, $SmsConfig);
$form->handleRequest($request);

// 設定画面で登録ボタンが押されたらこの処理を行う
if ($form->isSubmitted() && $form->isValid()) {
// フォームの入力データを取得
$SmsConfig = $form->getData();
// 設定画面で登録ボタンが押されたらこの処理を行う
if ($form->isSubmitted() && $form->isValid()) {
// フォームの入力データを取得
$SmsConfig = $form->getData();

// フォームの入力データを保存
$this->entityManager->persist($SmsConfig);
$this->entityManager->flush($SmsConfig);
// フォームの入力データを保存
$this->entityManager->persist($SmsConfig);
$this->entityManager->flush($SmsConfig);

// 完了メッセージを表示
log_info('config', ['status' => 'Success']);
$this->addSuccess('プラグインの設定を保存しました。', 'admin');
// 完了メッセージを表示
log_info('config', ['status' => 'Success']);
$this->addSuccess('プラグインの設定を保存しました。', 'admin');

// 設定画面にリダイレクト
return $this->redirectToRoute('two_factor_auth_customer42_admin_config');
}
// 設定画面にリダイレクト
return $this->redirectToRoute('two_factor_auth_customer42_admin_config');
}

return [
'SmsConfig' => $SmsConfig,
'form' => $form->createView(),
];
}
return [
'SmsConfig' => $SmsConfig,
'form' => $form->createView(),
];
}
}
61 changes: 35 additions & 26 deletions Controller/CustomerPersonalValidationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
use Twig\Error\LoaderError;
use Twig\Error\RuntimeError;
use Twig\Error\SyntaxError;
use Twilio\Exceptions\ConfigurationException;
use Twilio\Exceptions\TwilioException;
use Twilio\Rest\Api\V2010\Account\MessageInstance;

class CustomerPersonalValidationController extends AbstractController
Expand All @@ -49,9 +51,9 @@ class CustomerPersonalValidationController extends AbstractController
/**
* TwoFactorAuthCustomerController constructor.
*
* @param CustomerRepository $customerRepository,
* @param CustomerTwoFactorAuthService $customerTwoFactorAuthService,
* @param Environment $twig
* @param CustomerRepository $customerRepository ,
* @param CustomerTwoFactorAuthService $customerTwoFactorAuthService ,
* @param Environment $twig
*/
public function __construct(
CustomerRepository $customerRepository,
Expand Down Expand Up @@ -146,6 +148,11 @@ public function deviceAuthInputOneTime(Request $request, $secret_key)
* @param $secret_key
*
* @return array|RedirectResponse
* @throws ConfigurationException
* @throws LoaderError
* @throws RuntimeError
* @throws SyntaxError
* @throws TwilioException
*/
public function deviceAuthSendOneTime(Request $request, $secret_key)
{
Expand Down Expand Up @@ -198,6 +205,28 @@ public function deviceAuthSendOneTime(Request $request, $secret_key)
];
}

/**
* デバイス認証用のワンタイムトークンチェック.
*
* @param $Customer
* @param $token
*
* @return boolean
*/
private function checkDeviceToken($Customer, $token): bool
{
$now = new \DateTime();

// フォームからのハッシュしたワンタイムパスワードとDBに保存しているワンタイムパスワードのハッシュは一致しているかどうか
if (
$Customer->getDeviceAuthOneTimeToken() !== $this->customerTwoFactorAuthService->readOneTimeToken($token) ||
$Customer->getDeviceAuthOneTimeTokenExpire() < $now) {
return false;
}

return true;
}

/**
* デバイス認証用のワンタイムトークンを送信.
*
Expand All @@ -209,6 +238,8 @@ public function deviceAuthSendOneTime(Request $request, $secret_key)
* @throws LoaderError
* @throws RuntimeError
* @throws SyntaxError
* @throws ConfigurationException
* @throws TwilioException
*/
private function sendDeviceToken(Customer $Customer, string $phoneNumber)
{
Expand All @@ -227,28 +258,6 @@ private function sendDeviceToken(Customer $Customer, string $phoneNumber)
]);

// SMS送信
return $this->customerTwoFactorAuthService->sendBySms($Customer, $phoneNumber, $body);
}

/**
* デバイス認証用のワンタイムトークンチェック.
*
* @param $Customer
* @param $token
*
* @return boolean
*/
private function checkDeviceToken($Customer, $token): bool
{
$now = new \DateTime();

// フォームからのハッシュしたワンタイムパスワードとDBに保存しているワンタイムパスワードのハッシュは一致しているかどうか
if (
$Customer->getDeviceAuthOneTimeToken() !== $this->customerTwoFactorAuthService->readOneTimeToken($token) ||
$Customer->getDeviceAuthOneTimeTokenExpire() < $now) {
return false;
}

return true;
return $this->customerTwoFactorAuthService->sendBySms($phoneNumber, $body);
}
}
2 changes: 1 addition & 1 deletion Controller/TwoFactorAuthCustomerController.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public function __construct(
CustomerRepository $customerRepository,
CustomerTwoFactorAuthService $customerTwoFactorAuthService,
Environment $twig
) {
) {
$this->customerRepository = $customerRepository;
$this->customerTwoFactorAuthService = $customerTwoFactorAuthService;
$this->twig = $twig;
Expand Down
17 changes: 8 additions & 9 deletions Entity/BaseInfoTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@ trait BaseInfoTrait
* @ORM\Column(name="two_factor_auth_use", type="boolean", nullable=false, options={"default":false})
*/
private bool $two_factor_auth_use;
/**
* SMS通知の設定
*
* @var bool
*
* @ORM\Column(name="option_activate_device", type="boolean", nullable=false, options={"default":false})
*/
private bool $option_activate_device;

/**
* @return bool
Expand All @@ -46,15 +54,6 @@ public function setTwoFactorAuthUse(bool $two_factor_auth_use): void
$this->two_factor_auth_use = $two_factor_auth_use;
}

/**
* SMS通知の設定
*
* @var bool
*
* @ORM\Column(name="option_activate_device", type="boolean", nullable=false, options={"default":false})
*/
private bool $option_activate_device;

/**
* @return bool
*/
Expand Down
46 changes: 23 additions & 23 deletions Entity/CustomerTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ trait CustomerTrait
/**
* 2段階認証機能の設定
*
* @var int
* @var int|null
*
* @ORM\Column(name="two_factor_auth_type", type="integer", nullable=true)
*/
Expand Down Expand Up @@ -98,13 +98,23 @@ public function getDeviceAuthOneTimeToken(): ?string
}

/**
* @param string $device_auth_one_time_token
* @param string|null $device_auth_one_time_token
*/
public function setDeviceAuthOneTimeToken(?string $device_auth_one_time_token): void
{
$this->device_auth_one_time_token = $device_auth_one_time_token;
}

/**
* Get resetExpire.
*
* @return \DateTime|null
*/
public function getDeviceAuthOneTimeTokenExpire()
{
return $this->device_auth_one_time_token_expire;
}

/**
* Set oneTimeTokenExpire.
*
Expand All @@ -119,16 +129,6 @@ public function setDeviceAuthOneTimeTokenExpire($deviceAuthOneTimeTokenExpire =
return $this;
}

/**
* Get resetExpire.
*
* @return \DateTime|null
*/
public function getDeviceAuthOneTimeTokenExpire()
{
return $this->device_auth_one_time_token_expire;
}

/**
* @return bool
*/
Expand All @@ -138,7 +138,7 @@ public function isDeviceAuthed(): bool
}

/**
* @param bool $two_factor_auth
* @param bool $device_authed
*/
public function setDeviceAuthed(bool $device_authed): void
{
Expand All @@ -162,25 +162,25 @@ public function setDeviceAuthedPhoneNumber(?string $device_authed_phone_number):
}

/**
* Set two-factor auth type.
* Get sex.
*
* @param TwoFactorAuthType|null $twoFactorAuthType
* @return TwoFactorAuthType|null
*/
public function setTwoFactorAuthType(TwoFactorAuthType $twoFactorAuthType = null)
public function getTwoFactorAuthType()
{
$this->TwoFactorAuthType = $twoFactorAuthType;

return $this;
return $this->TwoFactorAuthType;
}

/**
* Get sex.
* Set two-factor auth type.
*
* @return TwoFactorAuthType|null
* @param TwoFactorAuthType|null $twoFactorAuthType
*/
public function getTwoFactorAuthType()
public function setTwoFactorAuthType(TwoFactorAuthType $twoFactorAuthType = null)
{
return $this->TwoFactorAuthType;
$this->TwoFactorAuthType = $twoFactorAuthType;

return $this;
}

/**
Expand Down
Loading

0 comments on commit e80dcca

Please sign in to comment.