How can I check if it's sfguarduser s first logon in symfony?

喜你入骨 提交于 2019-12-11 11:44:39

问题


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 whereabouts the logon is processed though to check if they are an existing user. Can anyone help?


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/6359124/how-can-i-check-if-its-sfguarduser-s-first-logon-in-symfony

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!