Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Using CGI and perl to specify modes which control page functionality.

by Bowlslaw (Initiate)
on Jul 02, 2013 at 14:42 UTC ( #1042028=perlquestion: print w/ replies, xml ) Need Help??
Bowlslaw has asked for the wisdom of the Perl Monks concerning the following question:

Hello, I'm trying to figure out how I would use "modes" to control page functionality. For example, I have a page link:

<a href="/viewquestions.dhtml~useridtext~">View and answer questions</a>

I must be able to change the functionality of the page, which would currently display a list of questions and answers. However, I also need it to be in "adminmode", in which the user/admin will be able to edit the questions/answers file himself. How would I do this with "modes"? So far, I have come up with:

<a href="/viewquestions.dhtml~useridtext~$action=adminmode"> if($action eq 'adminmode') { do stuff } else { do other stuff }

but I am not sure if this is correct. How do I specify whether the user is in "adminmode" or not?

Comment on Using CGI and perl to specify modes which control page functionality.
Select or Download Code
Re: Using CGI and perl to specify modes which control page functionality.
by Anonymous Monk on Jul 02, 2013 at 14:48 UTC

      For more perspective on how-to organize the urls in the best human oriented way read Clean URL/RESTful (means GET/POST/PUT/PATCH/DELETE )

        Thanks, but that will take me a long time to read and understand it all. I have a basic understanding, and the most important thing for me right now is to finish this. I can't find code examples anywhere.
Re: Using CGI and perl to specify modes which control page functionality.
by derby (Abbot) on Jul 02, 2013 at 17:05 UTC

    What's the server side process for .dhtml files? Are they generated via perl cgi script? If so, what's wrong with params? /viewquestions.dhtml?action=adminmode"

    Then the question moves to when constructing the link, whether or not you need add the params. That can be solved tons of ways but normally you have some type of session associated and within that session there is something that identifies the user as an admin or not. If the user is admin, construct the link with the param, else construct the link without it.

    -derby
Re: Using CGI and perl to specify modes which control page functionality.
by Shuraski (Scribe) on Jul 04, 2013 at 15:11 UTC

    If you move to an MVC type web templating engine like Catalyst, managing authorizations becomes very easy. You can then filter the content that is viewable depending on the authorization settings of the logged-in user.

    Reading this section of the Catalyst Manual will give you an idea of how it works.

    Basically, you can then manage content viewed in your controllers:

    # Check user roles if ($c->check_user_roles('admin')) { my $action = whatever you want your action to be here ({ for example, you can call a specific template from template toolk +it and display content tailored for that user there }) }

    Hope this helps!

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1042028]
Front-paged by Arunbear
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (3)
As of 2014-09-18 01:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (104 votes), past polls