0
votes

i'm new to symfony and i'm having the following issue creating login logic for application:

1) I have a form which is loaded by a slot in the layout.php file, the form contains a 'User' object, with only 2 properties: 'user_name'and 'password', and validation is taken care by symfony validator framework (both fields have 'required' validator set as you migh have guessed)

index page is accesed by action:

public function executeIndex(sfWebRequest $request)
{
    $this->form = new UserFormLogin();
}  

The form is loaded by something like this in the layout file:

2) I have a login action, which performs validation, here's the relevant code:

protected function processLoginForm(sfWebRequest $request, sfForm $form)
{
    form->bind($request->getParameter($form->getName()), $request->getFiles($form->getName()));
if ($form->isValid())
{ 
         ...Some code to retrieve from db, check credentials etc...

      }
      else
      {
          $this->redirect('users/index');
      }
}

public function executeLogin(sfWebRequest $request){
    $this->forward404Unless($request->isMethod(sfRequest::POST));
    $this->form = new UserFormLogin();
    $this->processLoginForm($request, $this->form);
}

3) All the above so (theoretically) when a user inputs non-valid credentials returns to index and shows error messages... but instead of getting the expected 'username is required' or something like that, it gives me the next error: "An object with the same "user_name" already exist.

Any ideas why is that? please help me, what i'm missing?

1
It seems that everthing is OK. Did you typed user_name? - Darmen Amanbayev
Nope, 'user_name' is the name of the field in the form. At first i though the error was because i shouldn't create a new UserFormLogin ecah time i call the index, but that causes trouble too. - melev
Please show code of your UserFormLogin.class.php - alternative you should have an eye on sfGuardPlugin, which provides a login form incl auth mechanism ! - domi27

1 Answers

0
votes

you are try to register new user form, so what are you doing right, no error, when the user enter the same user name you must redirect him the the index success, and if you try to register by used user name you will face the below validation message.