php - Login system in symfony 2 -


i tried create authentification system in symfony2 no results. in debug status bar situations have : logged anon.

if make dump of session in view :

"_security.last_error" => badcredentialsexception 

my routing file:

shop_show_login_page:   path: /login   defaults: { _controller: shopdesktopbundle:user:loginpage }  shop_login_user:   path: /loginuser   defaults: { _controller: shopdesktopbundle:user:logincheck }  shop_logout_user:   path: /logout 

my controller :

class usercontroller extends controller{ public function loginpageaction(){     return $this->render('shopdesktopbundle:user:loginpage.html.twig'); } public function logincheckaction(){     $request  = $this->getrequest();     $password = $request->request->get('_password');     $login    = $request->request->get('_username');     $em = $this->getdoctrine()->getentitymanager();     $repository = $em->getrepository('shopdesktopbundle:customer');     $user = $repository->findoneby(array('customer_login'=> $login, 'customer_password'=> $password));     if($user){         return $this->redirect($this->generateurl('shop_desktop_homepage'));     }else{         return $this->render('shopdesktopbundle:user:loginpage.html.twig',array('message_failed' => 'eroare : login sau password este gresit'));     } } } 

my view :

<form action="{{ path('shop_login_user') }}" method="post">                 <div class="form-group">                     <div class="input-group">                         <span class="input-group-addon"><i class="fa fa-user"></i></span>                         <input type="text" class="form-control" placeholder="username" name="_username">                     </div>                 </div>                 <div class="form-group">                     <div class="input-group">                         <span class="input-group-addon"><i class="fa fa-lock"></i></span>                         <input type="text" class="form-control" placeholder="password" name="_password">                     </div>                 </div>                 <div class="form-group">                     <button type="submit" class="button">autentificare</button>                 </div>             </form> 

security.yml :

security: # http://symfony.com/doc/current/book/security.html#encoding-the-user-s-password encoders:     symfony\component\security\core\user\user: plaintext  # http://symfony.com/doc/current/book/security.html#hierarchical-roles role_hierarchy:     role_admin:       role_user     role_super_admin: [role_user, role_admin, role_allowed_to_switch]  # http://symfony.com/doc/current/book/security.html#where-do-users-come-from-user-providers providers:     in_memory:         memory:             users:                 user:  { password: userpass, roles: [ 'role_user' ] }                 admin: { password: adminpass, roles: [ 'role_admin' ] }  # main part of security, can set firewalls # specific sections of app firewalls:     # disables authentication assets , profiler, adapt according needs     secured_area:         pattern:    ^/         form_login:             check_path: shop_login_user             login_path: shop_show_login_page             username_parameter: _username             password_parameter: _password         logout:             invalidate_session: true             path:   shop_logout_user             target: /         anonymous: true         #http_basic:         #    realm: "secured demo area"  # these settings can restrict or allow access different parts # of application based on roles, ip, host or methods # http://symfony.com/doc/current/cookbook/security/access_control.html access_control:     #- { path: ^/login, roles: is_authenticated_anonymously, requires_channel: https } 

i spent several days no results. me please!!! thx in advance

i think problem is, haven't updated user providers in security.yml still have static list of users provided in_memory user provider. security system not aware of own class shopdesktopbundle:customer.

if follow cookbook on "how create custom user provider", should able solve by:

update user class

your user class customer must implement userinterface (and recommended equatableinterface)

class customer implements userinterface, equatableinterface { […] } 

add userprovider

you have create userprovider, like:

class customeruserprovider implements userproviderinterface {     public function loaduserbyusername($username) { […]}     public function refreshuser(userinterface $user) { […] }     public function supportsclass($class) {         return $class === 'shop\desktopbundle\customer';     } } 

create service , update user_provider in security.yml

finally create service in service.yml like:

services:     customer_user_provider:         class: shop\desktopbundle\customeruserprovider 

and update security.yml like:

security:     providers:         webservice:             id: customer_user_provider 

Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -