0


I tried to solve this problem myself but after three days, I give up and ask for help..

I receive "Bad credentials." erros (details: pastebin)

Here is my security.yml:

security:
    encoders:
      Common\UserBundle\Entity\User:
        algorithm: bcrypt

    role_hierarchy:
        ROLE_ADMIN:       ROLE_USER
        ROLE_SUPER_ADMIN: [ROLE_USER, ROLE_ADMIN, ROLE_ALLOWED_TO_SWITCH]

    providers:
      request_users:
        entity:
          class: CommonUserBundle:User
          property: username

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

        request_security:
            pattern:    ^/
            anonymous: ~
            form_login:
                check_path:  _check_path
                login_path:  login_page
                default_target_path: gemmi_start_homepage
            logout:
                path:   _logout
                target: signup_page

    access_control:
        #- { path: ^/login, roles: IS_AUTHENTICATED_ANONYMOUSLY, requires_channel: https }

And my LoginController:

    <?php

namespace Common\UserBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Response;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Component\Security\Core\SecurityContextInterface;
use Symfony\Component\HttpFoundation\Request;

class LoginController extends Controller
{

    public function indexAction(Request $Request)
    {
        $Session = $this->get('session');

        if($Request->attributes->has(SecurityContextInterface::AUTHENTICATION_ERROR)) {
            $loginError = $Request->attributes->get(SecurityContextInterface::AUTHENTICATION_ERROR);
        } else {
            $loginError = $Session->remove(SecurityContextInterface::AUTHENTICATION_ERROR);
        }

        $userName = $Session->get(SecurityContextInterface::LAST_USERNAME);

        echo $loginError;

        return $this->render('CommonUserBundle::login.html.twig', array(
            'loginError' => $loginError,
            'userName' => $userName
        ));
    }   
}

Also my routing.yml:

    login_page:
    path:     /login
    defaults: { _controller: CommonUserBundle:Login:index }

signup_page:
    path:     /signup
    defaults: { _controller: CommonUserBundle:Login:signup }

_check_path:
    path: /login-check

_logout:
    path: /logout

And:

gemmi_start_homepage:
path:     /
defaults: { _controller: GemmiStartBundle:Default:index }

And my form:

<form method="post" action="{{ path('_check_path') }}" name="contactform" id="contactform">

                    <fieldset>

                        <label for="login" accesskey="E"></label>
                        <input name="_username" type="text" id="login" size="30" value="{{ userName }}" placeholder="{% trans %} nickname {% endtrans %}" />
                        <br> <br>
                        <label for="passwd" accesskey="E"></label>
                        <input name="_password" type="password" id="passwd" size="30" value="" placeholder="{% trans %} password {% endtrans %}" />
                        <br> <br>
                        <button type="submit" class="submit btn btn-send" id="submit" value="Submit">
                            <i class="fa fa-user"></i>
                            {% trans %} log_in {% endtrans %}
                        </button>

                    </fieldset>

                </form>


User Entity: pastebin

And the last one - UserFixtures: pastebin


I know there is a lot to check but can someone help me?

Gemmi
  • 1,252
  • 2
  • 13
  • 26

1 Answers1

1

Did you notice you're missing a specific option, named firewalls: in your security.yml file? Or you accidentally left it out while you were pasting your code? The syntax should be like this:

providers:
    request_users:
        entity:
            class: CommonUserBundle:User
            property: username

firewalls:
    # your firewalls definitions goes here.

I applied your configuration quickly, and I managed to pass the form. I was not authenticated fully though, but it did not throw me error for Bad credentials. Try editing your file (if that line is indeed missing) and see what happens. If that is not the case, we will continue investigating the problem further.

Artamiel
  • 3,652
  • 2
  • 19
  • 24
  • Unfortunately I miss "firewalls:" while pasting it here. So I do have it in my security.yml, so we need to find other issue. Thank You for helping! – Gemmi Apr 25 '15 at 05:41
  • There is a high chance that you indeed enter bad credentials. I pasted one of the passwords from my projects and I was redirected after form submission, just as expected. – Artamiel Apr 25 '15 at 05:47
  • Hmmm... For sure I enter correct credentiasl, I did It mamy Times. I think It will be another stupid,Simple issue. – Gemmi Apr 25 '15 at 07:24