Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/266.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Symfony 2错误凭据_Php_Symfony_Login - Fatal编程技术网

Php Symfony 2错误凭据

Php Symfony 2错误凭据,php,symfony,login,Php,Symfony,Login,我有一个管理系统,但我无法登录。它抛出错误的凭据错误。项目已连接到数据库,因为我从实体生成表,它工作正常。我猜问题在于用户角色,但我不确定 谢谢你的建议 security.yml security: encoders: administrators: class: Nasivin\AdminBundle\Entity\Admin algorithm: plaintext role_hierarchy: ROLE_USER: ROLE_USER

我有一个管理系统,但我无法登录。它抛出错误的凭据错误。项目已连接到数据库,因为我从实体生成表,它工作正常。我猜问题在于用户角色,但我不确定

谢谢你的建议

security.yml

security:
encoders:
    administrators:
     class: Nasivin\AdminBundle\Entity\Admin
     algorithm: plaintext

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

providers:
  administrators:
    entity: { class: NasivinAdminBundle:Admin, property: username }

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

    admin:
      pattern: ^/admin/
      provider: administrators
      anonymous: ~
      form_login:
        check_path: _admin_security_check
        login_path: _admin_login
        default_target_path: /admin/bla
        always_use_default_target_path: true
      logout:
        path: _admin_logout
        target: /admin

access_control:
    #- { path: ^/login, roles: IS_AUTHENTICATED_ANONYMOUSLY, requires_channel: https }
    admin_login:
      path: ^/admin/login
      roles: IS_AUTHENTICATED_ANONYMOUSLY
    admin_area:
      path: ^/admin/.*
      roles: ROLE_USER
Admin.php实体类

    <?php
/**
 * Created by PhpStorm.
 * User: Michal
 * Date: 16.9.2014
 * Time: 11:37
 */

namespace Nasivin\AdminBundle\Entity;


use Symfony\Component\Security\Core\User\UserInterface;
use Doctrine\ORM\Mapping as ORM;

/**
 * Nasivin\AdminBundle\Entity\Admin
 *
 * @ORM\Table(name="tb_admin")
 * @ORM\Entity()
 */
class Admin implements UserInterface
{
    /**
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    protected $id;

    /**
     * @ORM\Column(name="username", type="string", length=25, unique=true)
     */
    protected $username;

    /**
     * @ORM\Column(name="password", type="string", length=64)
     */
    protected $password;

    /**
     * @ORM\Column(name="salt", type="string", length=64)
     */
    protected $salt;

    /**
     * @inheritDoc
     */
    public function getUsername()
    {
        return $this->username;
    }

    /**
     * @inheritDoc
     */
    public function getSalt()
    {
        // you *may* need a real salt depending on your encoder
        // see section on salt below
        return null;
    }

    /**
     * @inheritDoc
     */
    public function getPassword()
    {
        return $this->password;
    }

    /**
     * @inheritDoc
     */
    public function eraseCredentials()
    {
    }

    /**
     * @inheritDoc
     */
    public function getRoles()
    {
        return array("ROLE_ADMIN", "ROLE_USER");
    }

    /**
     * Get id
     *
     * @return integer 
     */
    public function getId()
    {
        return $this->id;
    }

    /**
     * Set username
     *
     * @param string $username
     * @return Admin
     */
    public function setUsername($username)
    {
        $this->username = $username;

        return $this;
    }

    /**
     * Set password
     *
     * @param string $password
     * @return Admin
     */
    public function setPassword($password)
    {
        $this->password = $password;

        return $this;
    }

    /**
     * Set salt
     *
     * @param string $salt
     * @return Admin
     */
    public function setSalt($salt)
    {
        $this->salt = $salt;

        return $this;
    }
}

首先,symfony上的表单必须作为对象。
Symfony集成了一个表单组件,使处理表单变得简单


关于用户登录,我建议您使用

问题是我在数据库中创建了用户。一旦我创建了注册管理员的函数并注册了一个它正在工作的函数。

没有symfony表单的普通表单也用于文档和我的其他项目中,这不是问题。此外,我不想使用FOSuserBundle,但谢谢你的回答。
{% extends "::base.html.twig" %}

{% block title %}NasivinAdminBundle:Security:login{% endblock %}

{% block body %}
<h1>Welcome to the Security:login page</h1>
    <form action="{{ path('_admin_security_check') }}" method="post">
        <label for="username">Username:</label>
        <input type="text" id="username" name="_username" />

        <label for="password">Password:</label>
        <input type="password" id="password" name="_password" />

        {#
            If you want to control the URL the user
            is redirected to on success (more details below)
            <input type="hidden" name="_target_path" value="/account" />
        #}

        <button type="submit">login</button>
    </form>
{% endblock %}