From d8adae821a30c9baee8ce1c27f8322d8db542805 Mon Sep 17 00:00:00 2001 From: michalmarcinkowski Date: Sun, 3 May 2015 00:49:54 +0200 Subject: [PATCH] Removed FOSUserBundle and all its dependencies --- .../FOSUserBundle/serializer/Model.User.yml | 17 -- .../translations/FOSUserBundle.en.yml | 20 --- .../translations/FOSUserBundle.fr.yml | 33 ---- .../ChangePassword/changePassword.html.twig | 5 - .../views/Profile/edit.html.twig | 5 - .../views/Profile/show.html.twig | 5 - .../views/Registration/confirmed.html.twig | 14 -- .../views/Registration/register.html.twig | 23 --- .../views/Resetting/checkEmail.html.twig | 9 -- .../views/Resetting/email.txt.twig | 12 -- .../passwordAlreadyRequested.html.twig | 9 -- .../views/Resetting/request.html.twig | 10 -- .../views/Resetting/request_content.html.twig | 22 --- .../views/Resetting/reset.html.twig | 10 -- .../views/Resetting/reset_content.html.twig | 14 -- .../views/Security/login.html.twig | 59 ------- composer.json | 1 - composer.lock | 76 +-------- features/backend/orders.feature | 2 +- features/frontend/checkout_addressing.feature | 4 +- features/frontend/checkout_finalize.feature | 4 +- features/frontend/checkout_security.feature | 42 +++-- features/pricing/group_based_pricing.feature | 16 +- features/user/user_login.feature | 8 +- features/user/user_registration.feature | 33 ++-- .../PasswordResettingRequestController.php | 1 + .../SyliusApiExtension.php | 2 +- .../Bundle/CoreBundle/Behat/CoreContext.php | 2 +- .../Checkout/Step/AddressingStep.php | 11 +- .../CoreBundle/Checkout/Step/FinalizeStep.php | 4 +- .../CoreBundle/Checkout/Step/SecurityStep.php | 127 +++++++++------ .../CoreBundle/Controller/OrderController.php | 16 +- .../CheckoutAddressingListener.php | 3 +- .../EventListener/MailerListener.php | 7 +- .../Form/Type/Checkout/AddressingStepType.php | 2 +- .../Form/Type/Checkout/GuestType.php | 5 +- .../Bundle/CoreBundle/Form/Type/UserType.php | 37 +++++ .../Bundle/CoreBundle/Kernel/Kernel.php | 1 - .../CoreBundle/Resources/config/app/main.yml | 20 +-- .../Resources/config/app/sylius.yml | 2 + .../config/doctrine/model/Order.orm.xml | 3 + .../CoreBundle/Resources/config/form.xml | 4 +- .../CoreBundle/Resources/config/mailer.xml | 4 +- .../spec/Form/Type/UserTypeSpec.php | 53 ++++++ .../Controller/ResourceController.php | 1 - .../Controller/CustomerController.php | 13 +- .../SyliusUserExtension.php | 9 -- .../Doctrine/ORM/CustomerRepository.php | 49 ++++++ .../Doctrine/ORM/UserRepository.php | 17 +- .../EventListener/CanonicalizerListener.php | 10 +- .../EventListener/DefaultUsernameListener.php | 53 ++++++ .../CanonicalizerFormListener.php | 47 ------ .../UserRegistrationFormListener.php | 40 +++++ .../Form/Type/UserRegistrationType.php | 29 ++-- .../Bundle/UserBundle/Form/Type/UserType.php | 33 ++-- .../Resources/config/driver/doctrine/orm.xml | 1 + .../UserBundle/Resources/config/services.xml | 6 +- .../Resources/config/validation.xml | 60 ++++--- .../Resources/translations/validators.en.yml | 3 +- .../Bundle/UserBundle/Security/UserLogin.php | 4 +- .../Security/UserLoginInterface.php | 2 + .../CanonicalizerListenerSpec.php | 57 ++++--- .../CanonicalizerFormListenerSpec.php | 62 ------- .../Form/Type/UserRegistrationTypeSpec.php | 2 +- .../spec/Form/Type/UserTypeSpec.php | 1 - .../spec/Security/UserLoginSpec.php | 7 +- .../Bundle/WebBundle/Behat/WebContext.php | 2 +- .../Controller/Backend/FormController.php | 2 +- .../Frontend/Account/ProfileController.php | 152 ------------------ .../config/routing/backend/order.yml | 6 +- .../Resources/translations/messages.en.yml | 2 +- ...er.html.twig => indexByCustomer.html.twig} | 4 +- .../views/Backend/Order/macros.html.twig | 13 +- .../views/Backend/User/show.html.twig | 28 ++-- .../Frontend/Account/Profile/edit.html.twig | 2 +- src/Sylius/Component/Core/Model/User.php | 7 +- src/Sylius/Component/User/Model/User.php | 16 +- .../Component/User/Model/UserInterface.php | 1 + 78 files changed, 619 insertions(+), 879 deletions(-) delete mode 100644 app/Resources/FOSUserBundle/serializer/Model.User.yml delete mode 100644 app/Resources/FOSUserBundle/translations/FOSUserBundle.en.yml delete mode 100644 app/Resources/FOSUserBundle/translations/FOSUserBundle.fr.yml delete mode 100644 app/Resources/FOSUserBundle/views/ChangePassword/changePassword.html.twig delete mode 100644 app/Resources/FOSUserBundle/views/Profile/edit.html.twig delete mode 100644 app/Resources/FOSUserBundle/views/Profile/show.html.twig delete mode 100644 app/Resources/FOSUserBundle/views/Registration/confirmed.html.twig delete mode 100644 app/Resources/FOSUserBundle/views/Registration/register.html.twig delete mode 100644 app/Resources/FOSUserBundle/views/Resetting/checkEmail.html.twig delete mode 100644 app/Resources/FOSUserBundle/views/Resetting/email.txt.twig delete mode 100644 app/Resources/FOSUserBundle/views/Resetting/passwordAlreadyRequested.html.twig delete mode 100644 app/Resources/FOSUserBundle/views/Resetting/request.html.twig delete mode 100644 app/Resources/FOSUserBundle/views/Resetting/request_content.html.twig delete mode 100644 app/Resources/FOSUserBundle/views/Resetting/reset.html.twig delete mode 100644 app/Resources/FOSUserBundle/views/Resetting/reset_content.html.twig delete mode 100644 app/Resources/FOSUserBundle/views/Security/login.html.twig create mode 100644 src/Sylius/Bundle/CoreBundle/Form/Type/UserType.php create mode 100644 src/Sylius/Bundle/CoreBundle/spec/Form/Type/UserTypeSpec.php create mode 100644 src/Sylius/Bundle/UserBundle/Doctrine/ORM/CustomerRepository.php create mode 100644 src/Sylius/Bundle/UserBundle/EventListener/DefaultUsernameListener.php delete mode 100644 src/Sylius/Bundle/UserBundle/Form/EventListener/CanonicalizerFormListener.php create mode 100644 src/Sylius/Bundle/UserBundle/Form/EventListener/UserRegistrationFormListener.php delete mode 100644 src/Sylius/Bundle/UserBundle/spec/Form/EventListener/CanonicalizerFormListenerSpec.php delete mode 100644 src/Sylius/Bundle/WebBundle/Controller/Frontend/Account/ProfileController.php rename src/Sylius/Bundle/WebBundle/Resources/views/Backend/Order/{indexByUser.html.twig => indexByCustomer.html.twig} (73%) diff --git a/app/Resources/FOSUserBundle/serializer/Model.User.yml b/app/Resources/FOSUserBundle/serializer/Model.User.yml deleted file mode 100644 index 7f75421764..0000000000 --- a/app/Resources/FOSUserBundle/serializer/Model.User.yml +++ /dev/null @@ -1,17 +0,0 @@ -FOS\UserBundle\Model\User: - exclusion_policy: ALL - properties: - id: - expose: true - email: - expose: true - type: string - username: - expose: true - type: string - firstName: - expose: true - type: string - lastName: - expose: true - type: string diff --git a/app/Resources/FOSUserBundle/translations/FOSUserBundle.en.yml b/app/Resources/FOSUserBundle/translations/FOSUserBundle.en.yml deleted file mode 100644 index db271d51d4..0000000000 --- a/app/Resources/FOSUserBundle/translations/FOSUserBundle.en.yml +++ /dev/null @@ -1,20 +0,0 @@ -# Security -security: - login: - email: "Email:" - header:

Login Sylius store

- info: Please login using "sylius@example.com" email and "sylius" as password. - forgot_password: Forgot password? - no_account: No account yet? - -# Registration -registration: - register_header:

Registration Create an account in store

- confirmed_header:

Welcome Your registration was successful

- -# Password resetting -resetting: - request: - header:

Password reset request

- reset: - header:

Reset password

diff --git a/app/Resources/FOSUserBundle/translations/FOSUserBundle.fr.yml b/app/Resources/FOSUserBundle/translations/FOSUserBundle.fr.yml deleted file mode 100644 index 9c6b9a866a..0000000000 --- a/app/Resources/FOSUserBundle/translations/FOSUserBundle.fr.yml +++ /dev/null @@ -1,33 +0,0 @@ -# Security -security: - login: - email: "Email" - header:

Connexion Boutique LVP

- info: Connectez vous en utilisant l'email "sylius@example.com" et "sylius" comme mot de passe. - forgot_password: Mot de passe oublié ? - no_account: Pas encore de compte ? - username: "Nom d'utilisateur" - password: "Mot de passe" - -# Registration -registration: - register_header:

Enregistrement Créer votre compte

- confirmed_header:

Bienvenue Votre compte a été créé avec succès

- -# Form field labels -form: - group_name: "Nom du groupe" - username: "Nom d'utilisateur" - email: "Adresse e-mail" - current_password: "Mot de passe actuel" - password: "Mot de passe" - password_confirmation: "Vérification" - new_password: "Nouveau mot de passe" - new_password_confirmation: "Vérification" - -# Password resetting -resetting: - request: - header:

Demande de réinitialisation de mot de passe

- reset: - header:

Réinitialiser votre mot de passe

