Removed FOSUserBundle and all its dependencies

This commit is contained in:
michalmarcinkowski 2015-05-03 00:49:54 +02:00
parent 2137205d06
commit d8adae821a
78 changed files with 619 additions and 879 deletions

View file

@ -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

View file

@ -1,20 +0,0 @@
# Security
security:
login:
email: "Email:"
header: <h1>Login <small>Sylius store</small></h1>
info: Please login using "<strong>sylius@example.com</strong>" email and "<strong>sylius</strong>" as password.
forgot_password: Forgot password?
no_account: No account yet?
# Registration
registration:
register_header: <h1>Registration <small>Create an account in store</small></h1>
confirmed_header: <h1>Welcome <small>Your registration was successful</small></h1>
# Password resetting
resetting:
request:
header: <h1>Password reset request</h1>
reset:
header: <h1>Reset password</h1>

View file

@ -1,33 +0,0 @@
# Security
security:
login:
email: "Email"
header: <h1>Connexion <small>Boutique LVP</small></h1>
info: Connectez vous en utilisant l'email "<strong>sylius@example.com</strong>" et "<strong>sylius</strong>" 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: <h1>Enregistrement <small>Créer votre compte</small></h1>
confirmed_header: <h1>Bienvenue <small>Votre compte a été créé avec succès</small></h1>
# 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: <h1>Demande de réinitialisation de mot de passe</h1>
reset:
header: <h1>Réinitialiser votre mot de passe</h1>

View file

@ -1,5 +0,0 @@
{% extends 'SyliusWebBundle:Frontend/Account:layout.html.twig' %}
{% block content %}
{% include "SyliusWebBundle:Frontend/Account:_password.html.twig" %}
{% endblock %}

View file

@ -1,5 +0,0 @@
{% extends 'SyliusWebBundle:Frontend/Account:layout.html.twig' %}
{% block content %}
{% include "SyliusWebBundle:Frontend/Account:_profileEdit.html.twig" %}
{% endblock %}

View file

@ -1,5 +0,0 @@
{% extends 'SyliusWebBundle:Frontend/Account:layout.html.twig' %}
{% block content %}
{% include "SyliusWebBundle:Frontend/Account:_profile.html.twig" %}
{% endblock %}

View file

@ -1,14 +0,0 @@
{% extends 'SyliusWebBundle:Frontend:layout.html.twig' %}
{% trans_default_domain 'FOSUserBundle' %}
{% block content %}
<div class="page-header">
{{ 'registration.confirmed_header'|trans|raw }}
</div>
<hr />
<div class="alert alert-success">
{{ 'registration.confirmed'|trans({'%username%': user.firstName}) }}
</div>
{% endblock %}

View file

@ -1,23 +0,0 @@
{% extends 'SyliusWebBundle:Frontend:layout.html.twig' %}
{% trans_default_domain 'FOSUserBundle' %}
{% block content %}
<div class="page-header">
{{ 'registration.register_header'|trans|raw }}
</div>
<form action="{{ path('fos_user_registration_register') }}" method="post" class="form-horizontal" novalidate>
<fieldset class="well">
{% for field in form %}
{{ form_row(field) }}
{% endfor %}
</fieldset>
<div class="form-actions clearfix">
<div class="pull-right">
{{ render(url('hwi_oauth_connect')) }}
</div>
<button type="submit" class="btn btn-success btn-lg"><i class="icon-user"></i> {{ 'registration.submit'|trans }}</button>
</div>
</form>
{% endblock %}

View file

@ -1,9 +0,0 @@
{% extends 'SyliusWebBundle:Frontend:layout.html.twig' %}
{% trans_default_domain 'FOSUserBundle' %}
{% block content %}
<div class="alert alert-success">
{{ 'resetting.check_email'|trans({'%email%': email}) }}
</div>
{% endblock %}

View file

@ -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 %}

View file

@ -1,9 +0,0 @@
{% extends 'SyliusWebBundle:Frontend:layout.html.twig' %}
{% trans_default_domain 'FOSUserBundle' %}
{% block content %}
<div class="alert alert-info">
{{ 'resetting.password_already_requested'|trans }}
</div>
{% endblock %}

View file

@ -1,10 +0,0 @@
{% extends 'SyliusWebBundle:Frontend:layout.html.twig' %}
{% trans_default_domain 'FOSUserBundle' %}
{% block content %}
<div class="page-header">
{{ 'resetting.request.header'|trans|raw }}
</div>
{% include "FOSUserBundle:Resetting:request_content.html.twig" %}
{% endblock content %}

View file

@ -1,22 +0,0 @@
{% trans_default_domain 'FOSUserBundle' %}
{% if invalid_username is defined %}
<div class="alert alert-danger">
{{ 'resetting.request.invalid_username'|trans({'%username%': invalid_username}) }}
</div>
{% endif %}
<form action="{{ path('fos_user_resetting_send_email') }}" method="POST" class="fos_user_resetting_request form-horizontal">
<fieldset>
<div class="form-group">
<label for="username" class="col-sm-3 control-label">{{ 'security.login.email'|trans }}</label>
<div class="col-sm-9">
<input type="text" id="username" name="username" required="required" class="form-control" />
</div>
</div>
</fieldset>
<div class="form-actions clearfix">
<button type="submit" class="btn btn-primary btn-lg" name="login"><i class="icon-lock"></i> {{ 'resetting.request.submit'|trans }}</button>
</div>
</form>

View file

@ -1,10 +0,0 @@
{% extends 'SyliusWebBundle:Frontend:layout.html.twig' %}
{% trans_default_domain 'FOSUserBundle' %}
{% block content %}
<div class="page-header">
{{ 'resetting.reset.header'|trans|raw }}
</div>
{% include "FOSUserBundle:Resetting:reset_content.html.twig" %}
{% endblock content %}

View file

@ -1,14 +0,0 @@
{% trans_default_domain 'FOSUserBundle' %}
<form action="{{ path('fos_user_resetting_reset', {'token': token}) }}" {{ form_enctype(form) }} method="POST" class="fos_user_resetting_reset form-horizontal">
<fieldset>
<div class="form-group">
<div class="col-sm-9">
{{ form_widget(form) }}
</div>
</div>
</fieldset>
<div class="form-actions clearfix">
<button type="submit" class="btn btn-primary btn-lg" name="login"><i class="icon-lock"></i> {{ 'resetting.reset.submit'|trans }}</button>
</div>
</form>

View file

@ -1,59 +0,0 @@
{% extends 'SyliusWebBundle:Frontend:layout.html.twig' %}
{% trans_default_domain 'FOSUserBundle' %}
{% block content %}
<div class="page-header">
{{ 'security.login.header'|trans|raw }}
</div>
{% if error %}
<div class="alert alert-danger">
{{ error.messageKey|trans(error.messageData, 'security') }}
</div>
{% endif %}
<blockquote>
<p>{{ 'security.login.info'|trans|raw }}</p>
<small>Mr. Sylius Demo Guide</small>
</blockquote>
<form action="{{ path('fos_user_security_check') }}" method="post" class="form-horizontal">
<fieldset>
<div class="form-group">
<label for="username" class="col-sm-3 control-label">{{ 'security.login.email'|trans }}</label>
<div class="col-sm-9">
<input type="text" id="username" name="_username" value="{{ last_username }}" class="form-control" />
</div>
</div>
<div class="form-group">
<label for="password" class="col-sm-3 control-label">{{ 'security.login.password'|trans }}</label>
<div class="col-sm-9">
<input type="password" id="password" name="_password" class="form-control" />
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-3 col-sm-9">
<div class="checkbox">
<label for="remember_me">
{{ 'security.login.remember_me'|trans }} &nbsp; <input type="checkbox" id="remember_me" name="_remember_me" value="on" />
</label>
</div>
</div>
</div>
<div class="pull-right">
<p>
<a href="{{ path('fos_user_resetting_request') }}" class="btn btn-info btn-sm">{{ 'security.login.forgot_password'|trans }}</a>
<a href="{{ path('fos_user_registration_register') }}" class="btn btn-primary btn-sm">{{ 'security.login.no_account'|trans }}</a>
</p>
</div>
</fieldset>
<div class="form-actions clearfix">
<div class="pull-right">
{{ render(url('hwi_oauth_connect')) }}
</div>
<button type="submit" class="btn btn-primary btn-lg" name="login"><i class="icon-lock"></i> {{ 'security.login.submit'|trans }}</button>
</div>
</form>
{% endblock %}

View file

@ -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",

76
composer.lock generated
View file

@ -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": []
}

View file

@ -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

View file

@ -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 |

View file

@ -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

View file

@ -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"

View file

@ -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

View file

@ -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"

View file

@ -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"

View file

@ -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 <pawel@sylius.org>
*/

View file

@ -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'
),
));
}

View file

@ -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);
}
}

View file

@ -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();
}
}

View file

@ -42,9 +42,9 @@ class FinalizeStep extends CheckoutStep
{
$order = $this->getCurrentCart();
$this->dispatchCheckoutEvent(SyliusCheckoutEvents::FINALIZE_INITIALIZE, $order);
$this->completeOrder($order);
return $this->complete();
}

View file

@ -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();
}
}

View file

@ -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
));
}

View file

@ -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;
}

View file

@ -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,
));
}

View file

@ -82,7 +82,7 @@ class AddressingStepType extends AbstractResourceType
$resolver
->setDefaults(array(
'user' => null,
'customer' => null,
'cascade_validation' => true
))
;

View file

@ -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',
))
;
}

View file

@ -0,0 +1,37 @@
<?php
/*
* This file is part of the Sylius package.
*
* (c) Paweł Jędrzejewski
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Sylius\Bundle\CoreBundle\Form\Type;
use Sylius\Bundle\UserBundle\Form\Type\UserType as BaseUserType;
use Symfony\Component\Form\FormBuilderInterface;
/**
* @author Michał Marcinkowski <michal.marcinkowski@lakion.com>
*/
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
))
;
}
}

View file

@ -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(),

View file

@ -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:

View file

@ -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

View file

@ -62,6 +62,9 @@
<many-to-one field="customer" target-entity="Sylius\Component\User\Model\CustomerInterface" inversed-by="orders">
<join-column name="customer_id" referenced-column-name="id" nullable="true" />
<cascade>
<cascade-persist />
</cascade>
</many-to-one>
<many-to-many field="promotions" target-entity="Sylius\Component\Promotion\Model\PromotionInterface">

View file

@ -74,9 +74,9 @@
<tag name="form.type" alias="sylius_checkout_payment" />
</service>
<service id="sylius.checkout_form.guest" class="%sylius.checkout_form.guest.class%">
<argument>%sylius.model.cart.class%</argument>
<argument>%sylius.model.customer.class%</argument>
<argument type="collection">
<argument>Guest</argument>
<argument>guest</argument>
</argument>
<tag name="form.type" alias="sylius_checkout_guest" />
</service>

View file

@ -25,8 +25,8 @@
<argument type="service" id="sylius.email_sender" />
<tag name="kernel.event_listener" event="sylius.checkout.finalize.complete" method="sendOrderConfirmationEmail" />
<tag name="kernel.event_listener" event="sylius.shipment.post_update" method="sendShipmentConfirmationEmail" />
<tag name="kernel.event_listener" event="fos_user.registration.completed" method="sendUserConfirmationEmail" />
<tag name="kernel.event_listener" event="fos_user.registration.confirmed" method="sendUserConfirmationEmail" />
<tag name="kernel.event_listener" event="sylius.user.post_create" method="sendUserConfirmationEmail" />
<tag name="kernel.event_listener" event="sylius.user.post_register" method="sendUserConfirmationEmail" />
<tag name="kernel.event_listener" event="sylius.comment.post_create" method="sendOrderCommentEmail" />
</service>
</services>

View file

