-
-
Notifications
You must be signed in to change notification settings - Fork 157
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1291 from solverat/login_type
Implement Username/Email Login Identifier
- Loading branch information
Showing
28 changed files
with
452 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Within 2.2 | ||
|
||
## 2.2.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# CoreShop Customer Registration Types | ||
By default, a customer needs to provide a unique and valid email address to pass a registration. | ||
|
||
## Register By Email | ||
> This is the default setting! | ||
To switch to registration by a unique and valid email address, you need set the identifier: | ||
|
||
```yaml | ||
core_shop_customer: | ||
login_identifier: 'email' | ||
``` | ||
## Register By Username | ||
First, you need to make sure your customer object provides a `username` field. | ||
By default, coreshop **does not** install this field to prevent unnecessary confusion. | ||
To implement the username field, just open your class editor and add a text field called `username` and you're good to go! | ||
|
||
To switch to registration by a unique username, you need change the identifier: | ||
|
||
```yaml | ||
core_shop_customer: | ||
login_identifier: 'username' | ||
``` | ||
|
||
## Security | ||
|
||
### Form (Frontend) | ||
CoreShop comes with a preinstalled constraint which will tell your customer, if an email address or username - depending on your settings - is valid or not. | ||
|
||
### Backend / API | ||
Plus, if you're going to update a customer by API or Backend, coreshop also checks if your customer entity has unique data. | ||
|
||
> Note: Both checks only apply to non-guest entities! | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# CoreShop Customer Company Extension | ||
The Company Entity allows you to append customers to a given company. | ||
After a customer has been connected to a company by using the 1to1 relation `company`, it's possible to share addresses between company and the self-assigned addresses. | ||
|
||
## Access Types | ||
> Note! This is only available if a customer already is connected to a valid company! | ||
### Own Only | ||
If set, the customer can create, edit and delete own addresses and choose them in checkout as well. This is the default behaviour. | ||
|
||
### Company Only | ||
If set, the customer can create, edit und delete company addresses and choose them in checkout as well. He's not able to add addresses to himself. | ||
|
||
### Own And Company | ||
If set, the customer can create, edit and delete company and private addresses and choose them in checkout as well. | ||
|
||
Plus, the `own_and_company` mode allows the customer to define and modify the allocation of the address. | ||
To do so, coreshop renders an additional choice type to the address creation/modification form. | ||
|
||
**Note**: If a customer switches the allocation after it has been created, the address also physically gets moved to its desired location. | ||
In this example, the customer changes the allocation from `own` to `company`: | ||
|
||
Before: | ||
```yaml | ||
- company A | ||
- addresses | ||
- customer A | ||
- addresses | ||
- address A | ||
``` | ||
After: | ||
```yaml | ||
- company A | ||
- addresses | ||
- address A | ||
- customer A | ||
- addresses | ||
``` | ||
Read more about this feature [here](https://github.com/coreshop/CoreShop/issues/1266). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
# CoreShop Customer | ||
|
||
This guide should lead you through how CoreShop handles Customer Information. | ||
|
||
1. [Create, Read, Update, Delete](./01_CRUD.md) | ||
2. [Customer Context](./02_Context.md) | ||
3. [Registration Service](./03_Registration_Service.md) | ||
3. [Registration Service](./03_Registration_Service.md) | ||
3. [Registration Types](./04_Registration_Types.md) | ||
4. [Company Extension](./05_Company_Extension.md) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 85 additions & 0 deletions
85
src/CoreShop/Bundle/CoreBundle/EventListener/CustomerSecurityValidationListener.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
<?php | ||
/** | ||
* CoreShop. | ||
* | ||
* This source file is subject to the GNU General Public License version 3 (GPLv3) | ||
* For the full copyright and license information, please view the LICENSE.md and gpl-3.0.txt | ||
* files that are distributed with this source code. | ||
* | ||
* @copyright Copyright (c) 2015-2020 Kamil Wręczycki | ||
* @license https://www.coreshop.org/license GNU General Public License version 3 (GPLv3) | ||
*/ | ||
|
||
namespace CoreShop\Bundle\CoreBundle\EventListener; | ||
|
||
use CoreShop\Bundle\CoreBundle\Customer\CustomerLoginServiceInterface; | ||
use CoreShop\Component\Core\Model\CustomerInterface; | ||
use CoreShop\Component\Customer\Repository\CustomerRepositoryInterface; | ||
use Pimcore\Event\Model\DataObjectEvent; | ||
use Pimcore\Model\Element\ValidationException; | ||
|
||
final class CustomerSecurityValidationListener | ||
{ | ||
/** | ||
* @var CustomerRepositoryInterface | ||
*/ | ||
protected $customerRepository; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
protected $className; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
protected $loginIdentifier; | ||
|
||
/** | ||
* @param CustomerRepositoryInterface $customerRepository | ||
* @param string $className | ||
* @param string $loginIdentifier | ||
*/ | ||
public function __construct( | ||
CustomerRepositoryInterface $customerRepository, | ||
$className, | ||
$loginIdentifier | ||
) { | ||
$this->customerRepository = $customerRepository; | ||
$this->className = $className; | ||
$this->loginIdentifier = $loginIdentifier; | ||
} | ||
|
||
/** | ||
* @param DataObjectEvent $event | ||
* | ||
* @throws ValidationException | ||
*/ | ||
public function checkCustomerSecurityDataBeforeUpdate(DataObjectEvent $event) | ||
{ | ||
$object = $event->getObject(); | ||
|
||
if (!$object instanceof CustomerInterface) { | ||
return; | ||
} | ||
|
||
if ($object->getIsGuest() === true) { | ||
return; | ||
} | ||
|
||
$identifierValue = $this->loginIdentifier === 'email' ? $object->getEmail() : $object->getUsername(); | ||
|
||
$listing = $this->customerRepository->getList(); | ||
$listing->setUnpublished(true); | ||
$listing->addConditionParam(sprintf('%s = ?', $this->loginIdentifier), $identifierValue); | ||
$listing->addConditionParam('o_id != ?', $object->getId()); | ||
|
||
$objects = $listing->getObjects(); | ||
|
||
if (count($objects) === 0) { | ||
return; | ||
} | ||
|
||
throw new ValidationException(sprintf('%s "%s" is already used. Please use another one.', ucfirst($this->loginIdentifier), $identifierValue)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.