How can I check if it's sfguarduser s first logon in symfony?
I want someone to enter their logon details and then the action to check if they are an existing user. If not, then I want them to have to select their department from a drop down, otherwise proceed as normal.
I don't know whereabou开发者_JAVA百科ts the logon is processed though to check if they are an existing user. Can anyone help?
In Symfony sfGuard, if someone isn't an existing user, they cannot login at all. This means that you should separate these into login and registration:
- If a user, go login.
- If not, go register and select department.
However, if you'd like custom behaviour to occur on a user's first time logging in, you could create a flag for this yourself, possibly by creating an associated profile table for the sfGuardUser. The sfGuardUser model doesn't have custom fields you could use for something like this but... it does have "Timestampable" behaviour, so you could maybe do (pseudo-code):
if (created_at == updated_at) {
// go to select department and update updated_at
} else {
// login as normal
}
I believe those two fields are set to equal when a new sfGuardUser is made.
hope that helps.
IMHO it might be useful to store their department information in a table (either extend sf_guard_user
, or make another for such "extended userdata", and check if it's set there.
If not, they haven't answered this yet, and thus are here the first time; consider giving the user an option "don't want to choose", different from "not chosen yet" - depending on your business logic, you may want this or not.
精彩评论