@ -0,0 +1,53 @@
<?php
/*
* This file is part of the Sylius package.
*
* (c) Paweł Jędrzejewski
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace spec\Sylius\Bundle\CoreBundle\Form\Type;
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
use Sylius\Component\User\Canonicalizer\CanonicalizerInterface;
use Symfony\Component\Form\FormBuilderInterface;
/**
* @author Michał Marcinkowski <michal.marcinkowski@lakion.com>
*/
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());
}
}

View file

@ -438,7 +438,6 @@ class ResourceController extends FOSRestController
)
);
}
return $resource;
}

View file

@ -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()

View file

@ -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'))
;
}
}

View file

@ -0,0 +1,49 @@
<?php
/*
* This file is part of the Sylius package.
*
* (c) Paweł Jędrzejewski
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Sylius\Bundle\UserBundle\Doctrine\ORM;
use Pagerfanta\PagerfantaInterface;
use Sylius\Bundle\ResourceBundle\Doctrine\ORM\EntityRepository;
use Sylius\Component\Core\Model\UserInterface;
use Sylius\Component\User\Repository\UserRepositoryInterface;
/**
* @author Michał Marcinkowski <michal.marcinkowski@lakion.com>
*/
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;
}
}

View file

@ -17,16 +17,12 @@ use Sylius\Component\Core\Model\UserInterface;
use Sylius\Component\User\Repository\UserRepositoryInterface;
/**
* User repository.
*
* @author Saša Stamenković <umpirsky@gmail.com>
* @author Michał Marcinkowski <michal.marcinkowski@lakion.com>
*/
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)
;

View file

@ -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)

View file

@ -0,0 +1,53 @@
<?php
/*
* This file is part of the Sylius package.
*
* (c) Paweł Jędrzejewski
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Sylius\Bundle\UserBundle\EventListener;
use Doctrine\ORM\Event\LifecycleEventArgs;
use Sylius\Component\User\Model\CustomerInterface;
use Sylius\Component\User\Model\UserInterface;
/**
* Keeps user's username synchronized with email.
*
* @author Michał Marcinkowski <michal.marcinkowski@lakion.com>
*/
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);
}
}
}

View file

@ -1,47 +0,0 @@
<?php
/*
* This file is part of the Sylius package.
*
* (c) Paweł Jędrzejewski
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Sylius\Bundle\UserBundle\Form\EventListener;
use Sylius\Component\Resource\Exception\UnexpectedTypeException;
use Sylius\Component\User\Canonicalizer\CanonicalizerInterface;
use Sylius\Component\User\Model\UserInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\Form\FormEvent;
use Symfony\Component\Form\FormEvents;
/**
* @author Łukasz Chruściel <lukasz.chrusciel@lakion.com>
*/
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()));
}
}

View file

@ -0,0 +1,40 @@
<?php
/*
* This file is part of the Lakion package.
*
* (c) Lakion
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Sylius\Bundle\UserBundle\Form\EventListener;
use Sylius\Component\User\Model\UserInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\Form\Exception\UnexpectedTypeException;
use Symfony\Component\Form\FormEvent;
use Symfony\Component\Form\FormEvents;
/**
* @author Michał Marcinkowski <michal.marcinkowski@lakion.com>
*/
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);
}
}

View file

@ -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 <lukasz.chrusciel@lakion.com>
*/
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}
*/

View file

@ -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 <lukasz.chrusciel@lakion.com>
*/
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}
*/

View file

@ -19,6 +19,7 @@
<parameters>
<parameter key="sylius.repository.group.class">Sylius\Bundle\UserBundle\Doctrine\ORM\GroupRepository</parameter>
<parameter key="sylius.repository.user.class">Sylius\Bundle\UserBundle\Doctrine\ORM\UserRepository</parameter>
<parameter key="sylius.repository.customer.class">Sylius\Bundle\UserBundle\Doctrine\ORM\CustomerRepository</parameter>
<parameter key="sylius.form.type.user_choice.class">Sylius\Bundle\UserBundle\Form\Type\UserEntityType</parameter>
<parameter key="sylius.form.type.group_choice.class">Sylius\Bundle\UserBundle\Form\Type\GroupEntityType</parameter>
</parameters>

View file

@ -40,6 +40,7 @@
<parameter key="sylius.form.type.user_reset_password.class">Sylius\Bundle\UserBundle\Form\Type\UserResetPasswordType</parameter>
<parameter key="sylius.form.type.user_change_password.class">Sylius\Bundle\UserBundle\Form\Type\UserChangePasswordType</parameter>
<parameter key="sylius.listener.default_username.class">Sylius\Bundle\UserBundle\EventListener\DefaultUsernameListener</parameter>
<parameter key="sylius.listener.customer_aware.class">Sylius\Bundle\UserBundle\EventListener\CustomerAwareListener</parameter>
<parameter key="sylius.listener.user_delete.class">Sylius\Bundle\UserBundle\EventListener\UserDeleteListener</parameter>
<parameter key="sylius.listener.canonicalizer.class">Sylius\Bundle\UserBundle\EventListener\CanonicalizerListener</parameter>
@ -96,8 +97,9 @@
</service>
<!-- Listeners -->
<service id="sylius.listener.customer_aware" class="%sylius.listener.customer_aware.class%">
<argument type="service" id="sylius.context.customer" />
<service id="sylius.listener.default_username" class="%sylius.listener.default_username.class%">
<tag name="doctrine.event_listener" event="prePersist" priority="10" />
<tag name="doctrine.event_listener" event="preUpdate" priority="10" />
</service>
<service id="sylius.listener.user_login" class="%sylius.listener.user_login.class%">
<argument type="service" id="sylius.security.user_login" />

View file

@ -17,72 +17,82 @@
http://symfony.com/schema/dic/services/constraint-mapping-1.0.xsd">
<class name="Sylius\Component\User\Model\Customer">
<constraint name="Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity">
<option name="message">sylius.customer.email.unique</option>
<option name="fields">email</option>
<option name="groups">sylius</option>
</constraint>
<property name="firstName">
<constraint name="NotBlank">
<option name="message">sylius.customer.first_name.not_blank</option>
<option name="groups"><value>sylius</value></option>
<option name="groups">sylius</option>
</constraint>
<constraint name="Length">
<option name="min">2</option>
<option name="minMessage">sylius.customer.first_name.min</option>
<option name="max">255</option>
<option name="maxMessage">sylius.customer.first_name.max</option>
<option name="groups"><value>sylius</value></option>
<option name="groups">sylius</option>
</constraint>
</property>
<property name="lastName">
<constraint name="NotBlank">
<option name="message">sylius.customer.last_name.not_blank</option>
<option name="groups"><value>sylius</value></option>
<option name="groups">sylius</option>
</constraint>
<constraint name="Length">
<option name="min">2</option>
<option name="minMessage">sylius.customer.last_name.min</option>
<option name="max">255</option>
<option name="maxMessage">sylius.customer.last_name.max</option>
<option name="groups"><value>sylius</value></option>
<option name="groups">sylius</option>
</constraint>
</property>
<property name="email">
<constraint name="NotBlank">
<option name="message">sylius.customer.email.not_blank</option>
<option name="groups">sylius</option>
<option name="groups">
<value>sylius</value>
<value>guest</value>
</option>
</constraint>
<constraint name="Length">
<option name="min">2</option>
<option name="minMessage">sylius.customer.email.min</option>
<option name="max">254</option>
<option name="maxMessage">sylius.customer.email.max</option>
<option name="groups">sylius</option>
<option name="groups">
<value>sylius</value>
<value>guest</value>
</option>
</constraint>
<constraint name="Email">
<option name="message">sylius.customer.email.invalid</option>
<option name="groups">sylius</option>
<option name="groups">
<value>sylius</value>
<value>guest</value>
</option>
</constraint>
</property>
</class>
<class name="Sylius\Component\User\Model\User">
<!--<property name="email">-->
<!--<constraint name="NotBlank">-->
<!--<option name="message">sylius.user.email.not_blank</option>-->
<!--<option name="groups">sylius</option>-->
<!--</constraint>-->
<!--<constraint name="Length">-->
<!--<option name="min">2</option>-->
<!--<option name="minMessage">sylius.user.email.min</option>-->
<!--<option name="max">254</option>-->
<!--<option name="maxMessage">sylius.user.email.max</option>-->
<!--<option name="groups">sylius</option>-->
<!--</constraint>-->
<!--<constraint name="Email">-->
<!--<option name="message">sylius.user.email.invalid</option>-->
<!--<option name="groups">sylius</option>-->
<!--</constraint>-->
<!--</property>-->
<property name="plainPassword">
<constraint name="NotBlank">
<option name="groups">sylius</option>
<option name="groups">
<value>registration</value>
<value>user_create</value>
</option>
</constraint>
<constraint name="Length">
<option name="min">4</option>
<option name="minMessage">sylius.user.password.min</option>
<option name="max">254</option>
<option name="maxMessage">sylius.user.password.max</option>
<option name="groups">
<value>registration</value>
<value>user_create</value>
</option>
</constraint>
</property>
</class>

