diff --git a/app/config/config.yml b/app/config/config.yml index e899119..1b96d02 100644 --- a/app/config/config.yml +++ b/app/config/config.yml @@ -61,11 +61,14 @@ doctrine: # Swiftmailer Configuration swiftmailer: - transport: "%mailer_transport%" - host: "%mailer_host%" - username: "%mailer_user%" - password: "%mailer_password%" - spool: { type: memory } + transport: %mailer_transport% + host: %mailer_host% + port: %mailer_port% + username: %mailer_user% + encryption: %mailer_encryption% + auth_mode: %mailer_auth_mode% + password: %mailer_password% + stof_doctrine_extensions: default_locale: en_US diff --git a/app/config/parameters.yml.dist b/app/config/parameters.yml.dist index df1aaf7..c2f88f4 100644 --- a/app/config/parameters.yml.dist +++ b/app/config/parameters.yml.dist @@ -14,7 +14,9 @@ parameters: mailer_host: 127.0.0.1 mailer_user: ~ mailer_password: ~ - mailer_from: ~ + mailer_encryption: ssl + mailer_auth_mode: login + mailer_port: 465 # A secret key that's used to generate certain security-related tokens secret: ThisTokenIsNotSoSecretChangeIt diff --git a/app/config/security.yml b/app/config/security.yml index 17d4f4e..70a86fc 100644 --- a/app/config/security.yml +++ b/app/config/security.yml @@ -38,7 +38,7 @@ security: google: "/login/check-google" login_path: / use_forward: false - default_target_path: /registrationNet + default_target_path: /account/update-profile failure_path: / oauth_user_provider: service: oauth_test_provider diff --git a/app/config/services.xml b/app/config/services.xml index 17d60a0..c0f8175 100644 --- a/app/config/services.xml +++ b/app/config/services.xml @@ -72,7 +72,7 @@ - %mailer_from% + %mailer_user% diff --git a/install.sh b/install.sh index 098f010..4d80e39 100644 --- a/install.sh +++ b/install.sh @@ -24,8 +24,8 @@ case "$Keypress" in composer install ./node_modules/.bin/bower install ./node_modules/.bin/gulp - php app/console doctrine:database:drop --force - php app/console doctrine:database:create + #php app/console doctrine:database:drop --force + #php app/console doctrine:database:create php app/console doctrine:schema:update --force app/console app:admin_create admin@admin.net admin Admin Admin ;; diff --git a/src/AppBundle/Controller/RegistrationController.php b/src/AppBundle/Controller/RegistrationController.php index 84f11bd..8e7798a 100644 --- a/src/AppBundle/Controller/RegistrationController.php +++ b/src/AppBundle/Controller/RegistrationController.php @@ -27,7 +27,7 @@ public function registerAction(Request $request) } /** - * @Route("/registrationNet", name="net_registration") + * @Route("/account/update-profile", name="update_profile") * @Template("@App/registration/updateRegistration.html.twig") */ public function registerSocialNetAction(Request $request) @@ -35,7 +35,7 @@ public function registerSocialNetAction(Request $request) $user = $this->getUser(); if ($user) { - if ($user->getIsReg() === false) { + if (!$user->getPassword()) { return $this->get('app.registration.user') ->updateRegistrationUser($request, $user); } @@ -78,8 +78,7 @@ public function checkUserHash($hash, $email) ->findOneBy(array('email' => $email, 'hash' => $hash)); if ($user) { - - $user->setIsReg(true); + $user->setIsActive(true); $user->setHash(null); $this->addFlash('notice', 'You have successfully passed registration confirmation'); @@ -106,11 +105,12 @@ public function recoveryPassword(Request $request) $user = $em->getRepository('AppBundle:User') ->findOneBy(['email' => $email]); - if ($user && $user->getIsReg() == true) { + if ($user && $user->isAccountNonLocked() == true) { $password = $this->get('app.custom.mailer')->sendMailRecovery($email); $newPassword = $this->get('security.password_encoder') ->encodePassword($user, $password); $user->setPassword($newPassword); + $user->setIsActive(true); $em->flush(); $this->addFlash('notice', 'The new password is sent to your email'); @@ -121,8 +121,8 @@ public function recoveryPassword(Request $request) $this->addFlash('notice', 'Email is incorrectly specified'); return $this->redirectToRoute('homepage'); - } elseif ($user && $user->getIsReg() == false) { - $this->addFlash('notice', 'You aren\'t registered'); + } elseif ($user && $user->isAccountNonLocked() == false) { + $this->addFlash('notice', 'You are blocked'); return $this->redirectToRoute('homepage'); } else { diff --git a/src/AppBundle/DataFixtures/ORM/Data/users.yml b/src/AppBundle/DataFixtures/ORM/Data/users.yml index f61c4b3..63c2728 100644 --- a/src/AppBundle/DataFixtures/ORM/Data/users.yml +++ b/src/AppBundle/DataFixtures/ORM/Data/users.yml @@ -5,18 +5,18 @@ AppBundle\Entity\User: email(unique): user1@mail.ru password: role: ROLE_USER - isReg: true + isActive: true user2: firstName: lastName: email(unique): user2@mail.ru password: role: ROLE_USER - isReg: true + isActive: true user3: firstName: lastName: email(unique): user3@mail.ru password: role: ROLE_USER - isReg: true \ No newline at end of file + isActive: true \ No newline at end of file diff --git a/src/AppBundle/DataFixtures/ORM/DataForTests/test.yml b/src/AppBundle/DataFixtures/ORM/DataForTests/test.yml index a1f661c..50e66d5 100644 --- a/src/AppBundle/DataFixtures/ORM/DataForTests/test.yml +++ b/src/AppBundle/DataFixtures/ORM/DataForTests/test.yml @@ -3,18 +3,18 @@ AppBundle\Entity\User: password: email: admin@test.com isActive: true - isReg: true role: "ROLE_ADMIN" firstName: "Admin" lastName: "Admin" + isActive: true user2: password: email: user@test.com isActive: true - isReg: true role: "ROLE_USER" firstName: "User" lastName: "User" + isActive: true AppBundle\Entity\Category: category1: diff --git a/src/AppBundle/Entity/User.php b/src/AppBundle/Entity/User.php index 1e8b244..3164d9a 100644 --- a/src/AppBundle/Entity/User.php +++ b/src/AppBundle/Entity/User.php @@ -98,9 +98,9 @@ class User implements AdvancedUserInterface, \JsonSerializable protected $type; /** - * @ORM\Column(name="is_reg", type="boolean") + * @ORM\Column(name="is_locked", type="boolean") */ - protected $isReg; + protected $isLocked; /** * @ORM\Column(name="hash", type="string", nullable=true) @@ -121,14 +121,10 @@ public function jsonSerialize() ]; } - - /** - * - */ public function __construct() { $this->isActive = false; - $this->isReg = false; + $this->isLocked = false; $this->modulesUser = new ArrayCollection(); $this->role = self::ROLE_USER; } @@ -324,7 +320,7 @@ public function isAccountNonExpired() */ public function isAccountNonLocked() { - return true; + return $this->isLocked ? false : true ; } /** @@ -360,6 +356,23 @@ public function setIsActive($active) return $this->isActive = $active; } + /** + * @return bool + */ + public function getIsLocked() + { + return $this->isLocked; + } + + /** + * @param $isLocked + * @return mixed + */ + public function setIsLocked($isLocked) + { + return $this->isLocked = $isLocked; + } + /** * @return string */ @@ -370,6 +383,7 @@ public function getFacebookToken() /** * @param string $facebookToken + * @return $this */ public function setFacebookToken($facebookToken) { @@ -388,6 +402,7 @@ public function getFacebookId() /** * @param string $facebookId + * @return $this */ public function setFacebookId($facebookId) { @@ -406,6 +421,7 @@ public function getGoogleToken() /** * @param string $googleToken + * @return $this */ public function setGoogleToken($googleToken) { @@ -424,6 +440,7 @@ public function getGoogleId() /** * @param string $googleId + * @return $this */ public function setGoogleId($googleId) { @@ -456,24 +473,6 @@ public function getType() return $this->type; } - /** - * @return mixed - */ - public function getIsReg() - { - return $this->isReg; - } - - /** - * @param mixed $isReg - */ - public function setIsReg($isReg) - { - $this->isReg = $isReg; - - return $this; - } - /** * @return mixed */ @@ -484,6 +483,7 @@ public function getHash() /** * @param mixed $hash + * @return $this */ public function setHash($hash) { diff --git a/src/AppBundle/Form/UpdateUserSocialNetType.php b/src/AppBundle/Form/UpdateUserSocialNetType.php index f79f8c5..2e69bc2 100644 --- a/src/AppBundle/Form/UpdateUserSocialNetType.php +++ b/src/AppBundle/Form/UpdateUserSocialNetType.php @@ -36,6 +36,7 @@ public function buildForm(FormBuilderInterface $builder, array $options) ]) ->add('plain_password', RepeatedType::class, [ 'type' => PasswordType::class, + 'required' => false, 'invalid_message' => 'The password fields must match.', 'options' => [ 'attr' => [ diff --git a/src/AppBundle/Form/UpdateUserType.php b/src/AppBundle/Form/UpdateUserType.php index 942e8b9..19f4755 100644 --- a/src/AppBundle/Form/UpdateUserType.php +++ b/src/AppBundle/Form/UpdateUserType.php @@ -35,8 +35,8 @@ public function buildForm(FormBuilderInterface $builder, array $options) 'placeholder' => 'enter last name' ] ]) - ->add('is_active', CheckboxType::class, [ - 'label' => 'Active', + ->add('is_locked', CheckboxType::class, [ + 'label' => 'Locked', 'required' => false ]); } diff --git a/src/AppBundle/Form/UserType.php b/src/AppBundle/Form/UserType.php index 29a32df..5c2c630 100644 --- a/src/AppBundle/Form/UserType.php +++ b/src/AppBundle/Form/UserType.php @@ -18,19 +18,16 @@ public function buildForm(FormBuilderInterface $builder, array $options) ->add('email', EmailType::class, [ 'attr' => [ 'class' => 'form-control', - 'placeholder' => 'enter email' ] ]) ->add('firstName', TextType::class, [ 'attr' => [ 'class' => 'form-control', - 'placeholder' => 'enter first name' ] ]) ->add('lastName', TextType::class, [ 'attr' => [ 'class' => 'form-control', - 'placeholder' => 'enter last name' ] ]) ->add('plain_password', RepeatedType::class, [ @@ -39,9 +36,10 @@ public function buildForm(FormBuilderInterface $builder, array $options) 'options' => [ 'attr' => [ 'class' => 'form-control', - 'placeholder' => 'enter password' ] - ] + ], + 'first_options' => ['label' => 'Password'], + 'second_options' => ['label' => 'Repeat Password'], ] ); } diff --git a/src/AppBundle/Resources/views/Emails/registration.html.twig b/src/AppBundle/Resources/views/Emails/registration.html.twig index 12b3929..e2f0f30 100644 --- a/src/AppBundle/Resources/views/Emails/registration.html.twig +++ b/src/AppBundle/Resources/views/Emails/registration.html.twig @@ -1,6 +1,6 @@

You did it! You registered!

{# example, assuming you have a route named "login" #} -For completion of registration follow the link: CHECK REGISTER. +For completion of registration follow the link: CHECK REGISTER. Thanks! \ No newline at end of file diff --git a/src/AppBundle/Resources/views/admin/user/showUser.html.twig b/src/AppBundle/Resources/views/admin/user/showUser.html.twig index f5515d0..88e4bc8 100644 --- a/src/AppBundle/Resources/views/admin/user/showUser.html.twig +++ b/src/AppBundle/Resources/views/admin/user/showUser.html.twig @@ -15,6 +15,7 @@ First Name Last Name Active + Locked Info Modules Edit @@ -24,6 +25,7 @@ {{ user.firstName }} {{ user.lastName }} {% if user.isEnabled %}YES{% else %}NO{% endif %} + {% if user.isLocked %}YES{% else %}NO{% endif %} ({{ user.countModules }}) diff --git a/src/AppBundle/Resources/views/registration/updateRegistration.html.twig b/src/AppBundle/Resources/views/registration/updateRegistration.html.twig index 710afd8..549b444 100644 --- a/src/AppBundle/Resources/views/registration/updateRegistration.html.twig +++ b/src/AppBundle/Resources/views/registration/updateRegistration.html.twig @@ -8,7 +8,7 @@ {{ form_widget(form) }} {{ form_rest(form) }}
- + {{ form_end(form) }} diff --git a/src/AppBundle/Services/AdminCreator.php b/src/AppBundle/Services/AdminCreator.php index a8134e6..bc1fdd4 100644 --- a/src/AppBundle/Services/AdminCreator.php +++ b/src/AppBundle/Services/AdminCreator.php @@ -53,7 +53,6 @@ public function create($email, $password, $firstName, $lastName) $user->setPassword($pass); $user->setRole($role); $user->setIsActive(true); - $user->setIsReg(true); $em->persist($user); $em->flush(); } diff --git a/src/AppBundle/Services/MailerService.php b/src/AppBundle/Services/MailerService.php index 13b88ab..bedd10f 100644 --- a/src/AppBundle/Services/MailerService.php +++ b/src/AppBundle/Services/MailerService.php @@ -50,7 +50,7 @@ public function sendMailRecovery($mailTo) { $password = $this->generator->generator(); $message = \Swift_Message::newInstance() - ->setSubject('Registration') + ->setSubject('Recovery') ->setFrom($this->mailerFrom) ->setTo($mailTo) ->setBody( diff --git a/src/AppBundle/Services/PassControl.php b/src/AppBundle/Services/PassControl.php index 9e1966e..8bf5462 100644 --- a/src/AppBundle/Services/PassControl.php +++ b/src/AppBundle/Services/PassControl.php @@ -49,7 +49,7 @@ public function process(array $data) } $passModule->setCurrentQuestion($nextQuestionForPass); - $this->doctrine->getEntityManager()->flush(); + $this->doctrine->getManager()->flush(); return $this->generateOutput('redirect_to_pass', 301, $data['idPassModule']); } diff --git a/src/AppBundle/Services/PassManager.php b/src/AppBundle/Services/PassManager.php index 13b7569..2643a7c 100644 --- a/src/AppBundle/Services/PassManager.php +++ b/src/AppBundle/Services/PassManager.php @@ -96,8 +96,8 @@ private function createPassModule(ModuleUser $moduleUser) $passModule->setModuleUser($moduleUser); $passModule->setTimePeriod($moduleUser->getModule()->getTime()); - $this->doctrine->getEntityManager()->persist($passModule); - $this->doctrine->getEntityManager()->flush(); + $this->doctrine->getManager()->persist($passModule); + $this->doctrine->getManager()->flush(); return $passModule; } @@ -139,7 +139,7 @@ public function passModule($idPassModule) return $this->generateOutput('error', 500, 'This module does not have any questions ;('); $passModule->setCurrentQuestion($firstQuestionForPass); - $this->doctrine->getEntityManager()->flush(); + $this->doctrine->getManager()->flush(); } if(!($passModule->getIsActive())){ diff --git a/src/AppBundle/Services/Registration.php b/src/AppBundle/Services/Registration.php index dfe55e4..4c84c45 100644 --- a/src/AppBundle/Services/Registration.php +++ b/src/AppBundle/Services/Registration.php @@ -98,7 +98,6 @@ public function registrationUser(Request $request) $user->setPassword($password); $hash = $this->mailer->sendMail($user->getEmail()); - //$user->setIsReg(true); $user->setHash($hash); $em->persist($user); @@ -116,15 +115,19 @@ public function updateRegistrationUser(Request $request, User $user) { $em = $this->doctrine->getManager(); $form = $this->formFactory->create(UpdateUserSocialNetType::class, $user); - + $originalPassword = $user->getPassword(); $form->handleRequest($request); if ($form->isValid()) { - $password = $this->passwordEncoder - ->encodePassword($user, $user->getPlainPassword()); - $user->setPassword($password); - $user->setIsActive(false); - $user->setIsReg(true); + if (!empty($plainPassword)) { + $password = $this->passwordEncoder + ->encodePassword($user, $user->getPlainPassword()); + $user->setPassword($password); + } else { + $user->setPassword($originalPassword); + } + + $user->setIsActive(true); $em->flush(); diff --git a/src/AppBundle/Tests/Controller/RegistrationControllerTest.php b/src/AppBundle/Tests/Controller/RegistrationControllerTest.php index 23761d4..8c23247 100644 --- a/src/AppBundle/Tests/Controller/RegistrationControllerTest.php +++ b/src/AppBundle/Tests/Controller/RegistrationControllerTest.php @@ -25,7 +25,7 @@ public function testRegisterSocialNet() { $client = static::createClient(); - $client->request('GET', '/registrationNet'); + $client->request('GET', '/account/update-profile'); $this->assertEquals(302, $client->getResponse()->getStatusCode()); } } diff --git a/web-src/front/css/background.jpg b/web-src/front/css/background.jpg index 7fcad9f..13b7689 100644 Binary files a/web-src/front/css/background.jpg and b/web-src/front/css/background.jpg differ