Hi

I'm trying to get a login form working with database authentication
and the "right symfony way" of achieving this without using sfGuard.
Overall, I'm trying to comprehend the "way of doing things in
symfony", hopefully you guys can pinpoint me in the right direction.

action.class.php has a working executeLogin which makes use of lib/
form/LoginForm.class.php. I can login with a hardcoded dummy code, so
that works well.

However I'm struggling about how to go with the database
authentication. I've seen examples (symfony 1.0 example) that do the
authentication in the action.class.php/executeLogin(). However. I
don't think that is good since it's isn't the place to do the logic
things, right?

So I got this in:

lib/model/doctrine/MemberTable.class.php:
---------------------------------------------------------
  public function getMemberByEmailAndPassword($email,$password)
  {
      $q = $this->createQuery('m')
        ->where('m.email = ?', $email)
        ->andWhere('m.password = ?', $password);

      return $q->execute();
  }
---------------------------------------------------------


action.class.php: in my public function executeLogin():
---------------------------------------------------------
$this->result = Doctrine_Core::getTable('member')-
>getMemberByEmailAndPassword($tabform['email'],$tabform['password']);
---------------------------------------------------------

Now I got doctrinecollection member object in $this->result[0].
I can do $this->result[0]>getNickname(); but I think i'm not doing
this correctly, there must be a better way.

In this Symfony 1.0 cookbook example they use   $user =
UserPeer::doSelectOne($c); and eventually have:
$user->getPassword.

This Symfony 1.0  Cookbook example makes use of a class UserPeer and
doSelectOne. But it doesn't exist in Symfont 1.4. What are their
equivalents nowadays?

This example below is pretty much how I want it too but I shall put my
logic code into lib/model/doctrine to conform the MVC pattern.

Also it makes use of $request->setError('email', 'this user does not
exist'); Is it possible to do this in Symfony 1.4 as well.

public function executeLogin()
{
  // check if the user exists
  $c = new Criteria();
  $c->add(UserPeer::LOGIN, $this->getRequestParameter('login'));
  $user = UserPeer::doSelectOne($c);
  if ($user)
  {
    // check if the password is correct
    if ($this->getRequestParameter('password') == $user-
>getPassword())
    {
      // sign in
      $this->getContext()->getUser()->signIn();
      // proceed to home page
      return $this->redirect('main/index');
    }
    else
    {
      $this->getRequest()->setError('password', 'wrong password');
    }
  }
  else
  {
    $this->getRequest()->setError('email', 'this user does not
exist');
  }

  // an error was found
  return $this->forward('security', 'index');
}


Thanks in advance :)

-- 
If you want to report a vulnerability issue on symfony, please send it to 
security at symfony-project.com

You received this message because you are subscribed to the Google
Groups "symfony users" group.
To post to this group, send email to symfony-users@googlegroups.com
To unsubscribe from this group, send email to
symfony-users+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/symfony-users?hl=en

Reply via email to