View file

@ -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.
invalid: This email is invalid.
unique: This email is already used.

View file

@ -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));
}
}

View file

@ -20,6 +20,8 @@ interface UserLoginInterface
{
/**
* Log in user.
*
* @param UserInterface $user
*/
public function login(UserInterface $user);
}

View file

@ -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);
}

View file

@ -1,62 +0,0 @@
<?php
/*
* This file is part of the Sylius package.
*
* (c) Paweł Jędrzejewski
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace spec\Sylius\Bundle\UserBundle\Form\EventListener;
use PhpSpec\ObjectBehavior;
use Sylius\Component\Resource\Exception\UnexpectedTypeException;
use Sylius\Component\User\Canonicalizer\CanonicalizerInterface;
use Sylius\Component\User\Model\UserInterface;
use Symfony\Component\Form\FormEvent;
/**
* @author Łukasz Chruściel <lukasz.chrusciel@lakion.com>
*/
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);
}
}

View file

@ -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);

View file

@ -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);

View file

@ -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);
}

View file

@ -749,7 +749,7 @@ class WebContext extends DefaultContext implements SnippetAcceptingContext
$this->fillField('Email', $email);
$this->fillField('Password', $password);
$this->pressButton('login');
$this->pressButton('Login');
}
/**

View file

@ -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()

View file

@ -1,152 +0,0 @@
<?php
/**
* Created by PhpStorm.
* User: joeri.timmermans
* Date: 19/02/15
* Time: 10:37
*/
namespace Sylius\Bundle\WebBundle\Controller\Frontend\Account;
use FOS\RestBundle\Controller\FOSRestController;
use FOS\UserBundle\Model\UserInterface;
use FOS\UserBundle\FOSUserEvents;
use FOS\UserBundle\Event\FormEvent;
use FOS\UserBundle\Event\FilterUserResponseEvent;
use FOS\UserBundle\Event\GetResponseUserEvent;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
class ProfileController extends FOSRestController
{
/**
* Show the user
*/
public function indexAction()
{
$customer = $this->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();
}
}

View file

@ -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 }

View file

@ -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.

View file

@ -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} }) }}

View file

@ -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 %}
<table id="orders" class="table">
@ -41,13 +41,10 @@
{% include 'SyliusWebBundle:Backend/Order:_shippingState.html.twig' %}
</td>
<td>
{% if order.customer %}
{% if order.customer.user %}
<p>{{ order.customer.fullName }} <br><a href="{{ path('sylius_backend_user_show', {'id': order.customer.user.id}) }}">{{ order.customer.email }}</a></p>
{% else %}
<p>
{{ order.billingAddress.firstName }} {{ order.billingAddress.lastName }}<br>
<span title="{{ 'sylius.order.guest'|trans }}">{{ order.email }}</span>
</p>
<p>{{ order.customer.fullName }} <br><span title="{{ 'sylius.order.guest'|trans }}">{{ order.customer.email }}</span></p>
{% endif %}
</td>
<td>{{ order.total|sylius_price(order.currency) }}</td>
@ -104,13 +101,13 @@
{% include 'SyliusWebBundle:Backend/Order:_paymentState.html.twig' %}
</td>
<td style="width: 20%">
{% if order.customer %}
{% if order.customer.user %}
{{ order.customer.fullname }}<br>
<a href="{{ path('sylius_backend_user_show', {'id': order.customer.user.id}) }}">
{{ order.customer.email }}
</a>
{% else %}
{{ order.billingAddress.firstName }} {{ order.billingAddress.lastName }}
{{ order.customer.fullname }}<br>
<span title="{{ 'sylius.order.guest'|trans }}">{{ order.email }}</span>
{% endif %}
</td>

