diff --git a/app/AppKernel.php b/app/AppKernel.php index 16812c1..8b07f3e 100644 --- a/app/AppKernel.php +++ b/app/AppKernel.php @@ -18,6 +18,8 @@ class AppKernel extends Kernel new Doctrine\Bundle\DoctrineCacheBundle\DoctrineCacheBundle(), new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(), new \Snc\RedisBundle\SncRedisBundle(), + new \HWI\Bundle\OAuthBundle\HWIOAuthBundle(), + new \FOS\UserBundle\FOSUserBundle(), new Sikofitt\DoughnutWeddingBundle\SikofittDoughnutWeddingBundle(), ]; diff --git a/app/Resources/FOSUserBundle/views/ChangePassword/change_password.html.twig b/app/Resources/FOSUserBundle/views/ChangePassword/change_password.html.twig new file mode 100644 index 0000000..cdcd10d --- /dev/null +++ b/app/Resources/FOSUserBundle/views/ChangePassword/change_password.html.twig @@ -0,0 +1,5 @@ +{% extends "@FOSUser/layout.html.twig" %} + +{% block fos_user_content %} +{% include "@FOSUser/ChangePassword/change_password_content.html.twig" %} +{% endblock fos_user_content %} diff --git a/app/Resources/FOSUserBundle/views/ChangePassword/change_password_content.html.twig b/app/Resources/FOSUserBundle/views/ChangePassword/change_password_content.html.twig new file mode 100644 index 0000000..6c3d0cc --- /dev/null +++ b/app/Resources/FOSUserBundle/views/ChangePassword/change_password_content.html.twig @@ -0,0 +1,8 @@ +{% trans_default_domain 'FOSUserBundle' %} + +{{ form_start(form, { 'action': path('fos_user_change_password'), 'attr': { 'class': 'fos_user_change_password' } }) }} + {{ form_widget(form) }} +
{{ 'group.show.name'|trans }}: {{ group.getName() }}
+{{ 'profile.show.username'|trans }}: {{ user.username }}
+{{ 'profile.show.email'|trans }}: {{ user.email }}
+{{ 'registration.check_email'|trans({'%email%': user.email}) }}
+{% endblock fos_user_content %} diff --git a/app/Resources/FOSUserBundle/views/Registration/confirmed.html.twig b/app/Resources/FOSUserBundle/views/Registration/confirmed.html.twig new file mode 100644 index 0000000..4402b4f --- /dev/null +++ b/app/Resources/FOSUserBundle/views/Registration/confirmed.html.twig @@ -0,0 +1,10 @@ +{% extends "@FOSUser/layout.html.twig" %} + +{% trans_default_domain 'FOSUserBundle' %} + +{% block fos_user_content %} +{{ 'registration.confirmed'|trans({'%username%': user.username}) }}
+ {% if targetUrl %} +{{ 'registration.back'|trans }}
+ {% endif %} +{% endblock fos_user_content %} diff --git a/app/Resources/FOSUserBundle/views/Registration/email.txt.twig b/app/Resources/FOSUserBundle/views/Registration/email.txt.twig new file mode 100644 index 0000000..acbc685 --- /dev/null +++ b/app/Resources/FOSUserBundle/views/Registration/email.txt.twig @@ -0,0 +1,13 @@ +{% trans_default_domain 'FOSUserBundle' %} +{% block subject %} +{%- autoescape false -%} +{{ 'registration.email.subject'|trans({'%username%': user.username, '%confirmationUrl%': confirmationUrl}) }} +{%- endautoescape -%} +{% endblock %} + +{% block body_text %} +{% autoescape false %} +{{ 'registration.email.message'|trans({'%username%': user.username, '%confirmationUrl%': confirmationUrl}) }} +{% endautoescape %} +{% endblock %} +{% block body_html %}{% endblock %} diff --git a/app/Resources/FOSUserBundle/views/Registration/register.html.twig b/app/Resources/FOSUserBundle/views/Registration/register.html.twig new file mode 100644 index 0000000..92b6878 --- /dev/null +++ b/app/Resources/FOSUserBundle/views/Registration/register.html.twig @@ -0,0 +1,5 @@ +{% extends "@FOSUser/layout.html.twig" %} + +{% block fos_user_content %} +{% include "@FOSUser/Registration/register_content.html.twig" %} +{% endblock fos_user_content %} diff --git a/app/Resources/FOSUserBundle/views/Registration/register_content.html.twig b/app/Resources/FOSUserBundle/views/Registration/register_content.html.twig new file mode 100644 index 0000000..ecedeb9 --- /dev/null +++ b/app/Resources/FOSUserBundle/views/Registration/register_content.html.twig @@ -0,0 +1,8 @@ +{% trans_default_domain 'FOSUserBundle' %} + +{{ form_start(form, {'method': 'post', 'action': path('fos_user_registration_register'), 'attr': {'class': 'fos_user_registration_register'}}) }} + {{ form_widget(form) }} ++{{ 'resetting.check_email'|trans({'%tokenLifetime%': tokenLifetime})|nl2br }} +
+{% endblock %} diff --git a/app/Resources/FOSUserBundle/views/Resetting/email.txt.twig b/app/Resources/FOSUserBundle/views/Resetting/email.txt.twig new file mode 100644 index 0000000..bd52c9e --- /dev/null +++ b/app/Resources/FOSUserBundle/views/Resetting/email.txt.twig @@ -0,0 +1,13 @@ +{% trans_default_domain 'FOSUserBundle' %} +{% block subject %} +{%- autoescape false -%} +{{ 'resetting.email.subject'|trans({'%username%': user.username}) }} +{%- 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/request.html.twig b/app/Resources/FOSUserBundle/views/Resetting/request.html.twig new file mode 100644 index 0000000..87e7b41 --- /dev/null +++ b/app/Resources/FOSUserBundle/views/Resetting/request.html.twig @@ -0,0 +1,5 @@ +{% extends "@FOSUser/layout.html.twig" %} + +{% block fos_user_content %} +{% include "@FOSUser/Resetting/request_content.html.twig" %} +{% endblock fos_user_content %} diff --git a/app/Resources/FOSUserBundle/views/Resetting/request_content.html.twig b/app/Resources/FOSUserBundle/views/Resetting/request_content.html.twig new file mode 100644 index 0000000..3d1211b --- /dev/null +++ b/app/Resources/FOSUserBundle/views/Resetting/request_content.html.twig @@ -0,0 +1,11 @@ +{% trans_default_domain 'FOSUserBundle' %} + + diff --git a/app/Resources/FOSUserBundle/views/Resetting/reset.html.twig b/app/Resources/FOSUserBundle/views/Resetting/reset.html.twig new file mode 100644 index 0000000..fab676a --- /dev/null +++ b/app/Resources/FOSUserBundle/views/Resetting/reset.html.twig @@ -0,0 +1,5 @@ +{% extends "@FOSUser/layout.html.twig" %} + +{% block fos_user_content %} +{% include "@FOSUser/Resetting/reset_content.html.twig" %} +{% endblock fos_user_content %} diff --git a/app/Resources/FOSUserBundle/views/Resetting/reset_content.html.twig b/app/Resources/FOSUserBundle/views/Resetting/reset_content.html.twig new file mode 100644 index 0000000..d8b0c4d --- /dev/null +++ b/app/Resources/FOSUserBundle/views/Resetting/reset_content.html.twig @@ -0,0 +1,8 @@ +{% trans_default_domain 'FOSUserBundle' %} + +{{ form_start(form, { 'action': path('fos_user_resetting_reset', {'token': token}), 'attr': { 'class': 'fos_user_resetting_reset' } }) }} + {{ form_widget(form) }} +{{ 'connect.confirm.text' | trans({'%service%': service | trans({}, 'HWIOAuthBundle'), '%name%': userInformation.realName}, 'HWIOAuthBundle') }}
++ {{ form_start(form, {'action': path('hwi_oauth_connect_service', {'service': service, 'key': key}), 'attr': {'class': 'fos_user_registration_register'}}) }} + {{ form_widget(form) }} +
+ {{ form_end(form) }} + +- You can log in again by going to the login page. -
-- You can also login using a token by going to the token login page. + You can log in again by going to the login page.
{% endblock %} \ No newline at end of file diff --git a/app/config/config.yml b/app/config/config.yml index 0d88eba..c4d6b38 100644 --- a/app/config/config.yml +++ b/app/config/config.yml @@ -121,3 +121,67 @@ swiftmailer: username: '%mailer_user%' password: '%mailer_password%' spool: { type: memory } + +hwi_oauth: + firewall_names: [secured_area] + resource_owners: + facebook: + type: facebook + client_id: '1821112348143190' + client_secret: '155bc602a7e30e4227625c29c8b124c6' + scope: 'email,public_profile' + google: + type: google + client_id: '1076229066413-3rf8q0qjurn4h190dagi98tp0a10obe6.apps.googleusercontent.com' + client_secret: 'zQN32g_7lUz4dZ7E9kgY6nHe' + scope: "email profile" + options: + access_type: offline + amazon: + type: amazon + client_id: 'amzn1.application-oa2-client.15f87b8a4f23465b9022ba0a3f55610d' + client_secret: '84d6f402c53386ae0f196062945f217dcc56e7b7122cffb76c95b6a5775d22e0' + instagram: + type: instagram + client_id: ' 70e7edd280834c429d49f985ff308230' + client_secret: '9c405020a3ef412086032a4514909705' + twitter: + type: twitter + client_id: 'YmXGQN2Az0eTlkwJrnaO2wR9r' + client_secret: 'c73cBI7uj562BU4bBSHfNDcKHgM5aVo8sousjgUdDNBZFXxFHI' + windows: + type: windows_live + client_id: 'f9dc3dd7-1b1c-4b8c-acdf-f40611ab550d' + client_secret: 'fy5prOcKeLKNTB616WinrPt' + scope: wl.signin + yahoo: + type: yahoo + client_id: 'dj0yJmk9SndXWm05Tk5yME9MJmQ9WVdrOVRYTkVUVWRHTjJjbWNHbzlNQS0tJnM9Y29uc3VtZXJzZWNyZXQmeD1lMw--' + client_secret: '4f837f738d6c4df38eaedc7babe4d8f405f8cc0f' + fosub: + # try 30 times to check if a username is available (foo, foo1, foo2 etc) + username_iterations: 30 + + # mapping between resource owners (see below) and properties + properties: + google: googleId + facebook: facebookId + amazon: amazonId + instagram: instagramId + twitter: twitterId + windows_live: windowsId + yahoo: yahooId + + # if you want to use 'connect' and do not use the FOSUB integration, configure these separately + connect: ~ +fos_user: + db_driver: orm # other valid values are 'mongodb' and 'couchdb' + firewall_name: secured_area + user_class: Sikofitt\DoughnutWeddingBundle\Entity\User + from_email: + address: noreply@doughnutwedding.com + sender_name: "No Reply" + registration: + form: + type: Sikofitt\DoughnutWeddingBundle\Form\RegistrationType + diff --git a/app/config/routing.yml b/app/config/routing.yml index 8a49826..b650138 100644 --- a/app/config/routing.yml +++ b/app/config/routing.yml @@ -1,4 +1,35 @@ +hwi_oauth_redirect: + resource: "@HWIOAuthBundle/Resources/config/routing/redirect.xml" + prefix: /user/connect + +hwi_oauth_connect: + resource: "@HWIOAuthBundle/Resources/config/routing/connect.xml" + prefix: /user/connect + +hwi_oauth_login: + resource: "@HWIOAuthBundle/Resources/config/routing/login.xml" + prefix: /user/oauth + +facebook_login: + path: /user/login/callback/facebook +google_login: + path: /user/login/callback/google +twitter_login: + path: /user/login/callback/twitter +windows_login: + path: /user/login/callback/windows +instagram_login: + path: /user/login/callback/instagram +amazon_login: + path: /user/login/callback/amazon +yahoo_login: + path: /user/login/callback/yahoo + +fos_user: + resource: "@FOSUserBundle/Resources/config/routing/all.xml" + prefix: /user + sikofitt_doughnut_wedding: resource: "@SikofittDoughnutWeddingBundle/Controller/" type: annotation - prefix: / + prefix: / \ No newline at end of file diff --git a/app/config/security.yml b/app/config/security.yml index 1086c1a..095d896 100644 --- a/app/config/security.yml +++ b/app/config/security.yml @@ -1,17 +1,48 @@ # To get started with security, check out the documentation: # http://symfony.com/doc/current/security.html security: - + encoders: + FOS\UserBundle\Model\UserInterface: + algorithm: bcrypt + cost: 14 # http://symfony.com/doc/current/security.html#b-configuring-how-users-are-loaded providers: - in_memory: - memory: ~ - + #in_memory: + # memory: ~ + fos_userbundle: + id: fos_user.user_provider.username + #id: fos_user.user_manager firewalls: # disables authentication for assets and the profiler, adapt it according to your needs dev: pattern: ^/(_(profiler|wdt)|css|images|js)/ security: false + secured_area: + pattern: ^/ + form_login: + provider: fos_userbundle + login_path: /user/connect/ + check_path: /login/login_check + logout: + path: /user/logout + target: / + anonymous: true + oauth: + resource_owners: + facebook: /user/login/callback/facebook + google: /user/login/callback/google + twitter: /user/login/callback/twitter + windows: /user/login/callback/windows + instagram: /user/login/callback/instagram + amazon: /user/login/callback/amazon + yahoo: /user/login/callback/yahoo + login_path: /user/oauth + use_forward: false + failure_path: /user/oauth + oauth_user_provider: + service: hwi_oauth.user.provider.fosub_bridge + #oauth_user_provider: + # service: my.oauth_aware.user_provider.service main: anonymous: ~ @@ -22,3 +53,8 @@ security: # http://symfony.com/doc/current/cookbook/security/form_login_setup.html #form_login: ~ + access_control: + - { path: ^/user/login$, role: IS_AUTHENTICATED_ANONYMOUSLY } + - { path: ^/user/register, role: IS_AUTHENTICATED_ANONYMOUSLY } + - { path: ^/user/resetting, role: IS_AUTHENTICATED_ANONYMOUSLY } + - { path: ^/admin/, role: ROLE_ADMIN } \ No newline at end of file diff --git a/app/config/services.yml b/app/config/services.yml index 4d0ec71..47b5840 100644 --- a/app/config/services.yml +++ b/app/config/services.yml @@ -7,3 +7,8 @@ services: class: Bramus\Monolog\Formatter\ColoredLineFormatter tags: - { name: 'monolog.logger' } + + doughnutwedding.form.registration: + class: Sikofitt\DoughnutWeddingBundle\Form\RegistrationType + tags: + - { name: form.type, alias: app_user_registration } \ No newline at end of file diff --git a/composer.json b/composer.json index fa70072..20c30d3 100644 --- a/composer.json +++ b/composer.json @@ -18,7 +18,9 @@ "doctrine/doctrine-cache-bundle": "^1.3", "doctrine/orm": "^2.5", "egulias/email-validator": "^2.1", + "friendsofsymfony/user-bundle": "^2.0", "google/recaptcha": "^1.1", + "hwi/oauth-bundle": "^0.5.3", "incenteev/composer-parameter-handler": "^2.0", "ircmaxell/random-lib": "^1.2", "ircmaxell/security-lib": "^1.1", diff --git a/conf.d/default.conf b/conf.d/default.conf index 26c2e18..e9676fc 100644 --- a/conf.d/default.conf +++ b/conf.d/default.conf @@ -7,16 +7,17 @@ server { root /var/www/html; location / { - index index.php index.html; try_files $uri /app_dev.php$is_args$args; } - - location ~ \.php$ { + #location ~ \.php$ { + location ~ ^/(app_dev|config)\.php(/|$) { + fastcgi_pass php:9000; + fastcgi_split_path_info ^(.+\.php)(/.*)$; include fastcgi_params; - fastcgi_pass php:9000; - fastcgi_index app_dev.php; - fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name; + fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name; + fastcgi_param DOCUMENT_ROOT $realpath_root; + #fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name; } } diff --git a/docker-compose.yml b/docker-compose.yml index 37b94c6..30fb48d 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -7,7 +7,7 @@ services: - "80:80" volumes: - ./:/var/www - - ./html:/var/www/html + - ./web:/var/www/html - ./conf.d:/etc/nginx/conf.d links: - php diff --git a/src/Sikofitt/DoughnutWeddingBundle/Controller/DefaultController.php b/src/Sikofitt/DoughnutWeddingBundle/Controller/DefaultController.php index 4704809..e29d581 100644 --- a/src/Sikofitt/DoughnutWeddingBundle/Controller/DefaultController.php +++ b/src/Sikofitt/DoughnutWeddingBundle/Controller/DefaultController.php @@ -1,31 +1,34 @@ . - */ - namespace Sikofitt\DoughnutWeddingBundle\Controller; +use Symfony\Bundle\FrameworkBundle\Controller\Controller; +use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; +use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\Request; -class DefaultController +/** + * Class DefaultController + */ +class DefaultController extends Controller { - public function indexAction(Request $request, \Kernel $app) + /** + * @Route("/") + * + * @param Request $request + * @return Response + */ + public function indexAction(Request $request) { - return $app->render('index.html.twig', ['request' => $request]); + if(null === $user = $request->getUser()) { + return $this->render('default/index.html.twig', array( + 'base_dir' => $this->get('kernel')->getRootDir(), + )); + } + return $this->render('default/index_user.html.twig', array( + 'base_dir' => $this->get('kernel')->getRootDir(), + )); + } + } diff --git a/src/Sikofitt/DoughnutWeddingBundle/Controller/RsvpController.php b/src/Sikofitt/DoughnutWeddingBundle/Controller/RsvpController.php index a43658e..85d4fff 100644 --- a/src/Sikofitt/DoughnutWeddingBundle/Controller/RsvpController.php +++ b/src/Sikofitt/DoughnutWeddingBundle/Controller/RsvpController.php @@ -21,30 +21,30 @@ namespace Sikofitt\DoughnutWeddingBundle\Controller; use Doctrine\ORM\EntityManager; -use Sikofitt\{ - App\Entity\Rsvp, App\Entity\User, App\Form\ResetPasswordType, App\Form\ResetType, App\Form\RsvpType, App\Repository\RsvpRepository, App\Repository\UserRepository -}; +use Symfony\Bundle\FrameworkBundle\Controller\Controller; use Symfony\Component\Form\FormFactory; use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\HttpFoundation\Response; +use Symfony\Component\Routing\Annotation\Route; use Symfony\Component\Validator\ConstraintViolationList; -class RsvpController +class RsvpController extends Controller { /** + * @Route("/rsvp") * @param \Symfony\Component\HttpFoundation\Request $request - * @param \Kernel $app * * @return \Symfony\Component\HttpFoundation\RedirectResponse|\Symfony\Component\HttpFoundation\Response */ - public function indexAction(Request $request, \Kernel $app) + public function indexAction(Request $request) { /** * @var EntityManager $em * @var RsvpRepository $rsvpRepo * @var UserRepository $userRepo */ - $em = $app['orm.em']; + $em = $this->get('doctrine.orm.entity_manager'); $rsvpRepo = $em->getRepository('Sikofitt:Rsvp'); $count = (40 - $rsvpRepo->getRsvpCount()); $userRepo = $em->getRepository('Sikofitt:User'); diff --git a/src/Sikofitt/DoughnutWeddingBundle/Controller/UserController.php b/src/Sikofitt/DoughnutWeddingBundle/Controller/UserController.php index debfe7a..7d808cc 100644 --- a/src/Sikofitt/DoughnutWeddingBundle/Controller/UserController.php +++ b/src/Sikofitt/DoughnutWeddingBundle/Controller/UserController.php @@ -20,11 +20,11 @@ namespace Sikofitt\DoughnutWeddingBundle\Controller; +use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; use Sikofitt\App\Form\UserLoginType; use Sikofitt\App\Form\UserTokenType; -use Sikofitt\Security\TokenGenerator; -use Silex\Api\ControllerProviderInterface; -use Silex\Application; +use Sikofitt\DoughnutWeddingBundle\Security\TokenGenerator; +use Symfony\Bundle\FrameworkBundle\Controller\Controller; use Symfony\Component\Form\FormError; use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\Request; @@ -33,127 +33,107 @@ use Symfony\Component\HttpFoundation\StreamedResponse; /** * Class UserController. */ -class UserController implements ControllerProviderInterface +class UserController extends Controller { - public function connect(Application $app) + + /** + * @Route("/logout", name="logout") + * @param \Symfony\Component\HttpFoundation\Request $request + * @return \Symfony\Component\HttpFoundation\Response + */ + public function logoutAction(Request $request) { - /** - * @var ControllerCollection $userControllers - */ - $userControllers = $app['controllers_factory']; - $userControllers->match('/', __CLASS__.'::indexAction') - ->method('GET') - ->bind('user_index'); - - $userControllers->match('/login', __CLASS__.'::loginAction') - ->method('GET|POST') - ->bind('login'); - $userControllers->get('/logout', __CLASS__.'::logoutAction') - ->bind('logout'); - $userControllers->match('/login/token/{token}', __CLASS__.'::tokenLoginAction') - ->method('GET|POST') - ->bind('token_login') - ->value('token', null); - - $userControllers->match('/reset', __CLASS__.'::resetAction') - ->method('GET|POST') - ->bind('user_reset'); - $userControllers->match('/reset/{token}', __CLASS__.'::tokenAction') - ->bind('user_reset_token') - ->method('GET|POST'); - //->before(new MysqlAuthenticatorMiddleware()); - $userControllers->match('/edit', __CLASS__.'::editAction') - ->method('GET|POST') - ->bind('user_edit'); - - return $userControllers; - } - - public function logoutAction(\Kernel $app) - { - if (true === $app->session()->has('user')) { - $app->session()->remove('user'); + if(null !== $request->getUser()) { + $request->getSession()->remove('user'); } - - return $app->render('user/logout.html.twig'); + return $this->render('user/logout.html.twig'); } - public function tokenLoginAction(Request $request, \Kernel $app, string $token = null) + public function tokenLoginAction(Request $request, string $token = null) { if (null === $token) { - $tokenForm = $app->getFormFactory()->create(UserTokenType::class); + $tokenForm = $this->get('form.factory')->create(UserTokenType::class); if ($request->isMethod('POST')) { $tokenForm->handleRequest($request); if ($tokenForm->isValid() && $tokenForm->isSubmitted()) { if ($tokenForm->get('update_token')->isClicked()) { if (null !== $tokenForm->get('email')->getData()) { - return $this->updateAndSendTokenLoginLink($app, + return $this->updateAndSendTokenLoginLink($this, $tokenForm); } else { $tokenForm->get('email') ->addError(new FormError('Email address is a required field to send a new login link.')); - return $app->render('form/token.html.twig', + return $this->render('form/token.html.twig', ['form' => $tokenForm->createView()]); } } else { $userToken = $tokenForm->get('user_token')->getData(); - $user = $app->getEntityManager() - ->getRepository('Sikofitt:User') + + $user = $this->getDoctrine() + ->getRepository('SikofittDoughnutWeddingBundle:User') ->getUserByUserToken($userToken); + if (null === $user) { $tokenForm->get('user_token') ->addError(new FormError('Token is invalid.')); } else { - $app->session()->set('user', $user); + $request->getSession()->set('user', $user); } - return $app->render('form/token.html.twig', + return $this->render('form/token.html.twig', ['form' => $tokenForm->createView()]); } } else { - return $app->render('form/token.html.twig', + return $this->render('form/token.html.twig', ['form' => $tokenForm->createView()]); } } - return $app->render('form/token.html.twig', ['form' => $tokenForm->createView()]); + return $this->render('form/token.html.twig', ['form' => $tokenForm->createView()]); } else { // Token has been included. - $app->session()->remove('user'); - $tokenForm = $app->getFormFactory()->create(UserTokenType::class); + $request->getSession()->remove('user'); + $tokenForm = $this->get('form.factory')->create(UserTokenType::class); //$user = $app->getEntityManager()->getRepository('Sikofitt:User')->getUserByUserToken($token); - $user = $app->getEntityManager()->getRepository('Sikofitt:User')->findOneBy(['userToken' => $token]); + $user = $this->getDoctrine()->getRepository('SikofittDoughnutWeddingBundle:User')->findOneBy(['userToken' => $token]); if (null !== $user) { - $app->session()->set('user', $user); + $request->getSession()->set('user', $user); - return $app->render('user/index.html.twig'); + return $this->render('user/index.html.twig'); } else { - return new StreamedResponse(function () use ($app, $tokenForm, $token) { + return new StreamedResponse(function () use ($tokenForm, $token) { $tokenForm->get('user_token')->setData($token); $tokenForm->get('user_token')->addError(new FormError('Invalid token.')); - print $app->renderView('form/token.html.twig', ['form' => $tokenForm->createView()]); + print $this->renderView('form/token.html.twig', ['form' => $tokenForm->createView()]); }); } } } - public function indexAction(Request $request, \Kernel $app) + /** + * @Route("/user", name="user_index") + * @param \Symfony\Component\HttpFoundation\Request $request + * + * @return \Symfony\Component\HttpFoundation\JsonResponse + */ + public function indexAction(Request $request) { - if ($app->session()->has('user')) { + + //if ($request->getSession()->has('user')) { return new JsonResponse( [ 'request' => $request->request->all(), 'server' => $request->server->all(), 'headers' => $request->headers->all(), - 'session' => $app->getSession()->get('user'), + 'session' => $request->getSession()->all(), 'token' => (string) new TokenGenerator(), ] ); - } + // } } - public function loginAction(Request $request, \Kernel $app) + public function loginAction(Request $request) { if ($app->session()->has('user')) { //return $app->redirect($app->url('rsvp_edit')); diff --git a/src/Sikofitt/DoughnutWeddingBundle/Entity/User.php b/src/Sikofitt/DoughnutWeddingBundle/Entity/User.php index be0233e..9e44699 100644 --- a/src/Sikofitt/DoughnutWeddingBundle/Entity/User.php +++ b/src/Sikofitt/DoughnutWeddingBundle/Entity/User.php @@ -21,7 +21,7 @@ namespace Sikofitt\DoughnutWeddingBundle\Entity; use Doctrine\ORM\Mapping as ORM; -use Symfony\Component\Security\Core\User\UserInterface; +use FOS\UserBundle\Model\UserInterface; use Symfony\Component\Validator\Constraints as Assert; /** @@ -30,7 +30,7 @@ use Symfony\Component\Validator\Constraints as Assert; * @ORM\Entity(repositoryClass="Sikofitt\DoughnutWeddingBundle\Repository\UserRepository") * @ORM\Table(name="users") */ -class User implements UserInterface +class User extends \FOS\UserBundle\Model\User { const KATRINA_SIDE = 'Katrina'; @@ -43,7 +43,7 @@ class User implements UserInterface * * @var int */ - private $id; + protected $id; /** * @ORM\Column(name="first_name", type="string", length=255, nullable=false) @@ -65,31 +65,31 @@ class User implements UserInterface */ private $family = false; + //* @Assert\Choice(choices="{self::KATRINA_SIDE, self::ERIC_SIDE}", multiple=false) /** * @ORM\Column(type="string", name="family_side", nullable=true) - * @Assert\Choice(choices="{self::KATRINA_SIDE, self::ERIC_SIDE}", multiple=false) * * @var null|string */ private $familySide = null; - /** + /* * @ORM\Column(name="email", type="string", length=255) * @Assert\Email(strict=true, checkHost=true, checkMX=true) - */ - private $email; - /** + protected $email; + */ + /* * @var string * @ORM\Column(name="password", type="string", length=255)) - */ - private $password; - - /** + * + protected $password; + */ + /* * @var string - */ - private $plainPassword; - + * + protected $plainPassword; + */ /** * @var string * @ORM\Column(name="reset_token", type="string", length=255, nullable=true) @@ -107,6 +107,7 @@ class User implements UserInterface * @ORM\OneToOne(targetEntity="Sikofitt\DoughnutWeddingBundle\Entity\Rsvp", inversedBy="user", cascade={"persist"}) */ private $rsvp; + /** * @ORM\Column(type="datetime", name="created") */ @@ -117,12 +118,282 @@ class User implements UserInterface */ private $updated = null; + /** + * @ORM\Column(name="facebook_id", type="string", length=255, nullable=true) + */ + private $facebookId; + + private $facebookAccessToken; + + /** + * @ORM\Column(name="google_id", type="string", length=255, nullable=true) + */ + private $googleId; + + private $googleAccessToken; + + /** + * @ORM\Column(name="amazon_id", type="string", length=255, nullable=true) + */ + private $amazonId; + + private $amazonAccessToken; + /** + * @ORM\Column(name="instagram_id", type="string", length=255, nullable=true) + */ + private $instagramId; + private $instagramAccessToken; + + /** + * @ORM\Column(name="twitter_id", type="string", length=255, nullable=true) + */ + private $twitterId; + private $twitterAccessToken; + + /** + * @ORM\Column(name="windows_id", type="string", length=255, nullable=true) + */ + private $windowsId; + private $windowsAccessToken; + + /** + * @ORM\Column(name="yahoo_id", type="string", length=255, nullable=true) + */ + private $yahooId; + private $yahooAccessToken; + + /** + * @return mixed + */ + public function getAmazonId() { + return $this->amazonId; + } + + /** + * @param mixed $amazonId + * @return User + */ + public function setAmazonId($amazonId) { + $this->amazonId = $amazonId; + return $this; + } + + /** + * @return mixed + */ + public function getAmazonAccessToken() { + return $this->amazonAccessToken; + } + + /** + * @param mixed $amazonAccessToken + * @return User + */ + public function setAmazonAccessToken($amazonAccessToken) { + $this->amazonAccessToken = $amazonAccessToken; + return $this; + } + + /** + * @return mixed + */ + public function getFacebookId() { + return $this->facebookId; + } + + /** + * @param mixed $facebookId + * @return User + */ + public function setFacebookId($facebookId) { + $this->facebookId = $facebookId; + return $this; + } + + /** + * @return mixed + */ + public function getFacebookAccessToken() { + return $this->facebookAccessToken; + } + + /** + * @param mixed $facebookAccessToken + * @return User + */ + public function setFacebookAccessToken($facebookAccessToken) { + $this->facebookAccessToken = $facebookAccessToken; + return $this; + } + + /** + * @return mixed + */ + public function getGoogleId() { + return $this->googleId; + } + + /** + * @param mixed $googleId + * @return User + */ + public function setGoogleId($googleId) { + $this->googleId = $googleId; + return $this; + } + + /** + * @return mixed + */ + public function getGoogleAccessToken() { + return $this->googleAccessToken; + } + + /** + * @param mixed $googleAccessToken + * @return User + */ + public function setGoogleAccessToken($googleAccessToken) { + $this->googleAccessToken = $googleAccessToken; + return $this; + } + + /** + * @return mixed + */ + public function getInstagramId() { + return $this->instagramId; + } + + /** + * @param mixed $instagramId + * @return User + */ + public function setInstagramId($instagramId) { + $this->instagramId = $instagramId; + return $this; + } + + /** + * @return mixed + */ + public function getInstagramAccessToken() { + return $this->instagramAccessToken; + } + + /** + * @param mixed $instagramAccessToken + * @return User + */ + public function setInstagramAccessToken($instagramAccessToken) { + $this->instagramAccessToken = $instagramAccessToken; + return $this; + } + + /** + * @return mixed + */ + public function getTwitterId() { + return $this->twitterId; + } + + /** + * @param mixed $twitterId + * @return User + */ + public function setTwitterId($twitterId) { + $this->twitterId = $twitterId; + return $this; + } + + /** + * @return mixed + */ + public function getTwitterAccessToken() { + return $this->twitterAccessToken; + } + + /** + * @param mixed $twitterAccessToken + * @return User + */ + public function setTwitterAccessToken($twitterAccessToken) { + $this->twitterAccessToken = $twitterAccessToken; + return $this; + } + + /** + * @return mixed + */ + public function getWindowsId() { + return $this->windowsId; + } + + /** + * @param mixed $windowsId + * @return User + */ + public function setWindowsId($windowsId) { + $this->windowsId = $windowsId; + return $this; + } + + /** + * @return mixed + */ + public function getWindowsAccessToken() { + return $this->windowsAccessToken; + } + + /** + * @param mixed $windowsAccessToken + * @return User + */ + public function setWindowsAccessToken($windowsAccessToken) { + $this->windowsAccessToken = $windowsAccessToken; + return $this; + } + + /** + * @return mixed + */ + public function getYahooId() { + return $this->yahooId; + } + + /** + * @param mixed $yahooId + * @return User + */ + public function setYahooId($yahooId) { + $this->yahooId = $yahooId; + return $this; + } + + /** + * @return mixed + */ + public function getYahooAccessToken() { + return $this->yahooAccessToken; + } + + /** + * @param mixed $yahooAccessToken + * @return User + */ + public function setYahooAccessToken($yahooAccessToken) { + $this->yahooAccessToken = $yahooAccessToken; + return $this; + } + + public function __construct() { if (null === $this->created) { $this->created = new \DateTime('now'); } $this->updated = new \DateTime('now'); + parent::__construct(); } /** @@ -188,9 +459,7 @@ class User implements UserInterface */ public function getUsername() { - $email = explode('@', $this->email); - - return $email[0]; + return $this->username; } /** @@ -298,7 +567,7 @@ class User implements UserInterface * * @return User */ - public function setPlainPassword(string $plainPassword): User + public function setPlainPassword($plainPassword): User { $this->plainPassword = $plainPassword; @@ -313,7 +582,7 @@ class User implements UserInterface public function setUserToken($userToken) { $this->userToken = $userToken; - + return $this; } @@ -396,11 +665,11 @@ class User implements UserInterface /** * Set rsvp. * - * @param \Sikofitt\App\Entity\Rsvp $rsvp + * @param Rsvp $rsvp * * @return User */ - public function setRsvp(\Sikofitt\App\Entity\Rsvp $rsvp = null) + public function setRsvp(Rsvp $rsvp = null) { $this->rsvp = $rsvp; @@ -410,7 +679,7 @@ class User implements UserInterface /** * Get rsvp. * - * @return \Sikofitt\App\Entity\Rsvp + * @return Rsvp */ public function getRsvp() { diff --git a/src/Sikofitt/DoughnutWeddingBundle/Form/RegistrationType.php b/src/Sikofitt/DoughnutWeddingBundle/Form/RegistrationType.php new file mode 100644 index 0000000..988b52e --- /dev/null +++ b/src/Sikofitt/DoughnutWeddingBundle/Form/RegistrationType.php @@ -0,0 +1,30 @@ +add('first_name') + ->add('last_name'); + } + + public function configureOptions(OptionsResolver $resolver) + { + + } + public function getParent() { + return RegistrationFormType::class; + } + + public function getBlockPrefix() + { + return 'sikofitt_doughnut_wedding_bundle_registration_type'; + } +} diff --git a/src/Sikofitt/DoughnutWeddingBundle/Repository/RsvpRepository.php b/src/Sikofitt/DoughnutWeddingBundle/Repository/RsvpRepository.php index c62baec..053b9aa 100644 --- a/src/Sikofitt/DoughnutWeddingBundle/Repository/RsvpRepository.php +++ b/src/Sikofitt/DoughnutWeddingBundle/Repository/RsvpRepository.php @@ -18,7 +18,7 @@ * along with this program. If not, see