diff --git a/app/Resources/FOSUserBundle/views/ChangePassword/changePassword.html.twig b/app/Resources/FOSUserBundle/views/ChangePassword/changePassword.html.twig deleted file mode 100644 index 4d0e02f836..0000000000 --- a/app/Resources/FOSUserBundle/views/ChangePassword/changePassword.html.twig +++ /dev/null @@ -1,5 +0,0 @@ -{% extends 'SyliusWebBundle:Frontend/Account:layout.html.twig' %} - -{% block content %} - {% include "SyliusWebBundle:Frontend/Account:_password.html.twig" %} -{% endblock %} diff --git a/app/Resources/FOSUserBundle/views/Profile/edit.html.twig b/app/Resources/FOSUserBundle/views/Profile/edit.html.twig deleted file mode 100644 index 5efa0d0516..0000000000 --- a/app/Resources/FOSUserBundle/views/Profile/edit.html.twig +++ /dev/null @@ -1,5 +0,0 @@ -{% extends 'SyliusWebBundle:Frontend/Account:layout.html.twig' %} - -{% block content %} - {% include "SyliusWebBundle:Frontend/Account:_profileEdit.html.twig" %} -{% endblock %} diff --git a/app/Resources/FOSUserBundle/views/Profile/show.html.twig b/app/Resources/FOSUserBundle/views/Profile/show.html.twig deleted file mode 100644 index 0fe1c59cec..0000000000 --- a/app/Resources/FOSUserBundle/views/Profile/show.html.twig +++ /dev/null @@ -1,5 +0,0 @@ -{% extends 'SyliusWebBundle:Frontend/Account:layout.html.twig' %} - -{% block content %} - {% include "SyliusWebBundle:Frontend/Account:_profile.html.twig" %} -{% endblock %} diff --git a/app/Resources/FOSUserBundle/views/Registration/confirmed.html.twig b/app/Resources/FOSUserBundle/views/Registration/confirmed.html.twig deleted file mode 100644 index 3710ded135..0000000000 --- a/app/Resources/FOSUserBundle/views/Registration/confirmed.html.twig +++ /dev/null @@ -1,14 +0,0 @@ -{% extends 'SyliusWebBundle:Frontend:layout.html.twig' %} - -{% trans_default_domain 'FOSUserBundle' %} - -{% block content %} - - -
-
- {{ 'registration.confirmed'|trans({'%username%': user.firstName}) }} -
-{% endblock %} diff --git a/app/Resources/FOSUserBundle/views/Registration/register.html.twig b/app/Resources/FOSUserBundle/views/Registration/register.html.twig deleted file mode 100644 index 7dca59cafe..0000000000 --- a/app/Resources/FOSUserBundle/views/Registration/register.html.twig +++ /dev/null @@ -1,23 +0,0 @@ -{% extends 'SyliusWebBundle:Frontend:layout.html.twig' %} - -{% trans_default_domain 'FOSUserBundle' %} - -{% block content %} - - -
-
- {% for field in form %} - {{ form_row(field) }} - {% endfor %} -
-
-
- {{ render(url('hwi_oauth_connect')) }} -
- -
-
-{% endblock %} diff --git a/app/Resources/FOSUserBundle/views/Resetting/checkEmail.html.twig b/app/Resources/FOSUserBundle/views/Resetting/checkEmail.html.twig deleted file mode 100644 index 9051cbb969..0000000000 --- a/app/Resources/FOSUserBundle/views/Resetting/checkEmail.html.twig +++ /dev/null @@ -1,9 +0,0 @@ -{% extends 'SyliusWebBundle:Frontend:layout.html.twig' %} - -{% trans_default_domain 'FOSUserBundle' %} - -{% block content %} -
- {{ 'resetting.check_email'|trans({'%email%': email}) }} -
-{% endblock %} diff --git a/app/Resources/FOSUserBundle/views/Resetting/email.txt.twig b/app/Resources/FOSUserBundle/views/Resetting/email.txt.twig deleted file mode 100644 index 409aeeb2c5..0000000000 --- a/app/Resources/FOSUserBundle/views/Resetting/email.txt.twig +++ /dev/null @@ -1,12 +0,0 @@ -{% trans_default_domain 'FOSUserBundle' %} -{% block subject %} -{% autoescape false %} -{{ 'resetting.email.subject'|trans({'%username%': user.username, '%confirmationUrl%': confirmationUrl}) }} -{% endautoescape %} -{% endblock %} -{% block body_text %} -{% autoescape false %} -{{ 'resetting.email.message'|trans({'%username%': user.username, '%confirmationUrl%': confirmationUrl}) }} -{% endautoescape %} -{% endblock %} -{% block body_html %}{% endblock %} diff --git a/app/Resources/FOSUserBundle/views/Resetting/passwordAlreadyRequested.html.twig b/app/Resources/FOSUserBundle/views/Resetting/passwordAlreadyRequested.html.twig deleted file mode 100644 index 9a5619fc0a..0000000000 --- a/app/Resources/FOSUserBundle/views/Resetting/passwordAlreadyRequested.html.twig +++ /dev/null @@ -1,9 +0,0 @@ -{% extends 'SyliusWebBundle:Frontend:layout.html.twig' %} - -{% trans_default_domain 'FOSUserBundle' %} - -{% block content %} -
- {{ 'resetting.password_already_requested'|trans }} -
-{% endblock %} diff --git a/app/Resources/FOSUserBundle/views/Resetting/request.html.twig b/app/Resources/FOSUserBundle/views/Resetting/request.html.twig deleted file mode 100644 index 1850b9d6f7..0000000000 --- a/app/Resources/FOSUserBundle/views/Resetting/request.html.twig +++ /dev/null @@ -1,10 +0,0 @@ -{% extends 'SyliusWebBundle:Frontend:layout.html.twig' %} - -{% trans_default_domain 'FOSUserBundle' %} - -{% block content %} - - {% include "FOSUserBundle:Resetting:request_content.html.twig" %} -{% endblock content %} diff --git a/app/Resources/FOSUserBundle/views/Resetting/request_content.html.twig b/app/Resources/FOSUserBundle/views/Resetting/request_content.html.twig deleted file mode 100644 index 0e51f02675..0000000000 --- a/app/Resources/FOSUserBundle/views/Resetting/request_content.html.twig +++ /dev/null @@ -1,22 +0,0 @@ -{% trans_default_domain 'FOSUserBundle' %} - -{% if invalid_username is defined %} -
- {{ 'resetting.request.invalid_username'|trans({'%username%': invalid_username}) }} -
-{% endif %} - -
-
-
- -
- -
-
-
-
- -
- -
diff --git a/app/Resources/FOSUserBundle/views/Resetting/reset.html.twig b/app/Resources/FOSUserBundle/views/Resetting/reset.html.twig deleted file mode 100644 index 33974883ec..0000000000 --- a/app/Resources/FOSUserBundle/views/Resetting/reset.html.twig +++ /dev/null @@ -1,10 +0,0 @@ -{% extends 'SyliusWebBundle:Frontend:layout.html.twig' %} - -{% trans_default_domain 'FOSUserBundle' %} - -{% block content %} - - {% include "FOSUserBundle:Resetting:reset_content.html.twig" %} -{% endblock content %} diff --git a/app/Resources/FOSUserBundle/views/Resetting/reset_content.html.twig b/app/Resources/FOSUserBundle/views/Resetting/reset_content.html.twig deleted file mode 100644 index c47ac6ef33..0000000000 --- a/app/Resources/FOSUserBundle/views/Resetting/reset_content.html.twig +++ /dev/null @@ -1,14 +0,0 @@ -{% trans_default_domain 'FOSUserBundle' %} - -
-
-
-
- {{ form_widget(form) }} -
-
-
-
- -
-
diff --git a/app/Resources/FOSUserBundle/views/Security/login.html.twig b/app/Resources/FOSUserBundle/views/Security/login.html.twig deleted file mode 100644 index 126ad7947a..0000000000 --- a/app/Resources/FOSUserBundle/views/Security/login.html.twig +++ /dev/null @@ -1,59 +0,0 @@ -{% extends 'SyliusWebBundle:Frontend:layout.html.twig' %} - -{% trans_default_domain 'FOSUserBundle' %} - -{% block content %} - - -{% if error %} -
- {{ error.messageKey|trans(error.messageData, 'security') }} -
-{% endif %} - -
-

{{ 'security.login.info'|trans|raw }}