View file

@ -6,7 +6,7 @@
<ol class="breadcrumb">
<li>{{ 'sylius.breadcrumb.customers'|trans }}</li>
<li><a href="{{ path('sylius_backend_user_index') }}">{{ 'sylius.breadcrumb.user.index'|trans }}</a></li>
<li>{{ user.fullName }}</li>
<li>{{ user.customer.fullName }}</li>
</ol>
{% 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 @@
<td><strong>{{ 'sylius.user.id'|trans }}</strong></td>
<td>{{ user.id }}</td>
</tr>
{% if user.firstName %}
{% if user.customer.firstName %}
<tr>
<td><strong>{{ 'sylius.user.first_name'|trans }}</strong></td>
<td>{{ user.firstName }}</td>
<td>{{ user.customer.firstName }}</td>
</tr>
{% endif %}
{% if user.lastName %}
{% if user.customer.lastName %}
<tr>
<td><strong>{{ 'sylius.user.last_name'|trans }}</strong></td>
<td>{{ user.lastName }}</td>
<td>{{ user.customer.lastName }}</td>
</tr>
{% endif %}
<tr>
@ -58,7 +58,7 @@
</tr>
<tr>
<td><strong>{{ 'sylius.user.email'|trans }}</strong></td>
<td>{{ user.email }}</td>
<td>{{ user.customer.email }}</td>
</tr>
<tr>
<td><strong>{{ 'sylius.user.enabled'|trans }}</strong></td>
@ -77,9 +77,9 @@
<tr>
<td><strong>{{ 'sylius.user.groups'|trans }}</strong></td>
<td>
{% if user.groups|length > 0 %}
{% if user.customer.groups|length > 0 %}
<ul>
{% for group in user.groups %}
{% for group in user.customer.groups %}
<li>{{ group.name }}</li>
{% endfor %}
</ul>
@ -121,23 +121,23 @@
</div>
<div class="row">
{% if user.shippingAddress %}
{% if user.customer.shippingAddress %}
<div class="col-md-6">
<h4>{{ 'sylius.user.shipping_address'|trans }}</h4>
{% include 'SyliusWebBundle:Backend/Address:_show.html.twig' with {'address': user.shippingAddress } %}
{% include 'SyliusWebBundle:Backend/Address:_show.html.twig' with {'address': user.customer.shippingAddress } %}
</div>
{% endif %}
{% if user.billingAddress %}
{% if user.customer.billingAddress %}
<div class="col-md-6">
<h4>{{ 'sylius.user.billing_address'|trans }}</h4>
{% include 'SyliusWebBundle:Backend/Address:_show.html.twig' with {'address': user.billingAddress } %}
{% include 'SyliusWebBundle:Backend/Address:_show.html.twig' with {'address': user.customer.billingAddress } %}
</div>
{% endif %}
</div>
<div class="row">
<div class="col-md-12">
{% 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}) )) %}
</div>
</div>

View file

@ -7,7 +7,7 @@
<h4>{{ 'sylius.form.frontend.profile.title'|trans }}</h4>
<br>
<form action="{{ path('fos_user_profile_edit') }}" {{ form_enctype(form) }} method="POST" class="form-horizontal">
<form action="{{ path('sylius_user_profile_update') }}" {{ form_enctype(form) }} method="POST" class="form-horizontal">
<fieldset>
{{ form_widget(form) }}
</fieldset>

View file

@ -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}
*/

View file

@ -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}
*/

View file

@ -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
*/