Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/2.4-develop' into 2.4
Browse files Browse the repository at this point in the history
# Conflicts:
#	view/frontend/templates/popup/form/authentication/social.phtml
  • Loading branch information
HuyPhuc98 committed Jul 6, 2023
2 parents d145776 + 8fb4e58 commit 27d9ee0
Show file tree
Hide file tree
Showing 20 changed files with 333 additions and 309 deletions.
7 changes: 6 additions & 1 deletion Block/Css.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,12 @@ protected function _prepareLayout()
$this->pageConfig->addPageAsset('Mageplaza_Core::css/magnific-popup.css');
} elseif (in_array(
$this->_request->getFullActionName(),
['customer_account_login', 'customer_account_create', 'customer_account_index']
[
'customer_account_login',
'customer_account_create',
'customer_account_index',
'customer_account_forgotpassword'
]
)
) {
$this->pageConfig->addPageAsset('Mageplaza_SocialLogin::css/style.css');
Expand Down
8 changes: 6 additions & 2 deletions Block/Popup.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ public function __construct(
*/
public function isEnabled()
{
if (str_contains($this->_request->getFullActionName(), 'customer_account')) {
return false;
}

if ($this->helperData->isEnabled() && !$this->customerSession->isLoggedIn() && $this->helperData->getPopupLogin()) {
return $this->helperData->getPopupLogin();
}
Expand Down Expand Up @@ -165,7 +169,7 @@ public function getCreateFormUrl()
*/
public function isSecure()
{
return (bool)$this->helperData->isSecure();
return (bool) $this->helperData->isSecure();
}

/**
Expand All @@ -189,6 +193,6 @@ public function isRequireMoreInfo()
*/
public function isCheckMode()
{
return (bool)$this->helperData->isCheckMode();
return (bool) $this->helperData->isCheckMode();
}
}
19 changes: 15 additions & 4 deletions Block/Popup/Social.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,23 @@ public function getSocialButtonsConfig()
public function canShow($position = null)
{
$displayConfig = $this->socialHelper->getConfigGeneral('social_display');
$displayConfig = explode(',', $displayConfig);
$displayConfig = explode(',', $displayConfig ?? '');

if (!$position) {
$position = $this->getRequest()->getFullActionName() === 'customer_account_login' ?
Position::PAGE_LOGIN :
Position::PAGE_CREATE;
$controllerName = $this->getRequest()->getFullActionName();
switch ($controllerName) {
case 'customer_account_login':
$position = Position::PAGE_LOGIN;
break;
case 'customer_account_forgotpassword':
$position = Position::PAGE_FORGOT_PASS;
break;
case 'customer_account_create':
$position = Position::PAGE_CREATE;
break;
default:
return false;
}
}

return in_array($position, $displayConfig);
Expand Down
102 changes: 93 additions & 9 deletions Controller/Popup/Create.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,34 @@
use Exception;
use Magento\Captcha\Helper\Data as CaptchaData;
use Magento\Customer\Api\AccountManagementInterface;
use Magento\Customer\Api\CustomerRepositoryInterface as CustomerRepository;
use Magento\Customer\Api\Data\AddressInterfaceFactory;
use Magento\Customer\Api\Data\CustomerInterfaceFactory;
use Magento\Customer\Api\Data\RegionInterfaceFactory;
use Magento\Customer\Controller\Account\CreatePost;
use Magento\Customer\Helper\Address;
use Magento\Customer\Model\Account\Redirect as AccountRedirect;
use Magento\Customer\Model\CustomerExtractor;
use Magento\Customer\Model\Metadata\FormFactory;
use Magento\Customer\Model\Registration;
use Magento\Customer\Model\Session;
use Magento\Customer\Model\Url as CustomerUrl;
use Magento\Framework\Api\DataObjectHelper;
use Magento\Framework\App\Action\Context;
use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Framework\App\ObjectManager;
use Magento\Framework\Controller\Result\Json;
use Magento\Framework\Controller\Result\JsonFactory;
use Magento\Framework\Data\Form\FormKey\Validator;
use Magento\Framework\DataObject;
use Magento\Framework\Escaper;
use Magento\Framework\Exception\InputException;
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\Exception\StateException;
use Magento\Framework\Stdlib\Cookie\CookieMetadataFactory;
use Magento\Framework\Stdlib\Cookie\PhpCookieManager;
use Magento\Framework\UrlFactory;
use Magento\Newsletter\Model\SubscriberFactory;
use Magento\Store\Model\StoreManagerInterface;
use Mageplaza\SocialLogin\Helper\Data;

/**
Expand Down Expand Up @@ -69,14 +87,83 @@ class Create extends CreatePost
private $cookieMetadataFactory;

/**
* @return JsonFactory|mixed
* Create constructor.
*
* @param Context $context
* @param Session $customerSession
* @param ScopeConfigInterface $scopeConfig
* @param StoreManagerInterface $storeManager
* @param AccountManagementInterface $accountManagement
* @param Address $addressHelper
* @param UrlFactory $urlFactory
* @param FormFactory $formFactory
* @param SubscriberFactory $subscriberFactory
* @param RegionInterfaceFactory $regionDataFactory
* @param AddressInterfaceFactory $addressDataFactory
* @param CustomerInterfaceFactory $customerDataFactory
* @param CustomerUrl $customerUrl
* @param Registration $registration
* @param Escaper $escaper
* @param CustomerExtractor $customerExtractor
* @param DataObjectHelper $dataObjectHelper
* @param AccountRedirect $accountRedirect
* @param CustomerRepository $customerRepository
* @param JsonFactory $jsonFactory
* @param Validator|null $formKeyValidator
*/
public function __construct(
Context $context,
Session $customerSession,
ScopeConfigInterface $scopeConfig,
StoreManagerInterface $storeManager,
AccountManagementInterface $accountManagement,
Address $addressHelper,
UrlFactory $urlFactory,
FormFactory $formFactory,
SubscriberFactory $subscriberFactory,
RegionInterfaceFactory $regionDataFactory,
AddressInterfaceFactory $addressDataFactory,
CustomerInterfaceFactory $customerDataFactory,
CustomerUrl $customerUrl,
Registration $registration,
Escaper $escaper,
CustomerExtractor $customerExtractor,
DataObjectHelper $dataObjectHelper,
AccountRedirect $accountRedirect,
CustomerRepository $customerRepository,
JsonFactory $jsonFactory,
Validator $formKeyValidator = null
) {
parent::__construct(
$context,
$customerSession,
$scopeConfig,
$storeManager,
$accountManagement,
$addressHelper,
$urlFactory,
$formFactory,
$subscriberFactory,
$regionDataFactory,
$addressDataFactory,
$customerDataFactory,
$customerUrl,
$registration,
$escaper,
$customerExtractor,
$dataObjectHelper,
$accountRedirect,
$customerRepository,
$formKeyValidator
);
$this->resultJsonFactory = $jsonFactory;
}

/**
* @return JsonFactory
*/
protected function getJsonFactory()
{
if (!$this->resultJsonFactory) {
$this->resultJsonFactory = ObjectManager::getInstance()->get(JsonFactory::class);
}

return $this->resultJsonFactory;
}

Expand Down Expand Up @@ -125,9 +212,6 @@ public function checkCaptcha()
*/
public function execute()
{
/**
* @var Json $resultJson
*/
$resultJson = $this->getJsonFactory()->create();
$result = [
'success' => false,
Expand Down
17 changes: 7 additions & 10 deletions Controller/Popup/Forgot.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@
use Magento\Framework\Escaper;
use Magento\Framework\Exception\NoSuchEntityException;
use Magento\Framework\Exception\SecurityViolationException;
use Magento\Framework\Validator\ValidateException;
use Magento\Framework\Validator\ValidatorChain;
use Mageplaza\SocialLogin\Helper\Data;
use Zend_Validate;
use Zend_Validate_Exception;

/**
* Class Forgot
Expand Down Expand Up @@ -118,22 +118,19 @@ public function checkCaptcha()
}

/**
* @return $this|ResponseInterface|ResultInterface
* @throws Zend_Validate_Exception
* @return ResponseInterface|Json|ResultInterface
* @throws ValidateException
*/
public function execute()
{
/**
* @var Json $resultJson
*/
$resultJson = $this->resultJsonFactory->create();

$result = [
'success' => false,
'message' => []
];

if (!$this->checkCaptcha()) {
if (!$this->socialHelper->isEnabledGGRecaptcha() && !$this->checkCaptcha()) {
$result['message'] = __('Incorrect CAPTCHA.');

return $resultJson->setData($result);
Expand All @@ -142,10 +139,10 @@ public function execute()
/**
* @var Redirect $resultRedirect
*/
$email = (string)$this->getRequest()->getPost('email');
$email = (string) $this->getRequest()->getPost('email');

if ($email) {
if (!Zend_Validate::is($email, 'EmailAddress')) {
if (!ValidatorChain::is($email, 'EmailAddress')) {
$this->session->setForgottenEmail($email);
$result['message'][] = __('Please correct the email address.');
}
Expand Down
2 changes: 1 addition & 1 deletion Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ public function getPopupLogin($storeId = null)
/**
* @param null $storeId
*
* @return mixed
* @return bool
*/
public function isCheckMode($storeId = null)
{
Expand Down
11 changes: 7 additions & 4 deletions Model/System/Config/Source/Position.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,12 @@
*/
class Position implements ArrayInterface
{
const PAGE_LOGIN = 1;
const PAGE_CREATE = 2;
const PAGE_POPUP = 3;
const PAGE_AUTHEN = 4;
const PAGE_LOGIN = 1;
const PAGE_CREATE = 2;
const PAGE_POPUP = 3;
const PAGE_AUTHEN = 4;
const PAGE_FORGOT_PASS = 5;


/**
* Options getter
Expand All @@ -46,6 +48,7 @@ public function toOptionArray()
['value' => '', 'label' => __('-- Please Select --')],
['value' => self::PAGE_LOGIN, 'label' => __('Customer Login Page')],
['value' => self::PAGE_CREATE, 'label' => __('Customer Create Page')],
['value' => self::PAGE_FORGOT_PASS, 'label' => __('Forgot Your Password Page')],
['value' => self::PAGE_POPUP, 'label' => __('Social Login Popup')],
['value' => self::PAGE_AUTHEN, 'label' => __('Customer Authentication Popup')]
];
Expand Down
92 changes: 0 additions & 92 deletions Setup/InstallSchema.php

This file was deleted.

Loading

0 comments on commit 27d9ee0

Please sign in to comment.