Eric
Eric

Reputation: 2231

Symfony logging in a user

I'm using symfony 1.4 and am having trouble wrapping my mind around what seems like it should be a simple process -- logging in. I was originally looking at the Jobeet tutorial covering the subject here. The tutorial makes it seem like it should be fairly simple to store information about the user.

Currently, what I'm trying to do is very basic logging. First, store the username for the associated account, then adding a credential "user" that I'll use as a basis for determining if they're logged in. The above tutorial makes it seem like nothing has to be initialized and the code should work on it's own, so I tried the following:

$this->getUser()->setAttribute('username', $loginDetails['username']);
$user->addCredential('user');

This, like I thought, doesn't work on it's own. However, I have no idea what is required to be initialized first, so I'm kind of stuck here.

What is required to actually store this kind of information. Also, once I set that information, is it there until the user "logs out"? Or do I have to do something on each page to make sure this information is carried over?

Upvotes: 0

Views: 190

Answers (1)

prodigitalson
prodigitalson

Reputation: 60413

sfUser is essentially the model responsible for interacting with a session. So it helps to think of it in that respect. So all the rules of a normal session apply.

As for your code that should work assuming you made your user class extends sfSecurityUser. The only issue i see is in your second line you dont actually have a $user variable it should be:

$this->getUser()->setAttribute('username', $loginDetails['username']);
$this->getUser()->addCredential('user');

OR

$user = $this->getUser();
$user->setAttribute('username', $loginDetails['username']);
$user->addCredential('user');

Upvotes: 1

Related Questions