我根据security.yml中的symfony 2文档进行了更改,但它无法正常工作。不知道它在哪里破碎。注销后,它不会在登录表单的输入框中呈现用户名。请帮助我。
security.yml文件:
安全性: 编码器: trex \ EntityBundle \ Entity \ Users:plaintext
role_hierarchy:
ROLE_ADMIN: ROLE_USER
ROLE_SUPER_ADMIN: [ROLE_USER, ROLE_ADMIN, ROLE_ALLOWED_TO_SWITCH]
providers:
main:
entity:
class: trex\EntityBundle\Entity\Users
property: username
firewalls:
dev:
pattern: ^/(_(profiler|wdt)|css|images|js)/
security: false
login:
pattern: ^/login$
security: false
deteleRole:
pattern: ^/role/deleteRole$
security: false
#deteleCandidate:
# pattern: ^/candidates/delete$
# security: false
deteleUser:
pattern: ^/users/delete$
security: false
forgotPassword:
pattern: ^/forgot-password$
security: false
secured_area:
pattern: ^/
form_login:
check_path: login_check
login_path: login
default_target_path: default_security_target
remember_me: true
logout:
path: logout
target: login
remember_me:
key: trex-kharadi6
lifetime: 604800
always_remember_me: true
remember_me_parameter: _remember_me
path: /
domain: ~
access_control:
- { path: ^/secured_area, roles: ROLE_ADMIN }
- { path: ^/secured_area, roles: ROLE_ADMIN }
#- { path: ^/login, roles: IS_AUTHENTICATED_ANONYMOUSLY, requires_channel: https }
这是我的login.html.twig
<div class="input-prepend" data-rel="tooltip" style="margin-left: -12%; width:75%;">
<label class="control-label" for="focusedInput">Username <span class="red">*</span></label>
<input autofocus class="input-large span10" name="_username" data-validation="required" id="username" type="text" value="{{ last_username }}" style="float:left; width:55%; margin-left:5%;" />
</div>
<div class="clearfix"></div>
<div class="input-prepend" data-rel="tooltip" style="margin-left: -12%; width:75%;">
<label class="control-label" for="focusedInput">Password <span class="red">*</span></label>
<input class="input-large span10" name="_password" id="password" data-validation="required" type="password" style="float:left; width:55%; margin-left:5%;" />
</div>
<div class="clearfix"></div>
<div class="input-prepend">
<label class="remember" for="remember"><input type="checkbox" name="_remember_me" id="remember_me" checked/>Remember me <a href="{{path('forgotPassword')}}">Forgot password?</a></label>
</div>
<p class="center span5">
<button type="submit" class="btn btn-primary" style="width:45%;">Login</button>
</p>
</fieldset>
</form>
答案 0 :(得分:1)
此功能不适用于在登录表单的输入框中呈现用户名。
请记住,我的功能是允许用户使用Cookie保持登录的时间超过会话持续时间。如果用户在登录时检查了我的复选框,则cookie将保存在浏览器中,下次访问该网站时,他将自动登录。如果用户注销,则必须再次通过该表单重复登录过程