This forum is in READ-ONLY mode.
You can look around, but if you want to ask a new question, please use the new forum.
Home » legacy support » symfony 1.0 » Other - IP blocking for a specific page element in a symfony 1.0 project
Other - IP blocking for a specific page element in a symfony 1.0 project [message #99040] Fri, 14 May 2010 06:54 Go to next message
blurmy23  is currently offline blurmy23
Messages: 7
Registered: May 2010
Junior Member
Hey folks,

I've inherited a symfony 1.0 project and I'm looking for a little guidance. Though I've been using php for years, I'm fairly new to symfony so I'm working through the 1.0 askeet tutorial (http://www.symfony-project.org/askeet/1_0/en/). A request has come down the line to do the following:

* if a user comes from within a specified list of IP addresses, display the user's email in the user data table
* otherwise hide it

In regular old php, this would be as simple as an if statement, but in symfony it doesn't seem so clear-cut. I think the answer I'm looking for is in http://www.symfony-project.org/book/1_0/14-Generators#Admini stration but I can't seem to wrap my head around it. Here's what I'm assuming...

* The user data table is rendered by code automatically generated
* I can override it by adding a new executeShow() method to my apps/backend/modules/user/actions/action.class.php (?)
* I should probably add the relevant ips to app.yml (?)

Beyond here, I'm stuck. Any suggestions?

Thanks!

Jacob
Re: Other - IP blocking for a specific page element in a symfony 1.0 project [message #99047 is a reply to message #99040 ] Fri, 14 May 2010 11:33 Go to previous messageGo to next message
halfer  is currently offline halfer
Messages: 9535
Registered: January 2006
Location: West Midlands, UK
Faithful Member
Took me a while to work out that you're using the admin generator. I tend to avoid this, as I think sometimes a project presents a requirement that is hard to do inside the generator unless you know how it works internally *in detail*.

But that aside, it is likely to be possible. A trivial solution would be to override the action and set up showIpColumn perhaps as an attribute to the request object, and then create a partial column in the generator (prefix it with _) and inside that partial, do something like:

echo $sf_request->getAttribute('showEmail') ? $ip_var : ''

Here you'll have to work out how the partial accesses the actual email value, which I presume is in the database table.

Also at the bottom of the link you gave, you can override a number of template items ("Customizing the Theme") inside your own application. That is worth looking at too.

I know it's not a full reply, but the admin generator is highly frustrating to work with unless you wrote the generator yourself! If the screen is otherwise trivial, you might consider rewriting it using the CRUD generator instead, as this creates a simple CRUD interface that can be hacked as much as you like.


Remember Palestine
Re: Other - IP blocking for a specific page element in a symfony 1.0 project [message #99048 is a reply to message #99040 ] Fri, 14 May 2010 11:35 Go to previous messageGo to next message
halfer  is currently offline halfer
Messages: 9535
Registered: January 2006
Location: West Midlands, UK
Faithful Member
I would recommend you add your "allowed IPs" to a db table, not app.yml. We relied heavily on app.yml in our early days, and now changes to common items require a deployment rather than a database change. We would rewrite some of this is we had the time!


Remember Palestine
Re: Other - IP blocking for a specific page element in a symfony 1.0 project [message #99178 is a reply to message #99048 ] Mon, 17 May 2010 06:37 Go to previous messageGo to next message
blurmy23  is currently offline blurmy23
Messages: 7
Registered: May 2010
Junior Member
Thanks a lot for the reply! Looks like this is still a little over my head so I'm going to have to dig into the tutorials a bit more to get things going.

Thanks again!
Re: Other - IP blocking for a specific page element in a symfony 1.0 project [message #99904 is a reply to message #99178 ] Thu, 27 May 2010 07:54 Go to previous messageGo to next message
blurmy23  is currently offline blurmy23
Messages: 7
Registered: May 2010
Junior Member
Ok, I feel like I'm on the verge of a great discovery, but being a novice I still have learning yet to do. So this is what I've got so far:

* If I change pc_email to a partial and throw a _pc_email.php into apps/backend/modules/user/templates/ I can override what displays for pc_email when going to http://blahblahblah/admin/user/show/id/6861/
* print $sf_request->getAttribute('pc_email') doesn't seem to work. If I print_r($sf_request); I can see my pc_email data, but because it's protected I can't output it directly
* Same goes for print_r($user);... the data's in there but of course I can't get it out

How do I get this data out? I'm almost tempted to parse the print_r for it @_@
Re: Other - IP blocking for a specific page element in a symfony 1.0 project [message #99913 is a reply to message #99040 ] Thu, 27 May 2010 10:30 Go to previous messageGo to next message
halfer  is currently offline halfer
Messages: 9535
Registered: January 2006
Location: West Midlands, UK
Faithful Member
The call $sf_request->getAttribute() should work fine - I use it a fair bit, though of course not as much as $sf_request->getParameter(). How are you setting it - in the parent action?


Remember Palestine
Re: Other - IP blocking for a specific page element in a symfony 1.0 project [message #99917 is a reply to message #99913 ] Thu, 27 May 2010 10:41 Go to previous messageGo to next message
blurmy23  is currently offline blurmy23
Messages: 7
Registered: May 2010
Junior Member
Right! So the latest hurdle... let's say I edit apps/backend/modules/user/actions/actions.class.php and add something like:

public function executeShow() {
$this->getRequest()->setAttribute('foo', 'bar');
parent::executeShow();
}

I can then retrieve the attribute foo in my partial without a problem. Progress! But I do a print_r on $this (in the executeShow()) and pc_mail doesn't even show up. Where did it go?
Re: Other - IP blocking for a specific page element in a symfony 1.0 project [message #99930 is a reply to message #99917 ] Thu, 27 May 2010 12:09 Go to previous messageGo to next message
blurmy23  is currently offline blurmy23
Messages: 7
Registered: May 2010
Junior Member
So I see that if I do something like parent::getUserOrCreate();
it gets the info I want, but it's still protected so I can't seem to do anything with it. Arghhh
Re: Other - IP blocking for a specific page element in a symfony 1.0 project [message #99931 is a reply to message #99930 ] Thu, 27 May 2010 12:20 Go to previous messageGo to next message
blurmy23  is currently offline blurmy23
Messages: 7
Registered: May 2010
Junior Member
Hoowah, here we go. So now I can get at the info I want like this:

public function executeShow() {
  $user = parent::getUserOrCreate();
  $pc_email = $user->getPcEmail();
  $this->getRequest()->setAttribute('pc_email', $pc_email);
  parent::executeShow();
}


Now the question is, "Is there a better way?"
Re: Other - IP blocking for a specific page element in a symfony 1.0 project [message #99983 is a reply to message #99931 ] Fri, 28 May 2010 06:47 Go to previous message
blurmy23  is currently offline blurmy23
Messages: 7
Registered: May 2010
Junior Member
The other question being: "While that works for executeShow(), why does it utterly bomb on executeList()?" X_X
Previous Topic:how to get database name
Next Topic:Form didn't return errors
Goto Forum:
  

powered by FUDforum - copyright ©2001-2004 FUD Forum Bulletin Board Software