how to automatically populate user_Id
10 posts
• Page 1 of 1
Hi Steve,
this is my first posting. So let me thank you for your great work with the dataface framework first. I have a question on how to populate a given variable (here the $ENV.Username) into a field automatically. I have some tables connected with foreign keys and want the $ENV.Username variable of the current User to be inserted into a field widget when inserting a new record. Thank you Markus
Hi Markus, Thanks for the question.Ê There are a couple of ways to accomplish this.Ê You can either set the default field value to the user id, or you can set the value in the beforeSave() trigger. I generally prefer the first method.Ê For this, you would use the fieldname__default() method in the delegate class: e.g.Ê Suppose the name of the field we want to populate is username: function username__default(){ Then it is a good idea to set the widget for this field to hidden so that it can't be changed (or make it so that only administrators have edit permissions for this field). The second option (setting it in the beforeSave() trigger) would look like: function beforeSave(&$record){ (Note that the beforeSave() trigger will only work for this in 0.7 and later.Ê In 0.6.x changes made to the record in the triggers weren't propogated to the database). Hope this helps. -Steve
Steve, I am assuming that this implies that you are using "authentication". Is there a 'place' I can pass in the 'REMOTE_USER' from the Browser and be able to use this as the "login" name for use within history tables? Since I require SecurID to my site, I really hate ( well, I don't... but you know how people hate to double authenticate" ) - to require somebody to .. So, I would like to bring in whatever variables I need/use from the Browser. I'm just not sure.. where to pass them to. In Advance, Thanks dan
Hi Dan, Since PHP makes the REMOTE_USER variable available to you in the $_SERVER array, you can use this in place of the $auth->getLoggedInUsername() call.e.g. function username__default(){ ÊÊÊ return $_SERVER['REMOTE_USER']; } -Steve
Hey... Why can't I be smart like you?
Actaully, I think I was able to do it by enabling history... and then.
Down around line 125 $auth =& Dataface_AuthenticationTool::getInstance(); $userRecord =& $auth->getLoggedInUser(); if ( !isset($userRecord) ){ // $user = null; $user = $_SERVER['REMOTE_USER']; } else { // $user = $auth->getLoggedInUsername(); $user = $_SERVER['REMOTE_USER']; } dan
I suppose this is one way to do it.Ê The risk here is that by changing the code in the dataface distribution it will be more difficult to upgrade later.Ê The best way to support this sort of authentication is to create an authentication handler for itÊ (see the CAS module for a sample of an authentication handler).Ê The handler would really only need to implement one method: getLoggedInUsername(). But if this one is working for you you can go with it. Best regards Steve
Actually... I continue to be slightly confused.
1) If I do not want to authenticate, and only want to grab the "remote_user" from the Browser, am I correct in believing that I do not need [auth] in the config. eg: # [_auth] # users_table = Users # username_column = UserName # password_column = Password But since I want to track History, that I enable History. [history] enabled = 1 That being said... Do I need to Have _auth set and point it towards CAS and change the default handler as you mentioned in your first reply.. I guess I may be missing the interaction between having auth set ( in the config file ) and history enabled. I know HistoryTool.php has: $auth =& Dataface_AuthenticationTool::getInstance(); $userRecord =& $auth->getLoggedInUser(); if ( !isset($userRecord) ){ $user = null; } else { $user = $auth->getLoggedInUsername(); } But a few posts back, you suggested to use username_default instead of getLoggedInUsername.. I'm getting confused on "what class calls..... what function interacts... " . Luckily..... I have a nice development box to try everything out with... I"ve downloaded CAS module and am looking through it.. But let me query you about the basic starting point for the default_username from the browser. Do I need AUTH enabled? ( as you suggest by the use of the CAS module)? or turn AUTH off, Leave History enabled - and pass it when a Record is updated? ( ie actions? ) Monday woes.... dan
10 posts
• Page 1 of 1
Who is onlineUsers browsing this forum: No registered users and 36 guests |