Authenticating against a Database

This is for discussion, mainly on 1.x but there's some 2.x topics here too.

Moderators: dwhittle, Ian

Authenticating against a Database

Postby tariquesani » Mon Oct 31, 2005 2:46 pm

Hello,

First congratulations on creating a superb framework.

Can anyone give some hints on how to authenticate a user against a database in executeLogin()

I would very much prefer not to use Propel::getconnection etc - so that the login can still be kept independent of the DB layer

Thanks in advance

Cheers
Tarique
tariquesani
Junior Member
 
Posts: 2
Joined: Mon Oct 31, 2005 2:39 pm

Re: Authenticating against a Database

Postby fabien » Mon Oct 31, 2005 4:31 pm

You can easily create a User model with Propel and then use it in your login action.

Here is a very simple executeLogin action example:

Code: Select all
  public function executeLogin()
  {
    ...

    $c = new Criteria();
    $c->add(UserPeer::LOGIN, $this->getRequestParameter('login'));
    $tmpuser = UserPeer::doSelectOne($c);

    // user exists? and password is ok?
    if ($tmpuser && $tmpuser->getPassword() == $this->getRequestParameter('password'))
    {
      $user = $this->getUser();

      // we save the user object in session
      $user->setAttribute('user', $tmpuser);

      // user is now authenticated
      $user->setAuthenticated(true);

      // set user credentials
      $user->addCredential('somecredentials');
    }

    ...
  }
Last edited by fabien on Mon Oct 31, 2005 4:32 pm, edited 1 time in total.
fabien
Faithful Member
 
Posts: 486
Joined: Sat Oct 22, 2005 9:01 am

Re: Authenticating against a Database

Postby tariquesani » Tue Nov 01, 2005 3:49 am

Thanks for the quick reply - the key indeed was to read Propel documentation :)~ :-)~ :smile:

Cheers
tariquesani
Junior Member
 
Posts: 2
Joined: Mon Oct 31, 2005 2:39 pm


Return to General discussion

Who is online

Users browsing this forum: No registered users and 3 guests