Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "会員登録済みのメールアドレスを判別不可にする" #5460

Merged
merged 4 commits into from
Aug 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions codeception/acceptance/EF04CustomerCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ class EF04CustomerCest
*/
public function customer_会員登録正常(AcceptanceTester $I)
{
$I->getScenario()->incomplete('4.2.0-betaではスキップ');

$I->wantTo('EF0401-UC01-T01 会員登録 正常パターン');
$I->amOnPage('/entry');
$faker = Fixtures::get('faker');
Expand Down Expand Up @@ -104,7 +102,6 @@ public function customer_会員登録正常(AcceptanceTester $I)

public function customer_会員登録異常1(AcceptanceTester $I)
{
$I->getScenario()->incomplete('4.2.0-betaではスキップ');
$I->wantTo('EF0401-UC01-T02 会員登録 異常パターン 重複');
$I->amOnPage('/entry');

Expand Down
216 changes: 85 additions & 131 deletions src/Eccube/Controller/EntryController.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
namespace Eccube\Controller;

use Eccube\Entity\BaseInfo;
use Eccube\Entity\Customer;
use Eccube\Entity\Master\CustomerStatus;
use Eccube\Event\EccubeEvents;
use Eccube\Event\EventArgs;
Expand Down Expand Up @@ -169,57 +168,39 @@ public function index(Request $request)
case 'complete':
log_info('会員登録開始');

$existCustomer = $this->customerRepository->findOneBy([
'email' => $Customer->getEmail(),
'Status' => [
CustomerStatus::PROVISIONAL,
CustomerStatus::REGULAR,
],
]);
$encoder = $this->encoderFactory->getEncoder($Customer);
$salt = $encoder->createSalt();
$password = $encoder->encodePassword($Customer->getPlainPassword(), $salt);
$secretKey = $this->customerRepository->getUniqueSecretKey();

if ($existCustomer) {
log_info('会員登録済のため登録処理をスキップ');
} else {
log_info('会員登録を実行');

$encoder = $this->encoderFactory->getEncoder($Customer);
$salt = $encoder->createSalt();
$password = $encoder->encodePassword($Customer->getPlainPassword(), $salt);
$secretKey = $this->customerRepository->getUniqueSecretKey();

$Customer
->setSalt($salt)
->setPassword($password)
->setSecretKey($secretKey)
->setPoint(0);

$this->entityManager->persist($Customer);
$this->entityManager->flush();

log_info('会員登録完了');

$event = new EventArgs(
[
'form' => $form,
'Customer' => $Customer,
],
$request
);
}
$Customer
->setSalt($salt)
->setPassword($password)
->setSecretKey($secretKey)
->setPoint(0);

$this->entityManager->persist($Customer);
$this->entityManager->flush();

log_info('会員登録完了');

$event = new EventArgs(
[
'form' => $form,
'Customer' => $Customer,
],
$request
);
$this->eventDispatcher->dispatch($event, EccubeEvents::FRONT_ENTRY_INDEX_COMPLETE);

// 会員登録済の場合は既存のsecret_keyを利用
$secretKey = $existCustomer ? $existCustomer->getSecretKey() : $Customer->getSecretKey();
$activateFlg = $this->BaseInfo->isOptionCustomerActivate();

// 仮会員設定が有効な場合は、確認メールを送信し完了画面表示.
if ($this->BaseInfo->isOptionCustomerActivate()) {
log_info('仮会員設定が有効');

$activateUrl = $this->generateUrl('entry_activate', ['secret_key' => $secretKey], UrlGeneratorInterface::ABSOLUTE_URL);
if ($activateFlg) {
$activateUrl = $this->generateUrl('entry_activate', ['secret_key' => $Customer->getSecretKey()], UrlGeneratorInterface::ABSOLUTE_URL);

// メール送信
$this->mailService->sendCustomerConfirmMail($Customer, $activateUrl, $existCustomer);
$this->mailService->sendCustomerConfirmMail($Customer, $activateUrl);

if ($event->hasResponse()) {
return $event->getResponse();
Expand All @@ -229,31 +210,14 @@ public function index(Request $request)

return $this->redirectToRoute('entry_complete');
} else {
log_info('仮会員設定が無効');

if ($existCustomer) {
// 会員登録済の場合はメール通知のみ
$this->mailService->sendCustomerCompleteMail($Customer, $existCustomer);

log_info('会員登録完了画面へリダイレクト');

return $this->redirectToRoute('entry_activate_complete', [
'qtyInCart' => $this->getQuantityInCart(),
]);
} else {
// 本会員として更新
$this->updateRegularCustomer($Customer);
// ログイン済へ変更
$this->doLogin($Customer, $request);
// メール通知
$this->mailService->sendCustomerCompleteMail($Customer);

log_info('会員登録完了画面へリダイレクト');

return $this->redirectToRoute('entry_activate_complete', [
'qtyInCart' => $this->getQuantityInCart(),
]);
}
// 仮会員設定が無効な場合は、会員登録を完了させる.
$qtyInCart = $this->entryActivate($request, $Customer->getSecretKey());

// URLを変更するため完了画面にリダイレクト
return $this->redirectToRoute('entry_activate', [
'secret_key' => $Customer->getSecretKey(),
'qtyInCart' => $qtyInCart,
]);
}
}
}
Expand All @@ -264,7 +228,7 @@ public function index(Request $request)
}

/**
* 会員登録完了画面(仮会員).
* 会員登録完了画面.
*
* @Route("/entry/complete", name="entry_complete", methods={"GET"})
* @Template("Entry/complete.twig")
Expand All @@ -277,9 +241,10 @@ public function complete()
/**
* 会員のアクティベート(本会員化)を行う.
*
* @Route("/entry/activate/{secret_key}", name="entry_activate", methods={"GET"})
* @Route("/entry/activate/{secret_key}/{qtyInCart}", name="entry_activate", methods={"GET"})
* @Template("Entry/activate.twig")
*/
public function activate(Request $request, $secret_key)
public function activate(Request $request, $secret_key, $qtyInCart = null)
{
$errors = $this->recursiveValidator->validate(
$secret_key,
Expand All @@ -293,85 +258,74 @@ public function activate(Request $request, $secret_key)
]
);

if (count($errors) === 0) {
$Customer = $this->customerRepository->getProvisionalCustomerBySecretKey($secret_key);
if (null === $Customer) {
throw new HttpException\NotFoundHttpException();
}

// 本会員として更新
$this->updateRegularCustomer($Customer);
// ログイン済へ変更
$this->doLogin($Customer, $request);
// メール通知
$this->mailService->sendCustomerCompleteMail($Customer);

return $this->redirectToRoute('entry_activate_complete', [
'qtyInCart' => $this->getQuantityInCart(),
]);
if (!is_null($qtyInCart)) {
return [
'qtyInCart' => $qtyInCart,
];
} elseif ($request->getMethod() === 'GET' && count($errors) === 0) {
// 会員登録処理を行う
$qtyInCart = $this->entryActivate($request, $secret_key);

return [
'qtyInCart' => $qtyInCart,
];
}

throw new HttpException\NotFoundHttpException();
}

/**
* 会員登録完了画面(本会員).
* 会員登録処理を行う
*
* @Route("/entry/activate_complete", name="entry_activate_complete", methods={"GET"})
* @Template("Entry/activate.twig")
*/
public function activate_complete(Request $request)
{
return ['qtyInCart' => $request->query->get('qtyInCart')];
}

/**
* カート内の登録数を取得する.
* @param Request $request
* @param $secret_key
*
* @return int
* @return \Eccube\Entity\Cart|mixed
*/
private function getQuantityInCart(): int
private function entryActivate(Request $request, $secret_key)
{
log_info('本会員登録開始');
$Customer = $this->customerRepository->getProvisionalCustomerBySecretKey($secret_key);
if (is_null($Customer)) {
throw new HttpException\NotFoundHttpException();
}

$CustomerStatus = $this->customerStatusRepository->find(CustomerStatus::REGULAR);
$Customer->setStatus($CustomerStatus);
$this->entityManager->persist($Customer);
$this->entityManager->flush();

log_info('本会員登録完了');

$event = new EventArgs(
[
'Customer' => $Customer,
],
$request
);
$this->eventDispatcher->dispatch($event, EccubeEvents::FRONT_ENTRY_ACTIVATE_COMPLETE);

// メール送信
$this->mailService->sendCustomerCompleteMail($Customer);

// Assign session carts into customer carts
$Carts = $this->cartService->getCarts();
$qtyInCart = 0;
foreach ($Carts as $Cart) {
$qtyInCart += $Cart->getTotalQuantity();
}

// 本会員登録してログイン状態にする
$token = new UsernamePasswordToken($Customer, null, 'customer', ['ROLE_USER']);
$this->tokenStorage->setToken($token);
$request->getSession()->migrate(true);

if ($qtyInCart) {
$this->cartService->save();
}

return $qtyInCart;
}

/**
* ログイン状態に更新する.
*
* @param Customer $Customer
* @param Request $request
*
* @return void
*/
private function doLogin(Customer $Customer, Request $request): void
{
$token = new UsernamePasswordToken($Customer, null, 'customer', ['ROLE_USER']);
$this->tokenStorage->setToken($token);
$request->getSession()->migrate(true);
}
log_info('ログイン済に変更', [$this->getUser()->getId()]);

/**
* 本会員へ更新する.
*
* @param Customer $Customer
*
* @return void
*/
private function updateRegularCustomer(Customer $Customer): void
{
$CustomerStatus = $this->customerStatusRepository->find(CustomerStatus::REGULAR);
$Customer->setStatus($CustomerStatus);
$this->entityManager->persist($Customer);
$this->entityManager->flush();
return $qtyInCart;
}
}
12 changes: 12 additions & 0 deletions src/Eccube/Entity/Customer.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@
namespace Eccube\Entity;

use Doctrine\ORM\Mapping as ORM;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\Validator\Mapping\ClassMetadata;

if (!class_exists('\Eccube\Entity\Customer')) {
/**
Expand Down Expand Up @@ -330,6 +332,16 @@ public function eraseCredentials()
{
}

// TODO: できればFormTypeで行いたい
public static function loadValidatorMetadata(ClassMetadata $metadata)
{
$metadata->addConstraint(new UniqueEntity([
'fields' => 'email',
'message' => 'form_error.customer_already_exists',
'repositoryMethod' => 'getNonWithdrawingCustomers',
]));
}

/**
* Get id.
*
Expand Down
28 changes: 1 addition & 27 deletions src/Eccube/Form/Type/Admin/CustomerType.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
use Eccube\Form\Type\PostalType;
use Eccube\Form\Type\RepeatedPasswordType;
use Eccube\Form\Validator\Email;
use Eccube\Repository\CustomerRepository;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\BirthdayType;
use Symfony\Component\Form\Extension\Core\Type\EmailType;
Expand All @@ -46,21 +45,14 @@ class CustomerType extends AbstractType
*/
protected $eccubeConfig;

/**
* @var CustomerRepository
*/
protected $customerRepository;

/**
* CustomerType constructor.
*
* @param EccubeConfig $eccubeConfig
* @param CustomerRepository $customerRepository
*/
public function __construct(EccubeConfig $eccubeConfig, CustomerRepository $customerRepository)
public function __construct(EccubeConfig $eccubeConfig)
{
$this->eccubeConfig = $eccubeConfig;
$this->customerRepository = $customerRepository;
}

/**
Expand Down Expand Up @@ -158,24 +150,6 @@ public function buildForm(FormBuilderInterface $builder, array $options)
],
]);

$builder->addEventListener(FormEvents::POST_SUBMIT, function (FormEvent $event) {
$form = $event->getForm();
/** @var Customer $Customer */
$Customer = $event->getData();
$qb = $this->customerRepository->createQueryBuilder('c');
$qb->select('count(c.id)')
->where('c.email = :email')
->setParameter('email', $Customer->getEmail());
if ($Customer->getId()) {
$qb->andWhere('c.id <> :id')
->setParameter('id', $Customer->getId());
}
$count = $qb->getQuery()->getSingleScalarResult();
if ($count > 0) {
$form['email']->addError(new FormError(trans('form_error.customer_already_exists', [], 'validators')));
}
});

$builder->addEventListener(FormEvents::POST_SUBMIT, function (FormEvent $event) {
$form = $event->getForm();
/** @var Customer $Customer */
Expand Down
2 changes: 1 addition & 1 deletion src/Eccube/Resource/doctrine/import_csv/ja/dtb_page.csv
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ id,page_name,url,file_name,edit_type,author,description,keyword,create_date,upda
"18","会員登録(入力ページ)","entry","Entry/index","2",,,,"2017-03-07 10:14:52","2017-03-07 10:14:52",,,"page",
"20","会員登録(完了ページ)","entry_complete","Entry/complete","2",,,,"2017-03-07 10:14:52","2017-03-07 10:14:52","noindex",,"page",
"21","特定商取引に関する法律に基づく表記","help_tradelaw","Help/tradelaw","2",,,,"2017-03-07 10:14:52","2017-03-07 10:14:52",,,"page",
"22","本会員登録(完了ページ)","entry_activate_complete","Entry/activate","2",,,,"2017-03-07 10:14:52","2017-03-07 10:14:52","noindex",,"page",
"22","本会員登録(完了ページ)","entry_activate","Entry/activate","2",,,,"2017-03-07 10:14:52","2017-03-07 10:14:52","noindex",,"page",
"24","商品購入/お届け先の指定","shopping_shipping","Shopping/shipping","2",,,,"2017-03-07 10:14:52","2017-03-07 10:14:52","noindex",,"page",
"28","商品購入/ご注文完了","shopping_complete","Shopping/complete","2",,,,"2017-03-07 10:14:52","2017-03-07 10:14:52","noindex",,"page",
"29","プライバシーポリシー","help_privacy","Help/privacy","2",,,,"2017-03-07 10:14:52","2017-03-07 10:14:52",,,"page",
Expand Down
Loading