简体   繁体   中英

Symfony 2.7 - Login form issue (500 error code)

I've already done all the steps mentioned in "How to Build a Traditional Login Form" recipe (nearly in the same way as they done it), however redirect after successful login does not work as it should.

Validation of user/pass works like a charm, but after clicking submit button Chrome/Opera throws Error 500 with no description (it's NOT a Symfony error page, but default web-browser error page) and until reboot of browser it's no longer possible to enter on any of my application pages (even pages available with anonymous user). So likely the browser is forced to handle some endless loop of request or something like this.

Key-fragments of source codes :

Security.yml:

 (***) 
 firewalls:

        dev:
            pattern: ^/(_(profiler|wdt)|css|images|js)/
            security: false

        main_area:
            anonymous: ~
            http_basic: ~
            provider: user_provider
            form_login:
              login_path: /login
              check_path: /login_check
              default_target_path: /index/welcome
#              target_path_parameter: /index/welcome

    access_control:
      - { path: ^/admin, roles: ROLE_ADMIN }
      - { path: ^/index/board, roles: ROLE_USER}
 (***) 

SecurityControler.php

(***)    
class SecurityController extends Controller
    {
        /**
         * @Route("/login", name="login_route")
         */
        public function loginAction()
        {
            $authUtils = $this->get('security.authentication_utils');
            $error = $authUtils->getLastAuthenticationError();
            $enteredUsername = $authUtils->getLastUsername();

            return $this->render('BakaMainBundle::Login.html.twig',
                array
                (
                    'last_username' => $enteredUsername,
                    'error' => $error,
                    'site' => 'login'
                ));
        }

        /**
         * @Route("/login_check", name="login_check")
         */
        public function loginCheckAction()
        {

        }
    }

UserReg.php (Form):

(***)
class UserReg extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder
            ->add('email','email')
            ->add('username', 'text')
            ->add('plainPassword', 'repeated', array
            (
                'type' => 'password',
                'first_options' => array('label'=>'Password'),
                'second_options' => array('label'=> 'Repeat password')
            ))
            ->add('termsAccept', 'checkbox', array
            (
                'mapped'=> false,
                'constraints' => new IsTrue()
            ));
    }

    public function configureOptions(OptionsResolver $resolver)
    {
        $resolver->setDefaults(array
        (
            'data_class' => 'Baka\MainBundle\Entity\User'
        ));
    }

    public function getName()
    {
        return 'user';
    }
}

I really run out of ideas, no matter from which site request to login comes (or even /login is opened directly) still results are the same. Any ideas?

An easy way to track errors in your program, using the logs, it to use

tail -f app/logs/dev.log

using Cmd - f to find the "error" word.

this allows you to catch the exact moment it occurs, rather than randomly browsing through your entire logs.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM