Q:

symfony2 login class the simplest way

What is the simplest way to get login working? I instaled the AjaxLoginBundle but I have no idea how to handle the _username and _password. I just wont creat a simple class/function with works this way:
public function Login($username, $password) {
if ($username=="admin" && $password="admin") {
     someFunctionIsLoged(true);
     setUserLoged($username);
     setUserLevel(RULE_ADMIN);
}

This is everthing what I need, no FOSUserBundle or anthing, much to many functions and too complicated.

A:

I have a piece of login code that I usually use in my projects. I put it in my UserController since I don't use FOSUserBundle in most cases.I hope this will be of some use to you.
PS: The different methods called in the session setting part are specific to my User entity.   
public function loginAction()
        {
            $request = $this->get('request');
            $session = $request->getSession();
            $user_id = $request->request->get('login');
            $user_pass = $request->request->get('password');

            if($request->getMethod() == 'POST')
            {
                    $repository = $this->getDoctrine()
                    ->getManager()
                    ->getRepository('AppNameUserBundle:User');

                    $em = $this->getDoctrine()->getEntityManager();
                    $user = $repository->findBy(array('login' => $user_id,'password'=>$user_pass));

                    if( $user == null )
                    {   
                        throw $this->createNotFoundException("Nom d'utilisateur ou mot de passe incorrect");
                    }
                    else if($user != null)
                    {
                            //Session setting
                            $session = $this->get('session');
                            $session->set('id',$user->getId());
                            $session->set('name',$user->getName());
                            $session->set('surname',$user->getSurname());
                            $session->set('mail',$user->getEmail());
                            $session->set('login',$user->getLogin());
                            $element->setOnline(TRUE);
                            $em->persist($element);
                            $em->flush();
                        }
                    }
                   return $this->redirect($this->generateUrl('app_homepage_route'));

            }
        }