- Mr. Sylius Demo Guide -
- -
-
-
- -
- -
-
-
- -
- -
-
-
-
-
- -
-
-
- -
-
-
- {{ render(url('hwi_oauth_connect')) }} -
- -
-
- -{% endblock %} diff --git a/composer.json b/composer.json index 8bc5296245..a27da6f335 100644 --- a/composer.json +++ b/composer.json @@ -33,7 +33,6 @@ "friendsofsymfony/elastica-bundle": "^3.0.2", "friendsofsymfony/oauth-server-bundle": "~1.4", "friendsofsymfony/rest-bundle": "~1.5", - "friendsofsymfony/user-bundle": "2.0.*@dev", "fzaninotto/faker": "~1.2", "hwi/oauth-bundle": "~0.3", "incenteev/composer-parameter-handler": "~2.0", diff --git a/composer.lock b/composer.lock index f07d1c61f9..3db0040c4d 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "hash": "e7f5ff221576282ffa0d1d2e48e29f5b", + "hash": "09206bca55e7c6a301ba4363d1b46ca4", "packages": [ { "name": "a2lix/translation-form-bundle", @@ -1614,73 +1614,6 @@ ], "time": "2015-02-16 15:26:12" }, - { - "name": "friendsofsymfony/user-bundle", - "version": "dev-master", - "source": { - "type": "git", - "url": "https://github.com/FriendsOfSymfony/FOSUserBundle.git", - "reference": "f54031a652846cd8e7b12119fe713eae90e24cf9" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/FriendsOfSymfony/FOSUserBundle/zipball/f54031a652846cd8e7b12119fe713eae90e24cf9", - "reference": "f54031a652846cd8e7b12119fe713eae90e24cf9", - "shasum": "" - }, - "require": { - "php": ">=5.3.2", - "symfony/form": "~2.3", - "symfony/framework-bundle": "~2.3", - "symfony/security-bundle": "~2.3", - "symfony/twig-bundle": "~2.3" - }, - "require-dev": { - "doctrine/doctrine-bundle": "~1.3", - "swiftmailer/swiftmailer": "~4.3|~5", - "symfony/validator": "~2.3", - "symfony/yaml": "~2.3", - "willdurand/propel-typehintable-behavior": "~1.0" - }, - "suggest": { - "willdurand/propel-typehintable-behavior": "Needed when using the propel implementation" - }, - "type": "symfony-bundle", - "extra": { - "branch-alias": { - "dev-master": "2.0.x-dev" - } - }, - "autoload": { - "psr-4": { - "FOS\\UserBundle\\": "" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Christophe Coevoet", - "email": "stof@notk.org" - }, - { - "name": "FriendsOfSymfony Community", - "homepage": "https://github.com/friendsofsymfony/FOSUserBundle/contributors" - }, - { - "name": "Thibault Duplessis", - "email": "thibault.duplessis@gmail.com" - } - ], - "description": "Symfony FOSUserBundle", - "homepage": "http://friendsofsymfony.github.com", - "keywords": [ - "User management" - ], - "time": "2015-01-20 09:35:03" - }, { "name": "fzaninotto/faker", "version": "v1.4.0", @@ -2972,7 +2905,7 @@ "email": "stof@notk.org" }, { - "name": "Knplabs", + "name": "KnpLabs", "homepage": "http://knplabs.com" }, { @@ -9321,13 +9254,12 @@ "aliases": [], "minimum-stability": "stable", "stability-flags": { - "doctrine/migrations": 20, - "friendsofsymfony/user-bundle": 20 + "doctrine/migrations": 20 }, "prefer-stable": false, "prefer-lowest": false, "platform": { - "php": ">=5.3.3" + "php": ">=5.3.9" }, "platform-dev": [] } diff --git a/features/backend/orders.feature b/features/backend/orders.feature index 479d865ef9..fcae5584de 100644 --- a/features/backend/orders.feature +++ b/features/backend/orders.feature @@ -122,5 +122,5 @@ Feature: Orders management Scenario: Sorting order table by appropriate column Given I am on the order index page - When I follow "User" + When I follow "Customer" Then I should see table of orders sorted by lastName \ No newline at end of file diff --git a/features/frontend/checkout_addressing.feature b/features/frontend/checkout_addressing.feature index da46f1c719..9652245c94 100644 --- a/features/frontend/checkout_addressing.feature +++ b/features/frontend/checkout_addressing.feature @@ -15,8 +15,8 @@ Feature: Checkout addressing | PHP Top | 5.99 | PHP T-Shirts | And there are following users: | email | password | enabled | - | john@example.com | foo | yes | - | rick@example.com | bar | yes | + | john@example.com | foo1 | yes | + | rick@example.com | bar1 | yes | And the following zones are defined: | name | type | members | | UK + Germany | country | United Kingdom, Germany | diff --git a/features/frontend/checkout_finalize.feature b/features/frontend/checkout_finalize.feature index 4e00ec7489..7e5d948195 100644 --- a/features/frontend/checkout_finalize.feature +++ b/features/frontend/checkout_finalize.feature @@ -52,7 +52,7 @@ Feature: Checkout finalization And I added product "PHP Top" to cart And I go to the checkout start page When I press "Proceed with your order" - Then I should see "This value should not be blank." + Then I should see "Please enter your email" Scenario: Placing the order as Guest with invalid email address Given I am not logged in @@ -60,7 +60,7 @@ Feature: Checkout finalization And I go to the checkout start page And I fill in "sylius_checkout_guest[email]" with "example" And I press "Proceed with your order" - Then I should see "This value is not a valid email address." + Then I should see "This email is invalid" Scenario: Placing the order as Guest Given I am not logged in diff --git a/features/frontend/checkout_security.feature b/features/frontend/checkout_security.feature index 5131f21a6e..f1571672a0 100644 --- a/features/frontend/checkout_security.feature +++ b/features/frontend/checkout_security.feature @@ -17,8 +17,8 @@ Feature: Checkout security | PHP Top | 5.99 | PHP T-Shirts | And there are following users: | email | password | enabled | - | john@example.com | foo | yes | - | rick@example.com | bar | yes | + | john@example.com | foo1 | yes | + | rick@example.com | bar1 | yes | And the following zones are defined: | name | type | members | | UK | country | United Kingdom | @@ -46,27 +46,27 @@ Feature: Checkout security Scenario: Signing in during the checkout When I fill in the following: | Email | john@example.com | - | Password | foo | + | Password | foo1 | And I press "Login" Then I should be redirected to the checkout addressing step Scenario: Creating account during the checkout When I fill in the following: - | fos_user_registration_form_email | mike@example.com | - | fos_user_registration_form_plainPassword_first | mikepass | - | fos_user_registration_form_plainPassword_second | mikepass | - | fos_user_registration_form_firstName | Mike | - | fos_user_registration_form_lastName | Small | + | sylius_user_registration_customer_firstName | Mike | + | sylius_user_registration_customer_lastName | Small | + | sylius_user_registration_customer_email | mike@example.com | + | sylius_user_registration_plainPassword_first | mikepass | + | sylius_user_registration_plainPassword_second | mikepass | And I press "Register" Then I should be redirected to the checkout addressing step Scenario: Creating account during the whole checkout When I fill in the following: - | fos_user_registration_form_email | mike@example.com | - | fos_user_registration_form_plainPassword_first | mikepass | - | fos_user_registration_form_plainPassword_second | mikepass | - | fos_user_registration_form_firstName | Mike | - | fos_user_registration_form_lastName | Small | + | sylius_user_registration_customer_firstName | Mike | + | sylius_user_registration_customer_lastName | Small | + | sylius_user_registration_customer_email | mike@example.com | + | sylius_user_registration_plainPassword_first | mikepass | + | sylius_user_registration_plainPassword_second | mikepass | And I press "Register" And I fill in the shipping address to United Kingdom And I press "Continue" @@ -80,10 +80,20 @@ Feature: Checkout security Scenario: Creating account without first and last name When I fill in the following: - | fos_user_registration_form_email | mike@example.com | - | fos_user_registration_form_plainPassword_first | mikepass | - | fos_user_registration_form_plainPassword_second | mikepass | + | sylius_user_registration_customer_email | mike@example.com | + | sylius_user_registration_plainPassword_first | mikepass | + | sylius_user_registration_plainPassword_second | mikepass | And I press "Register" Then I should be on the checkout security forward step And I should see "Please enter your first name" And I should see "Please enter your last name" + + Scenario: Creating account without email + When I fill in the following: + | sylius_user_registration_customer_firstName | Mike | + | sylius_user_registration_customer_lastName | Small | + | sylius_user_registration_plainPassword_first | mikepass | + | sylius_user_registration_plainPassword_second | mikepass | + And I press "Register" + Then I should be on the checkout security forward step + And I should see "Please enter your email" diff --git a/features/pricing/group_based_pricing.feature b/features/pricing/group_based_pricing.feature index 84b3503f5f..5fb206cb23 100644 --- a/features/pricing/group_based_pricing.feature +++ b/features/pricing/group_based_pricing.feature @@ -23,13 +23,13 @@ Feature: Group based pricing | Taxable Goods | UK | UK Tax | 15% | And the default tax zone is "UK" And there are following groups: - | name | roles | - | Wholesale Customers | ROLE_WHOLESALE | - | Retail Customers | ROLE_RETAIL | + | name | + | Wholesale Customers | + | Retail Customers | And there are following users: | email | password | enabled | groups | - | beth@example.com | foo | yes | Wholesale Customers | - | martha@example.com | bar | yes | Retail Customers | + | beth@example.com | foo1 | yes | Wholesale Customers | + | martha@example.com | bar1 | yes | Retail Customers | And the following products exist: | name | price | taxons | tax category | | PHP Top | 49.99 | PHP T-Shirts | Taxable Goods | @@ -54,14 +54,14 @@ Feature: Group based pricing But "Grand total: €114.98" should appear on the page Scenario: Wholesale customers have the lower price - Given I log in with "beth@example.com" and "foo" + Given I log in with "beth@example.com" and "foo1" When I add product "PHP Top" to cart, with quantity "4" Then I should be on the cart summary page And "Tax total: €23.69" should appear on the page And "Grand total: €181.65" should appear on the page Scenario: Retail customers get the higher price than wholesalers - Given I log in with "martha@example.com" and "bar" + Given I log in with "martha@example.com" and "bar1" When I add product "PHP Top" to cart, with quantity "3" Then I should be on the cart summary page And "Tax total: €20.70" should appear on the page @@ -72,7 +72,7 @@ Feature: Group based pricing And I go to the checkout start page And I fill in the following: | Email | beth@example.com | - | Password | foo | + | Password | foo1 | And I press "Login" When I go to the cart summary page Then "Tax total: €23.69" should appear on the page diff --git a/features/user/user_login.feature b/features/user/user_login.feature index 3dd1c965fd..b62c8f95c2 100644 --- a/features/user/user_login.feature +++ b/features/user/user_login.feature @@ -7,7 +7,7 @@ Feature: Sign in to the store Background: Given there are following users: | email | password | enabled | - | bar@foo.com | foo | yes | + | bar@foo.com | foo1 | yes | And there is default currency configured And there is default channel configured @@ -16,7 +16,7 @@ Feature: Sign in to the store And I follow "Login" When I fill in the following: | Email | bar@foo.com | - | Password | foo | + | Password | foo1 | And I press "Login" Then I should be on the store homepage And I should see "Logout" @@ -26,7 +26,7 @@ Feature: Sign in to the store And I follow "Login" When I fill in the following: | Email | bar@foo.com | - | Password | bar | + | Password | bar1 | And I press "Login" Then I should be on login page And I should see "Invalid credentials" @@ -43,7 +43,7 @@ Feature: Sign in to the store And I follow "Login" When I fill in the following: | Email | john | - | Password | bar | + | Password | bar1 | And I press "Login" Then I should be on login page And I should see "Invalid credentials" diff --git a/features/user/user_registration.feature b/features/user/user_registration.feature index 59d6e3f0c2..259625bd5c 100644 --- a/features/user/user_registration.feature +++ b/features/user/user_registration.feature @@ -7,7 +7,7 @@ Feature: User registration Background: Given there are following users: | email | password | - | bar@bar.com | foo | + | bar@bar.com | foo1 | And there is default currency configured And there is default channel configured @@ -18,8 +18,8 @@ Feature: User registration | First name | John | | Last name | Doe | | Email | foo@bar.com | - | Password | bar | - | Verification | bar | + | Password | bar1 | + | Verification | bar1 | And I press "Register" Then I should see "Welcome" And I should see "Logout" @@ -31,8 +31,8 @@ Feature: User registration | First name | John | | Last name | Doe | | Email | foo@bar.com | - | Password | bar | - | Verification | foo | + | Password | bar1 | + | Verification | foo2 | And I press "Register" Then I should be on registration page And I should see "The entered passwords don't match" @@ -44,19 +44,32 @@ Feature: User registration | First name | John | | Last name | Doe | | Email | bar@bar.com | - | Password | bar | - | Verification | bar | + | Password | bar1 | + | Verification | bar1 | And I press "Register" Then I should be on registration page - And I should see "The email is already used" + And I should see "This email is already used" + + Scenario: Trying to register with already existing non canonical email + Given I am on the store homepage + And I follow "Register" + When I fill in the following: + | First name | John | + | Last name | Doe | + | Email | BaR@Bar.com | + | Password | bar1 | + | Verification | bar1 | + And I press "Register" + Then I should be on registration page + And I should see "This email is already used" Scenario: Trying to register without first and last name Given I am on the store homepage And I follow "Register" When I fill in the following: | Email | foo@bar.com | - | Password | bar | - | Verification | bar | + | Password | bar1 | + | Verification | bar1 | And I press "Register" Then I should be on registration page And I should see "Please enter your first name" diff --git a/src/Sylius/Bundle/ApiBundle/Controller/PasswordResettingRequestController.php b/src/Sylius/Bundle/ApiBundle/Controller/PasswordResettingRequestController.php index 467ae0cc3d..6de0ad2605 100644 --- a/src/Sylius/Bundle/ApiBundle/Controller/PasswordResettingRequestController.php +++ b/src/Sylius/Bundle/ApiBundle/Controller/PasswordResettingRequestController.php @@ -23,6 +23,7 @@ use Symfony\Component\Security\Core\Exception\AccessDeniedException; /** * API controller for resetting user passwords. + * TODO remove it and use UserController requestPasswordResetAction * * @author Paweł Jędrzejewski */ diff --git a/src/Sylius/Bundle/ApiBundle/DependencyInjection/SyliusApiExtension.php b/src/Sylius/Bundle/ApiBundle/DependencyInjection/SyliusApiExtension.php index dac0cedeb1..f6d038ece4 100644 --- a/src/Sylius/Bundle/ApiBundle/DependencyInjection/SyliusApiExtension.php +++ b/src/Sylius/Bundle/ApiBundle/DependencyInjection/SyliusApiExtension.php @@ -62,7 +62,7 @@ class SyliusApiExtension extends AbstractResourceExtension implements PrependExt 'auth_code_class' => $config['classes']['api_auth_code']['model'], 'service' => array( - 'user_provider' => 'fos_user.user_provider.username' + 'user_provider' => 'sylius.provider.name_or_email_provider' ), )); } diff --git a/src/Sylius/Bundle/CoreBundle/Behat/CoreContext.php b/src/Sylius/Bundle/CoreBundle/Behat/CoreContext.php index fca39ba61e..a63e5a96b3 100644 --- a/src/Sylius/Bundle/CoreBundle/Behat/CoreContext.php +++ b/src/Sylius/Bundle/CoreBundle/Behat/CoreContext.php @@ -249,7 +249,7 @@ class CoreContext extends DefaultContext foreach ($groups as $groupName) { if ($group = $this->findOneByName('group', $groupName)) { - $user->addGroup($group); + $user->getCustomer()->addGroup($group); } } diff --git a/src/Sylius/Bundle/CoreBundle/Checkout/Step/AddressingStep.php b/src/Sylius/Bundle/CoreBundle/Checkout/Step/AddressingStep.php index 13b73654af..aae8b33c34 100644 --- a/src/Sylius/Bundle/CoreBundle/Checkout/Step/AddressingStep.php +++ b/src/Sylius/Bundle/CoreBundle/Checkout/Step/AddressingStep.php @@ -33,8 +33,7 @@ class AddressingStep extends CheckoutStep { $order = $this->getCurrentCart(); $this->dispatchCheckoutEvent(SyliusCheckoutEvents::ADDRESSING_INITIALIZE, $order); - //TODO replace getUser with getCustomer - $form = $this->createCheckoutAddressingForm($order, $this->getUser()); + $form = $this->createCheckoutAddressingForm($order, $this->getCustomer()); return $this->renderStep($context, $order, $form); } @@ -48,8 +47,7 @@ class AddressingStep extends CheckoutStep $order = $this->getCurrentCart(); $this->dispatchCheckoutEvent(SyliusCheckoutEvents::ADDRESSING_INITIALIZE, $order); - //TODO replace getUser with getCustomer - $form = $this->createCheckoutAddressingForm($order, $this->getUser()); + $form = $this->createCheckoutAddressingForm($order, $this->getCustomer()); if ($form->handleRequest($request)->isValid()) { $this->dispatchCheckoutEvent(SyliusCheckoutEvents::ADDRESSING_PRE_COMPLETE, $order); @@ -78,4 +76,9 @@ class AddressingStep extends CheckoutStep { return $this->createForm('sylius_checkout_addressing', $order, array('customer' => $customer)); } + + protected function getCustomer() + { + return $this->container->get('sylius.context.customer')->getCustomer(); + } } diff --git a/src/Sylius/Bundle/CoreBundle/Checkout/Step/FinalizeStep.php b/src/Sylius/Bundle/CoreBundle/Checkout/Step/FinalizeStep.php index 4a30681701..6a188bbb1a 100644 --- a/src/Sylius/Bundle/CoreBundle/Checkout/Step/FinalizeStep.php +++ b/src/Sylius/Bundle/CoreBundle/Checkout/Step/FinalizeStep.php @@ -42,9 +42,9 @@ class FinalizeStep extends CheckoutStep { $order = $this->getCurrentCart(); $this->dispatchCheckoutEvent(SyliusCheckoutEvents::FINALIZE_INITIALIZE, $order); - + $this->completeOrder($order); - + return $this->complete(); } diff --git a/src/Sylius/Bundle/CoreBundle/Checkout/Step/SecurityStep.php b/src/Sylius/Bundle/CoreBundle/Checkout/Step/SecurityStep.php index 16893139cf..0975457774 100644 --- a/src/Sylius/Bundle/CoreBundle/Checkout/Step/SecurityStep.php +++ b/src/Sylius/Bundle/CoreBundle/Checkout/Step/SecurityStep.php @@ -11,13 +11,13 @@ namespace Sylius\Bundle\CoreBundle\Checkout\Step; -use FOS\UserBundle\Event\FilterUserResponseEvent; -use FOS\UserBundle\Event\FormEvent; -use FOS\UserBundle\FOSUserEvents; use Sylius\Bundle\FlowBundle\Process\Context\ProcessContextInterface; +use Sylius\Bundle\FlowBundle\Process\Step\ActionResult; +use Sylius\Component\Core\Model\CustomerInterface; use Sylius\Component\Core\Model\OrderInterface; -use FOS\UserBundle\Model\UserInterface; +use Sylius\Component\Core\Model\UserInterface; use Sylius\Component\Core\SyliusCheckoutEvents; +use Sylius\Component\Resource\Event\ResourceEvent; use Symfony\Component\Form\FormInterface; use Symfony\Component\HttpFoundation\Response; @@ -35,19 +35,16 @@ class SecurityStep extends CheckoutStep */ public function displayAction(ProcessContextInterface $context) { + $order = $this->getCurrentCart(); // If user is already logged in, transparently jump to next step. if ($this->isUserLoggedIn()) { - $this->saveUser($this->getUser()); - - return $this->complete(); + return $this->processUserLoggedIn($order); } - - $order = $this->getCurrentCart(); $this->dispatchCheckoutEvent(SyliusCheckoutEvents::SECURITY_INITIALIZE, $order); $this->overrideSecurityTargetPath(); - return $this->renderStep($context, $this->getRegistrationForm(), $this->getGuestForm($order)); + return $this->renderStep($context, $this->getRegistrationForm(), $this->getGuestForm()); } /** @@ -59,31 +56,19 @@ class SecurityStep extends CheckoutStep $this->dispatchCheckoutEvent(SyliusCheckoutEvents::SECURITY_INITIALIZE, $order); $request = $context->getRequest(); - $guestForm = $this->getGuestForm($order); + $guestForm = $this->getGuestForm(); $registrationForm = $this->getRegistrationForm(); if ($this->isGuestOrderAllowed() && $guestForm->handleRequest($request)->isValid()) { - $this->getManager()->persist($order); - $this->getManager()->flush(); - - return $this->complete(); + return $this->processGuestOrder($guestForm, $order); } elseif ($registrationForm->handleRequest($request)->isValid()) { - $user = $registrationForm->getData(); - - $this->dispatchEvent(FOSUserEvents::REGISTRATION_SUCCESS, new FormEvent($registrationForm, $request)); - $this->dispatchEvent(FOSUserEvents::REGISTRATION_COMPLETED, new FilterUserResponseEvent($user, $request, new Response())); - - $this->saveUser($user); - - return $this->complete(); + return $this->processRegistration($registrationForm, $order); } return $this->renderStep($context, $registrationForm, $guestForm); } /** - * Render step. - * * @param ProcessContextInterface $context * @param FormInterface $registrationForm * @param null|FormInterface $guestForm @@ -100,35 +85,31 @@ class SecurityStep extends CheckoutStep } /** - * Get registration form. - * * @return FormInterface */ protected function getRegistrationForm() { - $user = $this->get('fos_user.user_manager')->createUser(); - $user->setEnabled(true); + /** @var UserInterface $user */ + $user = $this->get('sylius.repository.user')->createNew(); - $form = $this->get('fos_user.registration.form.factory')->createForm(); + $form = $this->createForm('sylius_user_registration', $user); $form->setData($user); return $form; } /** - * Get guest form. - * - * @param OrderInterface $order - * * @return null|FormInterface */ - protected function getGuestForm(OrderInterface $order) + protected function getGuestForm() { if (!$this->isGuestOrderAllowed()) { return null; } + /** @var CustomerInterface $customer */ + $customer = $this->get('sylius.repository.customer')->createNew(); - return $this->createForm('sylius_checkout_guest', $order); + return $this->createForm('sylius_checkout_guest', $customer); } /** @@ -144,23 +125,77 @@ class SecurityStep extends CheckoutStep */ protected function overrideSecurityTargetPath() { - $providerKey = $this->container->getParameter('fos_user.firewall_name'); - - $this->get('session')->set('_security.'.$providerKey.'.target_path', $this->generateUrl('sylius_checkout_security', array(), true)); + $this->get('session')->set('_security.main.target_path', $this->generateUrl('sylius_checkout_security', array(), true)); } /** - * Dispatch security events, update user and flush - * - * @param UserInterface $user + * @param FormInterface $guestForm + * @param OrderInterface $order + * @return ActionResult */ - protected function saveUser(UserInterface $user) + protected function processGuestOrder(FormInterface $guestForm, OrderInterface $order) { - $order = $this->getCurrentCart(); + $customer = $guestForm->getData(); + $order->setCustomer($customer); $this->dispatchCheckoutEvent(SyliusCheckoutEvents::SECURITY_PRE_COMPLETE, $order); + $this->saveResource($order); - $this->get('fos_user.user_manager')->updateUser($user, true); + return $this->complete(); + } - $this->dispatchCheckoutEvent(SyliusCheckoutEvents::SECURITY_COMPLETE, $order); + /** + * @param FormInterface $registrationForm + * @param OrderInterface $order + * @return ActionResult + */ + protected function processRegistration(FormInterface $registrationForm, OrderInterface $order) + { + $this->registerUser($registrationForm); + $this->dispatchCheckoutEvent(SyliusCheckoutEvents::SECURITY_PRE_COMPLETE, $order); + $this->saveResource($order); + + return $this->complete(); + } + + /** + * @param OrderInterface $order + * @return ActionResult + */ + protected function processUserLoggedIn(OrderInterface $order) + { + $this->dispatchCheckoutEvent(SyliusCheckoutEvents::SECURITY_PRE_COMPLETE, $order); + $this->saveResource($order); + + return $this->complete(); + } + + /** + * @param FormInterface $registrationForm + * + * @return UserInterface + */ + protected function registerUser(FormInterface $registrationForm) + { + $user = $registrationForm->getData(); + $this->dispatchEvent('sylius.user.pre_register', new ResourceEvent($user)); + $this->saveResource($user); + $this->dispatchEvent('sylius.user.post_register', new ResourceEvent($user)); + } + + /** + * @param $resource + */ + protected function saveResource($resource) + { + $this->getManager()->persist($resource); + $this->getManager()->flush($resource); + } + /** + * {@inheritdoc} + */ + public function complete() + { + $this->dispatchCheckoutEvent(SyliusCheckoutEvents::SECURITY_COMPLETE, $this->getCurrentCart()); + return parent::complete(); } } diff --git a/src/Sylius/Bundle/CoreBundle/Controller/OrderController.php b/src/Sylius/Bundle/CoreBundle/Controller/OrderController.php index 8cbad16768..cd4e53f530 100644 --- a/src/Sylius/Bundle/CoreBundle/Controller/OrderController.php +++ b/src/Sylius/Bundle/CoreBundle/Controller/OrderController.php @@ -28,17 +28,17 @@ class OrderController extends ResourceController * * @throws NotFoundHttpException */ - public function indexByUserAction(Request $request, $id) + public function indexByCustomerAction(Request $request, $id) { - $user = $this->get('sylius.repository.user')->findForDetailsPage($id); + $customer = $this->get('sylius.repository.customer')->findForDetailsPage($id); - if (!$user) { - throw new NotFoundHttpException('Requested user does not exist.'); + if (!$customer) { + throw new NotFoundHttpException('Requested customer does not exist.'); } $paginator = $this ->getRepository() - ->createByUserPaginator($user, $this->config->getSorting()) + ->createByCustomerPaginator($customer, $this->config->getSorting()) ; $paginator->setCurrentPage($request->get('page', 1), true, true); @@ -51,9 +51,9 @@ class OrderController extends ResourceController $paginator->getNbResults(); $entityManager->getFilters()->enable('softdeleteable'); - return $this->render('SyliusWebBundle:Backend/Order:indexByUser.html.twig', array( - 'user' => $user, - 'orders' => $paginator + return $this->render('SyliusWebBundle:Backend/Order:indexByCustomer.html.twig', array( + 'customer' => $customer, + 'orders' => $paginator )); } diff --git a/src/Sylius/Bundle/CoreBundle/EventListener/CheckoutAddressingListener.php b/src/Sylius/Bundle/CoreBundle/EventListener/CheckoutAddressingListener.php index 2d010d783f..5a4cc7e953 100644 --- a/src/Sylius/Bundle/CoreBundle/EventListener/CheckoutAddressingListener.php +++ b/src/Sylius/Bundle/CoreBundle/EventListener/CheckoutAddressingListener.php @@ -12,6 +12,7 @@ namespace Sylius\Bundle\CoreBundle\EventListener; use Sylius\Component\Core\Model\OrderInterface; +use Sylius\Component\Core\Model\CustomerInterface; use Sylius\Component\Resource\Exception\UnexpectedTypeException; use Symfony\Component\EventDispatcher\GenericEvent; @@ -32,7 +33,7 @@ class CheckoutAddressingListener 'Sylius\Component\Core\Model\OrderInterface' ); } - + /** @var CustomerInterface $customer */ if (null === $customer = $order->getCustomer()) { return; } diff --git a/src/Sylius/Bundle/CoreBundle/EventListener/MailerListener.php b/src/Sylius/Bundle/CoreBundle/EventListener/MailerListener.php index 52bb196ac7..6e1abb3c2b 100644 --- a/src/Sylius/Bundle/CoreBundle/EventListener/MailerListener.php +++ b/src/Sylius/Bundle/CoreBundle/EventListener/MailerListener.php @@ -11,14 +11,13 @@ namespace Sylius\Bundle\CoreBundle\EventListener; -use FOS\UserBundle\Event\FilterUserResponseEvent; -use FOS\UserBundle\Model\UserInterface; use Sylius\Bundle\CoreBundle\Mailer\Emails; use Sylius\Component\Core\Model\OrderInterface; use Sylius\Component\Core\Model\ShipmentInterface; use Sylius\Component\Mailer\Sender\SenderInterface; use Sylius\Component\Order\Model\CommentInterface; use Sylius\Component\Resource\Exception\UnexpectedTypeException; +use Sylius\Component\User\Model\UserInterface; use Symfony\Component\EventDispatcher\GenericEvent; /** @@ -54,7 +53,7 @@ class MailerListener ); } - $this->emailSender->send(Emails::ORDER_CONFIRMATION, array($order->getEmail()), array('order' => $order)); + $this->emailSender->send(Emails::ORDER_CONFIRMATION, array($order->getCustomer()->getEmail()), array('order' => $order)); } /** @@ -123,7 +122,7 @@ class MailerListener $email = $order->getCustomer()->getEmail(); $this->emailSender->send(Emails::ORDER_COMMENT, array($email), array( - 'order' => $order, + 'order' => $order, 'comment' => $comment, )); } diff --git a/src/Sylius/Bundle/CoreBundle/Form/Type/Checkout/AddressingStepType.php b/src/Sylius/Bundle/CoreBundle/Form/Type/Checkout/AddressingStepType.php index 9116b870fe..064bc19ece 100644 --- a/src/Sylius/Bundle/CoreBundle/Form/Type/Checkout/AddressingStepType.php +++ b/src/Sylius/Bundle/CoreBundle/Form/Type/Checkout/AddressingStepType.php @@ -82,7 +82,7 @@ class AddressingStepType extends AbstractResourceType $resolver ->setDefaults(array( - 'user' => null, + 'customer' => null, 'cascade_validation' => true )) ; diff --git a/src/Sylius/Bundle/CoreBundle/Form/Type/Checkout/GuestType.php b/src/Sylius/Bundle/CoreBundle/Form/Type/Checkout/GuestType.php index aaf4f24287..45a7042611 100644 --- a/src/Sylius/Bundle/CoreBundle/Form/Type/Checkout/GuestType.php +++ b/src/Sylius/Bundle/CoreBundle/Form/Type/Checkout/GuestType.php @@ -13,7 +13,6 @@ namespace Sylius\Bundle\CoreBundle\Form\Type\Checkout; use Sylius\Bundle\ResourceBundle\Form\Type\AbstractResourceType; use Symfony\Component\Form\FormBuilderInterface; -use Symfony\Component\Validator\Constraints\Email; /** * Checkout guest form type. @@ -29,9 +28,7 @@ class GuestType extends AbstractResourceType { $builder ->add('email', 'email', array( - 'constraints' => array( - new Email(), - ), + 'label' => 'sylius.form.guest.email.label', )) ; } diff --git a/src/Sylius/Bundle/CoreBundle/Form/Type/UserType.php b/src/Sylius/Bundle/CoreBundle/Form/Type/UserType.php new file mode 100644 index 0000000000..a22b0795e3 --- /dev/null +++ b/src/Sylius/Bundle/CoreBundle/Form/Type/UserType.php @@ -0,0 +1,37 @@ + + */ +class UserType extends BaseUserType +{ + /** + * {@inheritdoc} + */ + public function buildForm(FormBuilderInterface $builder, array $options) + { + parent::buildForm($builder, $options); + $builder + ->add('authorizationRoles', 'sylius_role_choice', array( + 'label' => 'sylius.form.user.roles', + 'multiple' => true, + 'expanded' => true, + 'required' => false + )) + ; + } +} diff --git a/src/Sylius/Bundle/CoreBundle/Kernel/Kernel.php b/src/Sylius/Bundle/CoreBundle/Kernel/Kernel.php index 0ff80074c2..f24e6c213a 100644 --- a/src/Sylius/Bundle/CoreBundle/Kernel/Kernel.php +++ b/src/Sylius/Bundle/CoreBundle/Kernel/Kernel.php @@ -100,7 +100,6 @@ abstract class Kernel extends BaseKernel new \FOS\OAuthServerBundle\FOSOAuthServerBundle(), new \FOS\RestBundle\FOSRestBundle(), - new \FOS\UserBundle\FOSUserBundle(), new \FOS\ElasticaBundle\FOSElasticaBundle(), new \Knp\Bundle\GaufretteBundle\KnpGaufretteBundle(), new \Knp\Bundle\MenuBundle\KnpMenuBundle(), diff --git a/src/Sylius/Bundle/CoreBundle/Resources/config/app/main.yml b/src/Sylius/Bundle/CoreBundle/Resources/config/app/main.yml index d2655a8183..b5859495d8 100644 --- a/src/Sylius/Bundle/CoreBundle/Resources/config/app/main.yml +++ b/src/Sylius/Bundle/CoreBundle/Resources/config/app/main.yml @@ -65,19 +65,6 @@ stof_doctrine_extensions: loggable: true sortable: true -fos_user: - db_driver: orm - firewall_name: main - user_class: %sylius.model.user.class% - group: - group_class: %sylius.model.group.class% - profile: - form: - type: sylius_user_profile - registration: - form: - type: sylius_user_registration - fos_rest: view: formats: @@ -101,11 +88,18 @@ hwi_oauth: client_id: %sylius.oauth.facebook.clientid% client_secret: %sylius.oauth.facebook.clientsecret% scope: "email" + options: + display: popup google: type: google client_id: %sylius.oauth.google.clientid% client_secret: %sylius.oauth.google.clientsecret% scope: "https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/userinfo.profile" + options: + access_type: online + approval_prompt: force + display: popup + login_hint: email address jms_serializer: metadata: diff --git a/src/Sylius/Bundle/CoreBundle/Resources/config/app/sylius.yml b/src/Sylius/Bundle/CoreBundle/Resources/config/app/sylius.yml index 27954736ff..5669dc0ac6 100644 --- a/src/Sylius/Bundle/CoreBundle/Resources/config/app/sylius.yml +++ b/src/Sylius/Bundle/CoreBundle/Resources/config/app/sylius.yml @@ -714,5 +714,7 @@ sylius_user: user: model: Sylius\Component\Core\Model\User controller: Sylius\Bundle\CoreBundle\Controller\UserController + form: + default: Sylius\Bundle\CoreBundle\Form\Type\UserType customer: model: Sylius\Component\Core\Model\Customer \ No newline at end of file diff --git a/src/Sylius/Bundle/CoreBundle/Resources/config/doctrine/model/Order.orm.xml b/src/Sylius/Bundle/CoreBundle/Resources/config/doctrine/model/Order.orm.xml index 178fb4282b..6ed7184d68 100644 --- a/src/Sylius/Bundle/CoreBundle/Resources/config/doctrine/model/Order.orm.xml +++ b/src/Sylius/Bundle/CoreBundle/Resources/config/doctrine/model/Order.orm.xml @@ -62,6 +62,9 @@ + + + diff --git a/src/Sylius/Bundle/CoreBundle/Resources/config/form.xml b/src/Sylius/Bundle/CoreBundle/Resources/config/form.xml index 23c9852095..b00664daf9 100644 --- a/src/Sylius/Bundle/CoreBundle/Resources/config/form.xml +++ b/src/Sylius/Bundle/CoreBundle/Resources/config/form.xml @@ -74,9 +74,9 @@ - %sylius.model.cart.class% + %sylius.model.customer.class% - Guest + guest diff --git a/src/Sylius/Bundle/CoreBundle/Resources/config/mailer.xml b/src/Sylius/Bundle/CoreBundle/Resources/config/mailer.xml index 72a6df9c2d..5932d817b4 100644 --- a/src/Sylius/Bundle/CoreBundle/Resources/config/mailer.xml +++ b/src/Sylius/Bundle/CoreBundle/Resources/config/mailer.xml @@ -25,8 +25,8 @@ - - + + diff --git a/src/Sylius/Bundle/CoreBundle/spec/Form/Type/UserTypeSpec.php b/src/Sylius/Bundle/CoreBundle/spec/Form/Type/UserTypeSpec.php new file mode 100644 index 0000000000..3e30c531de --- /dev/null +++ b/src/Sylius/Bundle/CoreBundle/spec/Form/Type/UserTypeSpec.php @@ -0,0 +1,53 @@ + + */ +class UserTypeSpec extends ObjectBehavior +{ + function let(CanonicalizerInterface $canonicalizer) + { + $this->beConstructedWith('Sylius\Component\Core\Model\User', array('sylius'), $canonicalizer); + } + + function it_is_initializable() + { + $this->shouldHaveType('Sylius\Bundle\CoreBundle\Form\Type\UserType'); + } + + function it_extends_user_type_from_user_bundle() + { + $this->shouldHaveType('Sylius\Bundle\UserBundle\Form\Type\UserType'); + } + + function it_has_name() + { + $this->getName()->shouldReturn('sylius_user'); + } + + function it_builds_form(FormBuilderInterface $builder) + { + $builder->add('customer', 'sylius_customer')->shouldBeCalled()->willReturn($builder); + $builder->add('plainPassword', 'password', Argument::any())->shouldBeCalled()->willReturn($builder); + $builder->add('enabled', 'checkbox', Argument::any())->shouldBeCalled()->willReturn($builder); + $builder->add('authorizationRoles', 'sylius_role_choice', Argument::any())->shouldBeCalled()->willReturn($builder); + + $this->buildForm($builder, array()); + } +} diff --git a/src/Sylius/Bundle/ResourceBundle/Controller/ResourceController.php b/src/Sylius/Bundle/ResourceBundle/Controller/ResourceController.php index 6f459c15dc..3a369e15df 100644 --- a/src/Sylius/Bundle/ResourceBundle/Controller/ResourceController.php +++ b/src/Sylius/Bundle/ResourceBundle/Controller/ResourceController.php @@ -438,7 +438,6 @@ class ResourceController extends FOSRestController ) ); } - return $resource; } diff --git a/src/Sylius/Bundle/UserBundle/Controller/CustomerController.php b/src/Sylius/Bundle/UserBundle/Controller/CustomerController.php index 295627c9aa..4c457dfd05 100644 --- a/src/Sylius/Bundle/UserBundle/Controller/CustomerController.php +++ b/src/Sylius/Bundle/UserBundle/Controller/CustomerController.php @@ -39,16 +39,13 @@ class CustomerController extends ResourceController return $this->handleView($this->view($form, 400)); } - $view = $this - ->view() - ->setTemplate($this->config->getTemplate('updateProfile.html')) - ->setData(array( + return $this->render( + 'SyliusWebBundle:Frontend/Account:Profile/edit.html.twig', + array( $this->config->getResourceName() => $resource, 'form' => $form->createView(), - )) - ; - - return $this->handleView($view); + ) + ); } protected function getCustomer() diff --git a/src/Sylius/Bundle/UserBundle/DependencyInjection/SyliusUserExtension.php b/src/Sylius/Bundle/UserBundle/DependencyInjection/SyliusUserExtension.php index a206de44a4..d19c558fb6 100644 --- a/src/Sylius/Bundle/UserBundle/DependencyInjection/SyliusUserExtension.php +++ b/src/Sylius/Bundle/UserBundle/DependencyInjection/SyliusUserExtension.php @@ -42,14 +42,5 @@ class SyliusUserExtension extends AbstractResourceExtension $container->setParameter('sylius.user.resetting.token_ttl', $config['resetting']['token']['ttl']); $container->setParameter('sylius.user.resetting.token_length', $config['resetting']['token']['length']); $container->setParameter('sylius.user.resetting.pin_length', $config['resetting']['pin']['length']); - - $container - ->getDefinition('sylius.form.type.user_registration') - ->addArgument(new Reference('sylius.user.canonicalizer')) - ; - $container - ->getDefinition('sylius.form.type.user') - ->addArgument(new Reference('sylius.user.canonicalizer')) - ; } } diff --git a/src/Sylius/Bundle/UserBundle/Doctrine/ORM/CustomerRepository.php b/src/Sylius/Bundle/UserBundle/Doctrine/ORM/CustomerRepository.php new file mode 100644 index 0000000000..4646c7a9af --- /dev/null +++ b/src/Sylius/Bundle/UserBundle/Doctrine/ORM/CustomerRepository.php @@ -0,0 +1,49 @@ + + */ +class CustomerRepository extends EntityRepository +{ + /** + * Get the customer's data for the details page. + * + * @param integer $id + * + * @return null|UserInterface + */ + public function findForDetailsPage($id) + { + $this->_em->getFilters()->disable('softdeleteable'); + + $queryBuilder = $this->getQueryBuilder(); + $queryBuilder + ->andWhere($queryBuilder->expr()->eq('o.id', ':id')) + ->setParameter('id', $id) + ; + + $result = $queryBuilder + ->getQuery() + ->getOneOrNullResult() + ; + $this->_em->getFilters()->enable('softdeleteable'); + + return $result; + } +} diff --git a/src/Sylius/Bundle/UserBundle/Doctrine/ORM/UserRepository.php b/src/Sylius/Bundle/UserBundle/Doctrine/ORM/UserRepository.php index a1dbcb5bce..7edf4fe0c9 100644 --- a/src/Sylius/Bundle/UserBundle/Doctrine/ORM/UserRepository.php +++ b/src/Sylius/Bundle/UserBundle/Doctrine/ORM/UserRepository.php @@ -17,16 +17,12 @@ use Sylius\Component\Core\Model\UserInterface; use Sylius\Component\User\Repository\UserRepositoryInterface; /** - * User repository. - * * @author Saša Stamenković * @author Michał Marcinkowski */ class UserRepository extends EntityRepository implements UserRepositoryInterface { /** - * Create filter paginator. - * * @param array $criteria * @param array $sorting * @param bool $deleted @@ -43,10 +39,11 @@ class UserRepository extends EntityRepository implements UserRepositoryInterface if (isset($criteria['query'])) { $queryBuilder - ->where('o.username LIKE :query') - ->orWhere('o.email LIKE :query') - ->orWhere('o.firstName LIKE :query') - ->orWhere('o.lastName LIKE :query') + ->leftJoin($this->getAlias().'.customer', 'customer') + ->where('customer.emailCanonical LIKE :query') + ->orWhere('customer.firstName LIKE :query') + ->orWhere('customer.lastName LIKE :query') + ->orWhere($this->getAlias().'.username LIKE :query') ->setParameter('query', '%'.$criteria['query'].'%') ; } @@ -82,7 +79,9 @@ class UserRepository extends EntityRepository implements UserRepositoryInterface $queryBuilder = $this->getQueryBuilder(); $queryBuilder - ->andWhere($queryBuilder->expr()->eq('o.id', ':id')) + ->leftJoin($this->getAlias().'.customer', 'customer') + ->addSelect('customer') + ->where($queryBuilder->expr()->eq($this->getAlias().'.id', ':id')) ->setParameter('id', $id) ; diff --git a/src/Sylius/Bundle/UserBundle/EventListener/CanonicalizerListener.php b/src/Sylius/Bundle/UserBundle/EventListener/CanonicalizerListener.php index a1cf967e09..d0dbc76aea 100644 --- a/src/Sylius/Bundle/UserBundle/EventListener/CanonicalizerListener.php +++ b/src/Sylius/Bundle/UserBundle/EventListener/CanonicalizerListener.php @@ -13,6 +13,7 @@ namespace Sylius\Bundle\UserBundle\EventListener; use Doctrine\ORM\Event\LifecycleEventArgs; use Sylius\Component\User\Canonicalizer\CanonicalizerInterface; +use Sylius\Component\User\Model\CustomerInterface; use Sylius\Component\User\Model\UserInterface; /** @@ -36,12 +37,11 @@ class CanonicalizerListener { $item = $event->getEntity(); - if (!$item instanceof UserInterface) { - return; + if ($item instanceof CustomerInterface) { + $item->setEmailCanonical($this->canonicalizer->canonicalize($item->getEmail())); + } elseif ($item instanceof UserInterface) { + $item->setUsernameCanonical($this->canonicalizer->canonicalize($item->getUsername())); } - - $item->setUsernameCanonical($this->canonicalizer->canonicalize($item->getUsername())); - $item->setEmailCanonical($this->canonicalizer->canonicalize($item->getEmail())); } public function prePersist(LifecycleEventArgs $event) diff --git a/src/Sylius/Bundle/UserBundle/EventListener/DefaultUsernameListener.php b/src/Sylius/Bundle/UserBundle/EventListener/DefaultUsernameListener.php new file mode 100644 index 0000000000..14e1b87f58 --- /dev/null +++ b/src/Sylius/Bundle/UserBundle/EventListener/DefaultUsernameListener.php @@ -0,0 +1,53 @@ + + */ +class DefaultUsernameListener +{ + public function prePersist(LifecycleEventArgs $event) + { + $item = $event->getEntity(); + + if (!$item instanceof UserInterface) { + return; + } + $customer = $item->getCustomer(); + if (null !== $customer && $customer->getEmail() !== $item->getUsername()) { + $item->setUsername($customer->getEmail()); + } + } + + public function preUpdate(LifecycleEventArgs $event) + { + $item = $event->getEntity(); + + if (!$item instanceof CustomerInterface) { + return; + } + $user = $item->getUser(); + if (null !== $user && $user->getUsername() !== $item->getEmail()) { + $user->setUsername($item->getEmail()); + $entityManager = $event->getEntityManager(); + $entityManager->persist($user); + $entityManager->flush($user); + } + } +} diff --git a/src/Sylius/Bundle/UserBundle/Form/EventListener/CanonicalizerFormListener.php b/src/Sylius/Bundle/UserBundle/Form/EventListener/CanonicalizerFormListener.php deleted file mode 100644 index e8a9db4e6d..0000000000 --- a/src/Sylius/Bundle/UserBundle/Form/EventListener/CanonicalizerFormListener.php +++ /dev/null @@ -1,47 +0,0 @@ - - */ -class CanonicalizerFormListener implements EventSubscriberInterface -{ - public function __construct(CanonicalizerInterface $canonicalizer) - { - $this->canonicalizer = $canonicalizer; - } - - public static function getSubscribedEvents() - { - return array( - FormEvents::SUBMIT => 'submit', - ); - } - - public function submit(FormEvent $event) - { - $user = $event->getData(); - - if (!$user instanceof UserInterface) { - throw new UnexpectedTypeException($user, 'Sylius\Component\User\Model\UserInterface'); - } - $user->setUsernameCanonical($this->canonicalizer->canonicalize($user->getUsername())); - $user->setEmailCanonical($this->canonicalizer->canonicalize($user->getEmail())); - } -} diff --git a/src/Sylius/Bundle/UserBundle/Form/EventListener/UserRegistrationFormListener.php b/src/Sylius/Bundle/UserBundle/Form/EventListener/UserRegistrationFormListener.php new file mode 100644 index 0000000000..434e3de4ee --- /dev/null +++ b/src/Sylius/Bundle/UserBundle/Form/EventListener/UserRegistrationFormListener.php @@ -0,0 +1,40 @@ + + */ +class UserRegistrationFormListener implements EventSubscriberInterface +{ + public static function getSubscribedEvents() + { + return array( + FormEvents::SUBMIT => 'submit', + ); + } + public function submit(FormEvent $event) + { + $user = $event->getData(); + if (!$user instanceof UserInterface) { + throw new UnexpectedTypeException($user, 'Sylius\Component\User\Model\UserInterface'); + } + + $user->setEnabled(true); + } +} \ No newline at end of file diff --git a/src/Sylius/Bundle/UserBundle/Form/Type/UserRegistrationType.php b/src/Sylius/Bundle/UserBundle/Form/Type/UserRegistrationType.php index 5ea5191adb..31e740c4cb 100644 --- a/src/Sylius/Bundle/UserBundle/Form/Type/UserRegistrationType.php +++ b/src/Sylius/Bundle/UserBundle/Form/Type/UserRegistrationType.php @@ -11,30 +11,25 @@ namespace Sylius\Bundle\UserBundle\Form\Type; -use Sylius\Component\User\Canonicalizer\CanonicalizerInterface; +use Sylius\Bundle\UserBundle\Form\EventListener\UserRegistrationFormListener; use Symfony\Component\Form\FormBuilderInterface; use Sylius\Bundle\ResourceBundle\Form\Type\AbstractResourceType; -use Sylius\Bundle\UserBundle\Form\EventListener\CanonicalizerFormListener; +use Symfony\Component\OptionsResolver\OptionsResolverInterface; /** * @author Łukasz Chruściel */ class UserRegistrationType extends AbstractResourceType { - /** - * @var CanonicalizerInterface - */ - protected $canonicalizer; - /** * @param string $dataClass * @param string[] $validationGroups - * @param CanonicalizerInterface $canonicalizer */ - public function __construct($dataClass, array $validationGroups, CanonicalizerInterface $canonicalizer) + public function __construct($dataClass, array $validationGroups) { + // Add registration validation group + $validationGroups[] = 'registration'; parent::__construct($dataClass, $validationGroups); - $this->canonicalizer = $canonicalizer; } /** @@ -43,7 +38,7 @@ class UserRegistrationType extends AbstractResourceType public function buildForm(FormBuilderInterface $builder, array $options) { $builder - ->addEventSubscriber(new CanonicalizerFormListener($this->canonicalizer)) + ->addEventSubscriber(new UserRegistrationFormListener()) ->add('customer', 'sylius_customer') ->add('plainPassword', 'repeated', array( 'type' => 'password', @@ -54,6 +49,18 @@ class UserRegistrationType extends AbstractResourceType ; } + /** + * {@inheritdoc} + */ + public function setDefaultOptions(OptionsResolverInterface $resolver) + { + $resolver->setDefaults(array( + 'data_class' => $this->dataClass, + 'validation_groups' => $this->validationGroups, + 'cascade_validation' => true + )); + } + /** * {@inheritdoc} */ diff --git a/src/Sylius/Bundle/UserBundle/Form/Type/UserType.php b/src/Sylius/Bundle/UserBundle/Form/Type/UserType.php index 492c5b2465..ccd934a3ae 100644 --- a/src/Sylius/Bundle/UserBundle/Form/Type/UserType.php +++ b/src/Sylius/Bundle/UserBundle/Form/Type/UserType.php @@ -12,29 +12,22 @@ namespace Sylius\Bundle\UserBundle\Form\Type; use Sylius\Bundle\ResourceBundle\Form\Type\AbstractResourceType; -use Sylius\Bundle\UserBundle\Form\EventListener\CanonicalizerFormListener; -use Sylius\Component\User\Canonicalizer\CanonicalizerInterface; use Symfony\Component\Form\FormBuilderInterface; +use Symfony\Component\Form\FormInterface; +use Symfony\Component\OptionsResolver\OptionsResolverInterface; /** * @author Łukasz Chruściel */ class UserType extends AbstractResourceType { - /** - * @var CanonicalizerInterface - */ - protected $canonicalizer; - /** * @param string $dataClass * @param string[] $validationGroups - * @param CanonicalizerInterface $canonicalizer */ - public function __construct($dataClass, array $validationGroups, CanonicalizerInterface $canonicalizer) + public function __construct($dataClass, array $validationGroups) { parent::__construct($dataClass, $validationGroups); - $this->canonicalizer = $canonicalizer; } /** @@ -43,7 +36,6 @@ class UserType extends AbstractResourceType public function buildForm(FormBuilderInterface $builder, array $options) { $builder - ->addEventSubscriber(new CanonicalizerFormListener($this->canonicalizer)) ->add('customer', 'sylius_customer') ->add('plainPassword', 'password', array( 'label' => 'sylius.form.user.password.label', @@ -54,6 +46,25 @@ class UserType extends AbstractResourceType ; } + /** + * {@inheritdoc} + */ + public function setDefaultOptions(OptionsResolverInterface $resolver) + { + $resolver->setDefaults(array( + 'data_class' => $this->dataClass, + 'validation_groups' => function (FormInterface $form) { + $data = $form->getData(); + $groups = $this->validationGroups; + if ($data && !$data->getId()) { + $groups[] = 'user_create'; + } + return $groups; + }, + 'cascade_validation' => true + )); + } + /** * {@inheritdoc} */ diff --git a/src/Sylius/Bundle/UserBundle/Resources/config/driver/doctrine/orm.xml b/src/Sylius/Bundle/UserBundle/Resources/config/driver/doctrine/orm.xml index 481859f1cd..89ef5ae382 100644 --- a/src/Sylius/Bundle/UserBundle/Resources/config/driver/doctrine/orm.xml +++ b/src/Sylius/Bundle/UserBundle/Resources/config/driver/doctrine/orm.xml @@ -19,6 +19,7 @@ Sylius\Bundle\UserBundle\Doctrine\ORM\GroupRepository Sylius\Bundle\UserBundle\Doctrine\ORM\UserRepository + Sylius\Bundle\UserBundle\Doctrine\ORM\CustomerRepository Sylius\Bundle\UserBundle\Form\Type\UserEntityType Sylius\Bundle\UserBundle\Form\Type\GroupEntityType diff --git a/src/Sylius/Bundle/UserBundle/Resources/config/services.xml b/src/Sylius/Bundle/UserBundle/Resources/config/services.xml index 96362d4c32..7a81b8e0f4 100644 --- a/src/Sylius/Bundle/UserBundle/Resources/config/services.xml +++ b/src/Sylius/Bundle/UserBundle/Resources/config/services.xml @@ -40,6 +40,7 @@ Sylius\Bundle\UserBundle\Form\Type\UserResetPasswordType Sylius\Bundle\UserBundle\Form\Type\UserChangePasswordType + Sylius\Bundle\UserBundle\EventListener\DefaultUsernameListener Sylius\Bundle\UserBundle\EventListener\CustomerAwareListener Sylius\Bundle\UserBundle\EventListener\UserDeleteListener Sylius\Bundle\UserBundle\EventListener\CanonicalizerListener @@ -96,8 +97,9 @@ - - + + + diff --git a/src/Sylius/Bundle/UserBundle/Resources/config/validation.xml b/src/Sylius/Bundle/UserBundle/Resources/config/validation.xml index 54b6ce90b7..f6f0c6f94a 100644 --- a/src/Sylius/Bundle/UserBundle/Resources/config/validation.xml +++ b/src/Sylius/Bundle/UserBundle/Resources/config/validation.xml @@ -17,72 +17,82 @@ http://symfony.com/schema/dic/services/constraint-mapping-1.0.xsd"> + + + + + - + - + - + - + - + - + - + - - - - - - - - - - - - - - - - - - + + + + + + + + diff --git a/src/Sylius/Bundle/UserBundle/Resources/translations/validators.en.yml b/src/Sylius/Bundle/UserBundle/Resources/translations/validators.en.yml index 39ba6b1d8a..bbd6297c8e 100644 --- a/src/Sylius/Bundle/UserBundle/Resources/translations/validators.en.yml +++ b/src/Sylius/Bundle/UserBundle/Resources/translations/validators.en.yml @@ -30,4 +30,5 @@ sylius: max: Email must not be longer than {{ limit }} characters. min: Email must be at least {{ limit }} characters long. not_blank: Please enter your email. - invalid: This email is invalid. \ No newline at end of file + invalid: This email is invalid. + unique: This email is already used. \ No newline at end of file diff --git a/src/Sylius/Bundle/UserBundle/Security/UserLogin.php b/src/Sylius/Bundle/UserBundle/Security/UserLogin.php index 113cf6b971..64897c25c9 100644 --- a/src/Sylius/Bundle/UserBundle/Security/UserLogin.php +++ b/src/Sylius/Bundle/UserBundle/Security/UserLogin.php @@ -30,6 +30,7 @@ class UserLogin implements UserLoginInterface */ public function __construct(Container $container) { + //TODO inject security context instead of whole container $this->container = $container; } @@ -40,6 +41,7 @@ class UserLogin implements UserLoginInterface { $token = new UsernamePasswordToken($user, null, 'main', $user->getRoles()); $this->container->get('security.context')->setToken($token); - $this->container->get('session')->set('_security_main', serialize($token)); + // TODO Check if not needed for sure +// $this->container->get('session')->set('_security_main', serialize($token)); } } diff --git a/src/Sylius/Bundle/UserBundle/Security/UserLoginInterface.php b/src/Sylius/Bundle/UserBundle/Security/UserLoginInterface.php index 54c7fc677d..4996407229 100644 --- a/src/Sylius/Bundle/UserBundle/Security/UserLoginInterface.php +++ b/src/Sylius/Bundle/UserBundle/Security/UserLoginInterface.php @@ -20,6 +20,8 @@ interface UserLoginInterface { /** * Log in user. + * + * @param UserInterface $user */ public function login(UserInterface $user); } diff --git a/src/Sylius/Bundle/UserBundle/spec/EventListener/CanonicalizerListenerSpec.php b/src/Sylius/Bundle/UserBundle/spec/EventListener/CanonicalizerListenerSpec.php index a3950afe2d..b808aab696 100644 --- a/src/Sylius/Bundle/UserBundle/spec/EventListener/CanonicalizerListenerSpec.php +++ b/src/Sylius/Bundle/UserBundle/spec/EventListener/CanonicalizerListenerSpec.php @@ -14,8 +14,8 @@ namespace spec\Sylius\Bundle\UserBundle\EventListener; use Doctrine\ORM\Event\LifecycleEventArgs; use PhpSpec\ObjectBehavior; use Prophecy\Argument; -use Sylius\Component\Resource\Exception\UnexpectedTypeException; use Sylius\Component\User\Canonicalizer\CanonicalizerInterface; +use Sylius\Component\User\Model\CustomerInterface; use Sylius\Component\User\Model\UserInterface; /** @@ -33,45 +33,66 @@ class CanonicalizerListenerSpec extends ObjectBehavior $this->shouldHaveType('Sylius\Bundle\UserBundle\EventListener\CanonicalizerListener'); } - function it_canonicalize_user_email_and_username_on_pre_persist_doctrine_event($canonicalizer, LifecycleEventArgs $event, UserInterface $user) + function it_canonicalize_user_username_on_pre_persist_doctrine_event($canonicalizer, LifecycleEventArgs $event, UserInterface $user) { $event->getEntity()->willReturn($user); - $user->getUsername()->willReturn('testUser'); - $user->getEmail()->willReturn('test@email.com'); $user->setUsernameCanonical('testuser')->shouldBeCalled(); - $user->setEmailCanonical('test@email.com')->shouldBeCalled(); - $canonicalizer->canonicalize('testUser')->willReturn('testuser')->shouldBeCalled(); - $canonicalizer->canonicalize('test@email.com')->willReturn('test@email.com')->shouldBeCalled(); $this->prePersist($event); } - function it_canonicalize_user_email_and_username_on_pre_update_doctrine_event($canonicalizer, LifecycleEventArgs $event, UserInterface $user) + function it_canonicalize_customer_email_on_pre_persist_doctrine_event($canonicalizer, LifecycleEventArgs $event, CustomerInterface $customer) + { + $event->getEntity()->willReturn($customer); + $customer->getEmail()->willReturn('testUser@Email.com'); + + $customer->setEmailCanonical('testuser@email.com')->shouldBeCalled(); + $canonicalizer->canonicalize('testUser@Email.com')->willReturn('testuser@email.com')->shouldBeCalled(); + + $this->prePersist($event); + } + + function it_canonicalize_user_username_on_pre_update_doctrine_event($canonicalizer, LifecycleEventArgs $event, UserInterface $user) { $event->getEntity()->willReturn($user); - $user->getUsername()->willReturn('testUser'); - $user->getEmail()->willReturn('test@email.com'); $user->setUsernameCanonical('testuser')->shouldBeCalled(); - $user->setEmailCanonical('test@email.com')->shouldBeCalled(); - $canonicalizer->canonicalize('testUser')->willReturn('testuser')->shouldBeCalled(); - $canonicalizer->canonicalize('test@email.com')->willReturn('test@email.com')->shouldBeCalled(); $this->preUpdate($event); } - function it_canonicalize_only_user_interface_implementation($canonicalizer, LifecycleEventArgs $event) + function it_canonicalize_customer_email_on_pre_update_doctrine_event($canonicalizer, LifecycleEventArgs $event, CustomerInterface $customer) { - $user = ''; - $event->getEntity()->willReturn($user); + $event->getEntity()->willReturn($customer); + $customer->getEmail()->willReturn('testUser@Email.com'); - $canonicalizer->canonicalize('testUser')->shouldNotBeCalled(); - $canonicalizer->canonicalize('test@email.com')->shouldNotBeCalled(); + $customer->setEmailCanonical('testuser@email.com')->shouldBeCalled(); + $canonicalizer->canonicalize('testUser@Email.com')->willReturn('testuser@email.com')->shouldBeCalled(); + + $this->preUpdate($event); + } + + function it_canonicalize_only_user_or_customer_interface_implementation_on_pre_presist($canonicalizer, LifecycleEventArgs $event) + { + $item = new \stdClass(); + $event->getEntity()->willReturn($item); + + $canonicalizer->canonicalize(Argument::any())->shouldNotBeCalled(); + + $this->prePersist($event); + } + + function it_canonicalize_only_user_or_customer_interface_implementation_on_pre_update($canonicalizer, LifecycleEventArgs $event) + { + $item = new \stdClass(); + $event->getEntity()->willReturn($item); + + $canonicalizer->canonicalize(Argument::any())->shouldNotBeCalled(); $this->preUpdate($event); } diff --git a/src/Sylius/Bundle/UserBundle/spec/Form/EventListener/CanonicalizerFormListenerSpec.php b/src/Sylius/Bundle/UserBundle/spec/Form/EventListener/CanonicalizerFormListenerSpec.php deleted file mode 100644 index 876d47328f..0000000000 --- a/src/Sylius/Bundle/UserBundle/spec/Form/EventListener/CanonicalizerFormListenerSpec.php +++ /dev/null @@ -1,62 +0,0 @@ - - */ -class CanonicalizerFormListenerSpec extends ObjectBehavior -{ - function let(CanonicalizerInterface $canonicalizer) - { - $this->beConstructedWith($canonicalizer); - } - - function it_is_initializable() - { - $this->shouldHaveType('Sylius\Bundle\UserBundle\Form\EventListener\CanonicalizerFormListener'); - } - - function it_implements_event_subscriber_interface() - { - $this->shouldImplement('Symfony\Component\EventDispatcher\EventSubscriberInterface'); - } - - function it_canonicalize_user_email_and_username($canonicalizer, FormEvent $event, UserInterface $user) - { - $event->getData()->willReturn($user); - - $user->getUsername()->willReturn('testUser'); - $user->getEmail()->willReturn('test@user.com'); - $user->setUsernameCanonical('testuser')->shouldBeCalled(); - $user->setEmailCanonical('test@user.com')->shouldBeCalled(); - - $canonicalizer->canonicalize('testUser')->willReturn('testuser'); - $canonicalizer->canonicalize('test@user.com')->willReturn('test@user.com'); - - $this->submit($event); - } - - function it_affects_only_on_user_interface_implementations(FormEvent $event) - { - $user = ''; - $event->getData()->willReturn($user); - $this->shouldThrow(new UnexpectedTypeException($user, 'Sylius\Component\User\Model\UserInterface')) - ->duringSubmit($event); - } -} diff --git a/src/Sylius/Bundle/UserBundle/spec/Form/Type/UserRegistrationTypeSpec.php b/src/Sylius/Bundle/UserBundle/spec/Form/Type/UserRegistrationTypeSpec.php index 6317d64155..dcede1a049 100644 --- a/src/Sylius/Bundle/UserBundle/spec/Form/Type/UserRegistrationTypeSpec.php +++ b/src/Sylius/Bundle/UserBundle/spec/Form/Type/UserRegistrationTypeSpec.php @@ -43,7 +43,7 @@ class UserRegistrationTypeSpec extends ObjectBehavior function it_builds_form(FormBuilderInterface $builder) { - $builder->addEventSubscriber(Argument::type('Sylius\Bundle\UserBundle\Form\EventListener\CanonicalizerFormListener'))->shouldBeCalled()->willReturn($builder); + $builder->addEventSubscriber(Argument::type('Sylius\Bundle\UserBundle\Form\EventListener\UserRegistrationFormListener'))->shouldBeCalled()->willReturn($builder); $builder->add('customer', 'sylius_customer')->shouldBeCalled()->willReturn($builder); $builder->add('plainPassword', 'repeated', Argument::any())->shouldBeCalled()->willReturn($builder); diff --git a/src/Sylius/Bundle/UserBundle/spec/Form/Type/UserTypeSpec.php b/src/Sylius/Bundle/UserBundle/spec/Form/Type/UserTypeSpec.php index 122759e766..02a0a31d45 100644 --- a/src/Sylius/Bundle/UserBundle/spec/Form/Type/UserTypeSpec.php +++ b/src/Sylius/Bundle/UserBundle/spec/Form/Type/UserTypeSpec.php @@ -43,7 +43,6 @@ class UserTypeSpec extends ObjectBehavior function it_builds_form(FormBuilderInterface $builder) { - $builder->addEventSubscriber(Argument::type('Sylius\Bundle\UserBundle\Form\EventListener\CanonicalizerFormListener'))->shouldBeCalled()->willReturn($builder); $builder->add('customer', 'sylius_customer')->shouldBeCalled()->willReturn($builder); $builder->add('plainPassword', 'password', Argument::any())->shouldBeCalled()->willReturn($builder); $builder->add('enabled', 'checkbox', Argument::any())->shouldBeCalled()->willReturn($builder); diff --git a/src/Sylius/Bundle/UserBundle/spec/Security/UserLoginSpec.php b/src/Sylius/Bundle/UserBundle/spec/Security/UserLoginSpec.php index 2f1d0ed115..5469b07bf4 100644 --- a/src/Sylius/Bundle/UserBundle/spec/Security/UserLoginSpec.php +++ b/src/Sylius/Bundle/UserBundle/spec/Security/UserLoginSpec.php @@ -43,14 +43,15 @@ class UserLoginSpec extends ObjectBehavior function it_logs_user_in($container, UserInterface $user, SecurityContextInterface $context, SessionInterface $session) { + //TODO cleanup $user->getRoles()->willReturn(array('ROLE_TEST')); - $user->serialize(Argument::any())->shouldBeCalled(); +// $user->serialize(Argument::any())->shouldBeCalled(); $container->get('security.context')->willReturn($context); - $container->get('session')->willReturn($session); +// $container->get('session')->willReturn($session); $context->setToken(Argument::type('Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken'))->shouldBeCalled(); - $session->set('_security_main', Argument::any())->shouldBeCalled(); +// $session->set('_security_main', Argument::any())->shouldBeCalled(); $this->login($user); } diff --git a/src/Sylius/Bundle/WebBundle/Behat/WebContext.php b/src/Sylius/Bundle/WebBundle/Behat/WebContext.php index 4b74d60b42..d48363b5e4 100644 --- a/src/Sylius/Bundle/WebBundle/Behat/WebContext.php +++ b/src/Sylius/Bundle/WebBundle/Behat/WebContext.php @@ -749,7 +749,7 @@ class WebContext extends DefaultContext implements SnippetAcceptingContext $this->fillField('Email', $email); $this->fillField('Password', $password); - $this->pressButton('login'); + $this->pressButton('Login'); } /** diff --git a/src/Sylius/Bundle/WebBundle/Controller/Backend/FormController.php b/src/Sylius/Bundle/WebBundle/Controller/Backend/FormController.php index dd5ebd0e72..b8938c6b76 100644 --- a/src/Sylius/Bundle/WebBundle/Controller/Backend/FormController.php +++ b/src/Sylius/Bundle/WebBundle/Controller/Backend/FormController.php @@ -43,7 +43,7 @@ class FormController extends Controller * * @return Response */ - public function filterAction($type, $template = 'SyliusWebBundle:Backend/Form:filter.html.twig') + public function filterAction($type, $template) { return $this->render($template, array( 'form' => $this->get('form.factory')->createNamed('criteria', $type)->createView() diff --git a/src/Sylius/Bundle/WebBundle/Controller/Frontend/Account/ProfileController.php b/src/Sylius/Bundle/WebBundle/Controller/Frontend/Account/ProfileController.php deleted file mode 100644 index af88878998..0000000000 --- a/src/Sylius/Bundle/WebBundle/Controller/Frontend/Account/ProfileController.php +++ /dev/null @@ -1,152 +0,0 @@ -getCustomer(); - $orderRepository = $this->get('sylius.repository.order'); - $orders = $orderRepository->findBy(array('customer' => $customer), array('updatedAt' => 'desc'), 5); - - $view = $this - ->view() - ->setTemplate('SyliusWebBundle:Frontend/Account:Profile/index.html.twig') - ->setData(array( - 'customer' => $customer, - 'orders' => $orders, - )) - ; - - return $this->handleView($view); - } - - /** - * Edit the user - */ - public function editAction(Request $request) - { - $user = $this->getUser(); - if (!is_object($user) || !$user instanceof UserInterface) { - throw new AccessDeniedException('This user does not have access to this section.'); - } - - /** @var $dispatcher \Symfony\Component\EventDispatcher\EventDispatcherInterface */ - $dispatcher = $this->get('event_dispatcher'); - - $event = new GetResponseUserEvent($user, $request); - $dispatcher->dispatch(FOSUserEvents::PROFILE_EDIT_INITIALIZE, $event); - - if (null !== $event->getResponse()) { - return $event->getResponse(); - } - - /** @var $formFactory \FOS\UserBundle\Form\Factory\FactoryInterface */ - $formFactory = $this->get('fos_user.profile.form.factory'); - - $form = $formFactory->createForm(); - $form->setData($user); - - $form->handleRequest($request); - - if ($form->isValid()) { - /** @var $userManager \FOS\UserBundle\Model\UserManagerInterface */ - $userManager = $this->get('fos_user.user_manager'); - - $event = new FormEvent($form, $request); - $dispatcher->dispatch(FOSUserEvents::PROFILE_EDIT_SUCCESS, $event); - - $userManager->updateUser($user); - - if (null === $response = $event->getResponse()) { - $url = $this->generateUrl('sylius_account_homepage'); - $response = new RedirectResponse($url); - } - - $dispatcher->dispatch(FOSUserEvents::PROFILE_EDIT_COMPLETED, new FilterUserResponseEvent($user, $request, $response)); - - return $response; - } - - return $this->render('SyliusWebBundle:Frontend/Account:Profile/edit.html.twig', array( - 'form' => $form->createView() - )); - } - - /** - * Change user password - */ - public function changePasswordAction(Request $request) - { - $user = $this->getUser(); - if (!is_object($user) || !$user instanceof UserInterface) { - throw new AccessDeniedException('This user does not have access to this section.'); - } - - /** @var $dispatcher \Symfony\Component\EventDispatcher\EventDispatcherInterface */ - $dispatcher = $this->get('event_dispatcher'); - - $event = new GetResponseUserEvent($user, $request); - $dispatcher->dispatch(FOSUserEvents::CHANGE_PASSWORD_INITIALIZE, $event); - - if (null !== $event->getResponse()) { - return $event->getResponse(); - } - - /** @var $formFactory \FOS\UserBundle\Form\Factory\FactoryInterface */ - $formFactory = $this->get('fos_user.change_password.form.factory'); - - $form = $formFactory->createForm(); - $form->setData($user); - - $form->handleRequest($request); - - if ($form->isValid()) { - /** @var $userManager \FOS\UserBundle\Model\UserManagerInterface */ - $userManager = $this->get('fos_user.user_manager'); - - $event = new FormEvent($form, $request); - $dispatcher->dispatch(FOSUserEvents::CHANGE_PASSWORD_SUCCESS, $event); - - $userManager->updateUser($user); - - if (null === $response = $event->getResponse()) { - $url = $this->generateUrl('fos_user_profile_show'); - $response = new RedirectResponse($url); - } - - $dispatcher->dispatch(FOSUserEvents::CHANGE_PASSWORD_COMPLETED, new FilterUserResponseEvent($user, $request, $response)); - - return $response; - } - - return $this->render('SyliusWebBundle:Frontend/Account:Profile/changePassword.html.twig', array( - 'form' => $form->createView() - )); - } - - protected function getCustomer() - { - return $this->get('sylius.context.customer')->getCustomer(); - } -} \ No newline at end of file diff --git a/src/Sylius/Bundle/WebBundle/Resources/config/routing/backend/order.yml b/src/Sylius/Bundle/WebBundle/Resources/config/routing/backend/order.yml index aa51f6274a..9208e3583c 100644 --- a/src/Sylius/Bundle/WebBundle/Resources/config/routing/backend/order.yml +++ b/src/Sylius/Bundle/WebBundle/Resources/config/routing/backend/order.yml @@ -73,13 +73,13 @@ sylius_backend_order_show: method: findForDetailsPage arguments: [$id] -sylius_backend_order_by_user: +sylius_backend_order_by_customer: path: /u/{id} methods: [GET] defaults: - _controller: sylius.controller.order:indexByUserAction + _controller: sylius.controller.order:indexByCustomerAction _sylius: - template: SyliusWebBundle:Backend/Order:indexByUser.html.twig + template: SyliusWebBundle:Backend/Order:indexByCustomer.html.twig sortable: true sorting: { updatedAt: desc } diff --git a/src/Sylius/Bundle/WebBundle/Resources/translations/messages.en.yml b/src/Sylius/Bundle/WebBundle/Resources/translations/messages.en.yml index 9b3ad718e4..cf7432c743 100644 --- a/src/Sylius/Bundle/WebBundle/Resources/translations/messages.en.yml +++ b/src/Sylius/Bundle/WebBundle/Resources/translations/messages.en.yml @@ -564,7 +564,7 @@ sylius: taxes: Taxes total: Total update_header: Editing order - user: User + customer: Customer currency: Currency state: State immutable_warning: Already shipped orders are immutable. diff --git a/src/Sylius/Bundle/WebBundle/Resources/views/Backend/Order/indexByUser.html.twig b/src/Sylius/Bundle/WebBundle/Resources/views/Backend/Order/indexByCustomer.html.twig similarity index 73% rename from src/Sylius/Bundle/WebBundle/Resources/views/Backend/Order/indexByUser.html.twig rename to src/Sylius/Bundle/WebBundle/Resources/views/Backend/Order/indexByCustomer.html.twig index 1964d70fcf..e248b36e0d 100644 --- a/src/Sylius/Bundle/WebBundle/Resources/views/Backend/Order/indexByUser.html.twig +++ b/src/Sylius/Bundle/WebBundle/Resources/views/Backend/Order/indexByCustomer.html.twig @@ -1,5 +1,5 @@ {% from 'SyliusWebBundle:Backend/Macros:misc.html.twig' import pagination %} {% from 'SyliusWebBundle:Backend/Order:macros.html.twig' import list %} -{{ list(orders, user) }} -{{ pagination(orders, {'routeName' : 'sylius_backend_user_show', 'routeParams' : {'id' : user.id} }) }} +{{ list(orders, customer) }} +{{ pagination(orders, {'routeName' : 'sylius_backend_user_show', 'routeParams' : {'id' : customer.user.id} }) }} diff --git a/src/Sylius/Bundle/WebBundle/Resources/views/Backend/Order/macros.html.twig b/src/Sylius/Bundle/WebBundle/Resources/views/Backend/Order/macros.html.twig index 7e894cdf1e..75d7af5d4a 100644 --- a/src/Sylius/Bundle/WebBundle/Resources/views/Backend/Order/macros.html.twig +++ b/src/Sylius/Bundle/WebBundle/Resources/views/Backend/Order/macros.html.twig @@ -4,7 +4,7 @@ {% import 'SyliusWebBundle:Backend/Macros:alerts.html.twig' as alerts %} {% import 'SyliusWebBundle:Backend/Macros:misc.html.twig' as misc %} -{% set router_paramters = customer is not null ? {'id' : customer.user.id} : {} %} +{% set router_paramters = customer is not null ? {'id' : customer.id} : {} %} {% if orders|length > 0 %} @@ -41,13 +41,10 @@ {% include 'SyliusWebBundle:Backend/Order:_shippingState.html.twig' %} @@ -104,13 +101,13 @@ {% include 'SyliusWebBundle:Backend/Order:_paymentState.html.twig' %} diff --git a/src/Sylius/Bundle/WebBundle/Resources/views/Backend/User/show.html.twig b/src/Sylius/Bundle/WebBundle/Resources/views/Backend/User/show.html.twig index e536ce315d..a58889d10b 100644 --- a/src/Sylius/Bundle/WebBundle/Resources/views/Backend/User/show.html.twig +++ b/src/Sylius/Bundle/WebBundle/Resources/views/Backend/User/show.html.twig @@ -6,7 +6,7 @@ {% endblock %} @@ -19,7 +19,7 @@ {{ buttons.manage(path('sylius_backend_user_index'), 'sylius.user.manage'|trans) }} {% if not user.deleted %} {{ buttons.edit(path('sylius_backend_user_update', {'id': user.id})) }} - {% if user.username is not sameas(app.user.username) %} + {% if user.id is not sameas(app.user.id) %} {{ buttons.delete(path('sylius_backend_user_delete', {'id': user.id}), null, false, false) }} {% endif %} {% endif %} @@ -40,16 +40,16 @@ - {% if user.firstName %} + {% if user.customer.firstName %} - + {% endif %} - {% if user.lastName %} + {% if user.customer.lastName %} - + {% endif %} @@ -58,7 +58,7 @@ - + @@ -77,9 +77,9 @@
- {% if order.customer %} + {% if order.customer.user %}

{{ order.customer.fullName }}
{{ order.customer.email }}

{% else %} -

- {{ order.billingAddress.firstName }} {{ order.billingAddress.lastName }}
- {{ order.email }} -

+

{{ order.customer.fullName }}
{{ order.customer.email }}

{% endif %}
{{ order.total|sylius_price(order.currency) }} - {% if order.customer %} + {% if order.customer.user %} {{ order.customer.fullname }}
{{ order.customer.email }} {% else %} - {{ order.billingAddress.firstName }} {{ order.billingAddress.lastName }} + {{ order.customer.fullname }}
{{ order.email }} {% endif %}
{{ 'sylius.user.id'|trans }} {{ user.id }}
{{ 'sylius.user.first_name'|trans }}{{ user.firstName }}{{ user.customer.firstName }}
{{ 'sylius.user.last_name'|trans }}{{ user.lastName }}{{ user.customer.lastName }}
{{ 'sylius.user.email'|trans }}{{ user.email }}{{ user.customer.email }}
{{ 'sylius.user.enabled'|trans }}
{{ 'sylius.user.groups'|trans }} - {% if user.groups|length > 0 %} + {% if user.customer.groups|length > 0 %}
    - {% for group in user.groups %} + {% for group in user.customer.groups %}
  • {{ group.name }}
  • {% endfor %}
@@ -121,23 +121,23 @@
- {% if user.shippingAddress %} + {% if user.customer.shippingAddress %}

{{ 'sylius.user.shipping_address'|trans }}

- {% include 'SyliusWebBundle:Backend/Address:_show.html.twig' with {'address': user.shippingAddress } %} + {% include 'SyliusWebBundle:Backend/Address:_show.html.twig' with {'address': user.customer.shippingAddress } %}
{% endif %} - {% if user.billingAddress %} + {% if user.customer.billingAddress %}

{{ 'sylius.user.billing_address'|trans }}

- {% include 'SyliusWebBundle:Backend/Address:_show.html.twig' with {'address': user.billingAddress } %} + {% include 'SyliusWebBundle:Backend/Address:_show.html.twig' with {'address': user.customer.billingAddress } %}
{% endif %}
- {% render(url('sylius_backend_order_by_user', app.request.query.all|merge({id: user.id}) )) %} + {% render(url('sylius_backend_order_by_customer', app.request.query.all|merge({id: user.customer.id}) )) %}
diff --git a/src/Sylius/Bundle/WebBundle/Resources/views/Frontend/Account/Profile/edit.html.twig b/src/Sylius/Bundle/WebBundle/Resources/views/Frontend/Account/Profile/edit.html.twig index 9b3bc09ff8..be9bc81980 100644 --- a/src/Sylius/Bundle/WebBundle/Resources/views/Frontend/Account/Profile/edit.html.twig +++ b/src/Sylius/Bundle/WebBundle/Resources/views/Frontend/Account/Profile/edit.html.twig @@ -7,7 +7,7 @@

{{ 'sylius.form.frontend.profile.title'|trans }}


-
+
{{ form_widget(form) }}
diff --git a/src/Sylius/Component/Core/Model/User.php b/src/Sylius/Component/Core/Model/User.php index 1628bf633b..ceef0ce912 100644 --- a/src/Sylius/Component/Core/Model/User.php +++ b/src/Sylius/Component/Core/Model/User.php @@ -29,10 +29,15 @@ class User extends BaseUser implements UserInterface public function __construct() { parent::__construct(); - $this->customer = new Customer(); $this->authorizationRoles = new ArrayCollection(); } + protected function initializeCustomer() + { + $this->customer = new Customer(); + $this->customer->setUser($this); + } + /** * {@inheritdoc} */ diff --git a/src/Sylius/Component/User/Model/User.php b/src/Sylius/Component/User/Model/User.php index 6e7cfef9f5..fbe35f048c 100644 --- a/src/Sylius/Component/User/Model/User.php +++ b/src/Sylius/Component/User/Model/User.php @@ -104,14 +104,10 @@ class User implements UserInterface protected $credentialsExpireAt; /** - * @var Collection - */ - protected $groups; - - /** + * We need at least one role to be able to authenticate * @var array */ - protected $roles = array(); + protected $roles = array(UserInterface::DEFAULT_ROLE); /** * @var Collection @@ -135,12 +131,18 @@ class User implements UserInterface public function __construct() { - $this->customer = new Customer(); + $this->initializeCustomer(); $this->salt = base_convert(sha1(uniqid(mt_rand(), true)), 16, 36); $this->oauthAccounts = new ArrayCollection(); $this->createdAt = new \DateTime(); } + protected function initializeCustomer() + { + $this->customer = new Customer(); + $this->customer->setUser($this); + } + /** * {@inheritdoc} */ diff --git a/src/Sylius/Component/User/Model/UserInterface.php b/src/Sylius/Component/User/Model/UserInterface.php index a15df9caf3..f9d96208ca 100644 --- a/src/Sylius/Component/User/Model/UserInterface.php +++ b/src/Sylius/Component/User/Model/UserInterface.php @@ -27,6 +27,7 @@ use Symfony\Component\Security\Core\User\AdvancedUserInterface; */ interface UserInterface extends AdvancedUserInterface, \Serializable, TimestampableInterface, SoftDeletableInterface { + const DEFAULT_ROLE = 'ROLE_USER'; /** * @return int */