我正在尝试制作自己的用户包,目前正在登录阶段挣扎,错误信息:
由于系统问题,无法处理身份验证请求。
我是Symfony的新手,我正在尽我最大的努力学习尽可能多的方面,所以如果我在定义东西时走错了路,请原谅我。
我目前有两个bundle,一个是我的应用scoreboarbundle,另一个是用于认证机制PulsahrUserBundle。我打算在我的其他项目中重用这个包。
我想使用的用户实体是scoreboarbundle entity User,继承自PulsahrUserBundle entity User,它实现了UserInterface, Serializable。
我查看了dev.log,发现了这个有趣的行:
[2016-09-22 14:16:19]安全。INFO:认证请求失败。{"exception":"[object] (SymfonyComponentSecurityCore exception AuthenticationServiceException(code: 0):执行SELECT t1时发生异常。id AS id_2 t1。username AS username_3, t1。password AS password_4, t1。roles AS roles_5, t1。email AS email_6, t1。config AS config_7, t1.name AS name_8, t1.nameavatar AS avatar_9, t1。graph_color AS graph_color_10 FROM user t1 WHERE t0。username = ?LIMIT 1' with params ["fdsfgsd"]
我可能在某个地方犯了一个错误,Doctrine正在寻找一个0。不定义别名的用户名。为什么?
下面是我的几个文件,希望对你有帮助。
/src/Pulsahr/UserBundle/资源/config/理论/User.orm。yml:
PulsahrUserBundleEntityUser:
type: entity
table: user
repositoryClass: PulsahrUserBundleRepositoryUserRepository
id:
id:
type: integer
id: true
generator:
strategy: AUTO
fields:
username:
type: string
length: 255
unique: true
password:
type: string
length: 255
roles:
type: array
nullable: true
lifecycleCallbacks: { }
/src/ScoreboardBundle/资源/config/理论/User.orm。yml:
ScoreboardBundleEntityUser:
type: entity
table: user
repositoryClass: ScoreboardBundleRepositoryUserRepository
fields:
email:
type: string
length: 255
config:
type: integer
name:
type: string
length: 127
avatar:
type: string
length: 255
nullable: true
graphColor:
column: graph_color
type: string
length: 255
manyToMany:
races:
targetEntity: Race
mappedBy: users
oneToMany:
scores:
targetEntity: Score
mappedBy: user
lifecycleCallbacks: { }
/app/config/安全。yml:
security:
encoders:
ScoreboardBundleUser:
algorithm: bcrypt
cost: 4
role_hierarchy:
ROLE_RACEADMIN: ROLE_USER
ROLE_ADMIN: ROLE_RACEADMIN
ROLE_SUPER_ADMIN: [ROLE_ADMIN, ROLE_ALLOWED_TO_SWITCH]
providers:
pulsahr_userbundle:
entity:
class: ScoreboardBundle:User
property: username
firewalls:
dev:
pattern: ^/(_(profiler|wdt)|css|images|js)/
security: false
pulsahr_user_security:
anonymous: true
form_login:
login_path: pulsahr_user_login
check_path: pulsahr_user_check
provider: pulsahr_userbundle
logout:
path: pulsahr_user_logout
target: pulsahr_user_login
pattern: ^/
remember_me:
secret: '%secret%'
access_control:
- { path: ^/admin, role: ROLE_ADMIN }
我必须手动输入一个用户,并使用bcrypt计算器作为密码,使用4作为代价,与security.yml中定义的相同。但是无论使用什么登录名和密码,我都有相同的错误消息。
经过一番努力,一位朋友帮我找到了解决办法。
这个问题是由于从PulsahrUserBundleEntityUser继承scoreboarbundle UserEntityUser而引起的。
php类很好,问题来自于映射。我必须在user . org .yaml中指定源类的类型为"mapappedsuperclass"。只需要这样做:
PulsahrUserBundleEntityUser:
type: mappedSuperclass
table: user
[...]
更多关于原则文档的信息:http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/inheritance-mapping.html
我希望这能帮助到一些像我一样被困的人。