Redirection and logging-off

From GruppoZenit
Jump to: navigation, search

Z-CMS redirect tag zcms:redirect can be used to perform redirection from one webpage to another.


The redirect tag can be used as follows:

<zcms:redirect url="/authenticated"/>

Z-CMS provides the following plugin tag to issue log-off for the logged-in user:

<zcms:plugin.logoff/>


Example: sample usage that includes form handling and a reserved area

Consider a Site in which users who are both logged-in and not logged-in can add blog entries. Users can login using the login form if required and for logged-in users, a specific blog form will be presented.


A Content Model named as "tuser" is created with the three attributes "name", "login" and "password".

Redirection and logging-off 1.png

Another Content Model named as "blog" is also created with the two attributes "title" and "description".

Redirection and logging-off 2.png

A Widget is created with its name as "Login" and type as "Form" to contain the following Z-CMS "content-form".

<zcms:content-form name="tuser" type="AUTH" action="tuserlogin" method="post">
   <zcms:component type="text" name="txtlogin" attribute="login" /> <br />
   <zcms:component type="password" name="txtpassword" attribute="password" />
   <zcms:submit form="tuser"><a>Click to login</a></zcms:submit>
   <zcms:validate checkfor="required" name="txtlogin">Please enter username</zcms:validate>
   <zcms:validate checkfor="required" name="txtpassword">Please enter password</zcms:validate>
   <zcms:status event="SUCCESS" url="authenticated" />
   <zcms:status event="AUTH_FAILED" url="authfail" />
</zcms:content-form>

Another Widget is created with its name as "Blog" and type as "Form" to contain the blog "content-form" for users who are not logged-in.

<zcms:content-form name="blog" type="INSERT" action="saveblog" method="post">
   <zcms:component type="text" name="txttitle" attribute="title" /> <br />
   <zcms:component type="textarea" name="txtdescription" attribute="description" /> <br />
   <zcms:submit form="blog"><a>click to submit</a></zcms:submit> <br />
   <zcms:validate checkfor="required" name="txttitle">Please enter title</zcms:validate>
   <zcms:validate checkfor="required" name="txtdescription">Please enter description</zcms:validate>
   <zcms:status event="SUCCESS" url="success"></zcms:status>
   <zcms:status event="ERROR" url="fail"></zcms:status>
</zcms:content-form>

Another Widget is created with its name as "Blog" and type as "Form2" to contain the blog "content-form" for users who are logged-in.

<zcms:content-form name="blog" type="INSERT" action="saveblog" method="post">
   <zcms:message for="*" />
   <zcms:component type="text" name="txttitle" attribute="title" /> <br />
   <zcms:component type="textarea" name="txtdescription" attribute="description" /> <br />
   <zcms:submit form="blog"><a>click to submit</a></zcms:submit> <br />
   <zcms:validate checkfor="required" name="txttitle">Please enter title</zcms:validate>
   <zcms:validate checkfor="required" name="txtdescription">Please enter description</zcms:validate>
   <zcms:status event="SUCCESS" url="#">Successfully inserted</zcms:status>
   <zcms:status event="ERROR" url="#">Insert failed</zcms:status>
</zcms:content-form>

Relevant webpages are created as follows:

  • "index.xhtml" Page Identifier: "home".
<zcms:pagestart />
   <head>
      <zcms:pagehead />
         <title> Title goes here </title>
   </head>
   <body>
      <b>Homepage</b>
         <br /><br /><br />
            <zcms:include widget="Blog" type="Form" />
         <br /><br /><br />
      <a href="/login">Click here to login</a>
   </body>
<zcms:pageend />
  • "login.xhtml" Page Identifier: "login".
<zcms:pagestart />
   <head>
      <zcms:pagehead />
         <title> Title goes here </title>
   </head>
   <body>
      <b>Loginpage</b>
         <br /><br /><br />
            <zcms:unreserved>
               <zcms:include widget="Login" type="Form" />
            </zcms:unreserved>
            <zcms:reserved>
               <zcms:redirect url="/authenticated" />
            </zcms:reserved>
         <br /><br /><br />
       <a href="/home">Back to home</a>
   </body>
<zcms:pageend />
  • "auth.xhtml" Page Identifier: "authenticated".
<zcms:pagestart />
   <head>
      <zcms:pagehead />
         <title> Title goes here </title>
   </head>
   <body>
      <b>Authpage</b>
         <zcms:unreserved>
            <zcms:redirect url="/login" />
         </zcms:unreserved>
            <br /><br /><br />
               <zcms:include widget="Blog" type="Form2" />
            <br /><br /><br />
      <a href="/logout">Click here to logout</a>
   </body>
<zcms:pageend />
  • "logout.xhtml" Page Identifier: "logout".
<zcms:pagestart />
   <head>
      <zcms:pagehead />
         <title> Title goes here </title>
   </head>
   <body>
      <zcms:plugin.logoff />
      <zcms:redirect url="/login" />
   </body>
<zcms:pageend />
  • "success.xhtml" Page Identifier: "success".
<zcms:pagestart />
   <head>
      <zcms:pagehead />
      <title> Title goes here </title>
   </head>
   <body>
      <b>Successfully inserted</b>
         <br /><br /><br />
            <a href="/authenticated">Click here to go to authenticated page</a>
         <br /><br /><br />
      <a href="/home">Back to home</a>
   </body>
<zcms:pageend />
  • "fail.xhtml" Page Identifier: "fail".
<zcms:pagestart />
   <head>
      <zcms:pagehead />
      <title> Title goes here </title>
   </head>
   <body>
      <b>Insert failed</b>
         <br /><br /><br />
            <a href="/authenticated">Click here to go to authenticated page</a>
         <br /><br /><br />
      <a href="/home">Back to home</a>
   </body>
<zcms:pageend />
  • "‘authfail.xhtml" Page Identifier: "authfail"
<zcms:pagestart />
   <head>
      <zcms:pagehead />
      <title> Title goes here </title>
   </head>
   <body>
      <b>Authentication failed</b>    
         <br /><br /><br />
         <a href="/login">Back to login page</a>
         <br /><br /><br />
         <a href="/home">Back to home</a>
   </body>
<zcms:pageend />


By inserting inside the webpage the above mentioned code it is possible to manage the redirection and logging-off of the page.


See also

Personal tools
Namespaces

Variants
Actions
Toolbox