Danh mục

Embedding Perl in HTML with Mason Chapter 8: Building a Mason Site-P2

Số trang: 29      Loại file: pdf      Dung lượng: 48.37 KB      Lượt xem: 6      Lượt tải: 0    
Thu Hiền

Hỗ trợ phí lưu trữ khi tải xuống: 15,000 VND Tải xuống file đầy đủ (29 trang) 0

Báo xấu

Xem trước 3 trang đầu tiên của tài liệu này:

Thông tin tài liệu:

Tham khảo tài liệu embedding perl in html with mason chapter 8: building a mason site-p2, công nghệ thông tin, kỹ thuật lập trình phục vụ nhu cầu học tập, nghiên cứu và làm việc hiệu quả
Nội dung trích xuất từ tài liệu:
Embedding Perl in HTML with Mason Chapter 8: Building a Mason Site-P2 Chapter 8: Building a Mason Site-P2• left_side_menu.masThis component is longer than any of the previous ones, but not significantlymore complicated. Several features are worth noting here.The first is that the menu changes based on whether or not the return valuefrom $User->is_logged_in() is true. The $User object wasgenerated in the /syshandler component and may represent either a guestuser or a real logged-in user.If a user has logged in, she sees options that allow her to create a newproject, edit any projects for which she may have editing access, change heruser account information, and log out. The link to edit projects appears onlyif she actually has editing access to one or more projects.Note that we construct all URLs using the /lib/url.mas component, which wewill examine later. This component handles the construction of properlyescaped URLs of arbitrary complexity. Using this component for all URLswould make it easy to add in something like URL-based sessions later on.For the Logout URL, we are regenerating the URL, and query string, if any,for the current page. We do this because the component that handles logouts,/users/logout.html, will redirect the client back to the page where she clickedon the Logout link.Getting back to the menu component, we can see that if the user is notlogged in, we generate a form that POSTs to the /user/login_submit.htmlcomponent. Again, we will be passing in the current URL and query stringparameters to the login component so that it can send the user back whereshe came from, with either a cookie indicating a successful login or an errormessage. That error message is handled just above where the form starts,where we check the variable $login_error.We take advantage of the fact that a POST request can also have a querystring in order to put the %caller_args hash into the query string, wherewe can be sure that keys and values will be received by the server in theright order. If we put the keys and values in the form itself as hidden fields,there is no guarantee that the browser will submit them in the order wespecify.A bit further on, we see that if the $User->is_admin() method returnstrue we add a few extra links for the site administrators.The section for this component shows a common applicationof filtering. We first determine the URL for our current page. Then, if thereis a link in the menu that matches that page, we replace the anchor tag () with a bold tag ( ).We need to special-case the URL /index.html because the link for thisparticular page is simply . We do this with a regularexpression so that itll work properly if we decide to add links to otherdirectories here in the future. The site Welcome, username%> Home Search All the projects Browse by category % if ( $User->is_logged_in ) { Add a newproject % if ( $User->has_projects ) { Edit one of your projects % } % } % if ( $User->is_logged_in ) { &>>Logout Edit youraccount % } elsif ( $r->uri !~ m,/login_form, ) { Login % if ($login_error) { % } query => { caller_url => $r->uri, caller_args =>\%query_args } &> method=POST> Username: Password: path =>/users/forgot_password.html &>>Forgot mypassword New user % } % if ($User->is_admin) { Admin Edit users Editcategories % } Complaints /Compliments? $username => $login_error => my %query_args = $m->request_args; # These arguments are intended for use on thispage and do not need # to be passed through to the login_submit.htmlcomponent delete @query_args{ username, login_error }; (my $url = $r->uri) =~ s/index.html$//; $url = $m->scomp( /lib/url.mas, path => $url); s{([^ • /lib/url.masThe purpose of this component is to construct a properly escaped andformatted query string based on the param ...

Tài liệu được xem nhiều: