Redirect error with dashboard

A place to discuss development of the Xataface core.

Redirect error with dashboard

Postby rlevin » Fri Apr 08, 2011 8:06 am

I am getting this message "The page isn't redirecting properly".

I have a directory in the main called Dashboard. In this directory I have my actions.ini, conf.ini, and index.php

actions.ini:
[mydashboard]
permission=view
--------------------------
conf.ini:
[_database]
all my login info here

[_tables]
dashboard = "Dashboard"
myTable = "test"
---------------------------
In this Dashboard folder I have folder called actions with a file named dashboard.php

dashboard.php:
Code: Select all
<?php
class actions_dashboard {
    function handle(&$params){
        $bib= df_get_records_array('myTable', array());
        df_display(array('myTable'=>$bib), 'dashboard.html');
    }
}
?>


In this Dashboard folder I have folder called conf with a file named ApplicationDelegate.php

ApplicationDelegate.php:
Code: Select all
<?php
/**
* A delegate class for the entire application to handle custom handling of
* some functions such as permissions and preferences.
*/
class conf_ApplicationDelegate {
    /**
     * Returns permissions array.  This method is called every time an action is
     * performed to make sure that the user has permission to perform the action.
     * @param record A Dataface_Record object (may be null) against which we check
     *               permissions.
     * @see Dataface_PermissionsTool
     * @see Dataface_AuthenticationTool
     */
     function getPermissions(&$record){
         $auth =& Dataface_AuthenticationTool::getInstance();
         $user =& $auth->getLoggedInUser();
         if ( !isset($user) ) return Dataface_PermissionsTool::NO_ACCESS();
             // if the user is null then nobody is logged in... no access.
             // This will force a login prompt.
         $role = $user->val('role');
         return Dataface_PermissionsTool::getRolePermissions($role);
             // Returns all of the permissions for the user's current role.
      }
     
     function beforeHandleRequest(){
        $app =& Dataface_Application::getInstance();
        $query =& $app->getQuery();
        if ( $query['-table'] == 'dashboard' and ($query['-action'] == 'browse' or $query['-action'] == 'list') ){
           $query['-action'] = 'dashboard';
           }
      }
     
}
?>


In this Dashboard folder I have folder called tables with 2 other folders inside called dashboard and myTable. This includes my class delegate files.
In this Dashboard folder I have another folder called templates with file called dashboard.html

dashboard.html:
Code: Select all
{use_macro file="Dataface_Main_Template.html"}
    {fill_slot name="main_column"}
        <h1>My Management System (RCMS)</h1>
       
        <p>This system allows you to manage your publications and publish
        them on the web.  Some common actions you may perform with this system
        include:
            <ul>
                <li><img src="{$ENV.DATAFACE_URL}/images/add_icon.gif"/>
                    <a href="{$ENV.DATAFACE_SITE_HREF}?-table=myTable&-action=new">
                       Do Something</a>
                </li>
                <li><img src="{$ENV.DATAFACE_URL}/images/edit.gif"/>
                   Edit existing bibliography:
                   <select onchange="window.location.href=this.options[this.selectedIndex].value">
                    <option value="">Select ...</option>
                    {foreach from=$myTable item=bibliography}
                        <option value="{$bibliography->getURL('-action=edit')}">
                            {$bibliography->getTitle()}
                        </option>
                   
                    {/foreach}
                </select>
                </li>
                <li><img src="{$ENV.DATAFACE_URL}/images/file.gif"/>
                    Embed your bibliography in a webpage:
                    <select onchange="window.location.href=this.options[this.selectedIndex].value">
                    <option value="">Select ...</option>
                    {foreach from=$myTable item=bibliography}
                        <option value="{$bibliography->getURL('-action=view')}#embed">
                            {$bibliography->getTitle()}
                        </option>
                   
                {/foreach}
                </select>
                </li>
               
            </ul>
    {/fill_slot}
{/use_macro}


Whats causing the redirect error?
Last edited by rlevin on Fri Apr 08, 2011 8:14 am, edited 2 times in total.
rlevin
 
Posts: 32
Joined: Thu Mar 10, 2011 11:40 am

Re: Redirect error with dashboard

Postby rlevin » Fri Apr 08, 2011 8:09 am

heres the index.php:
Code: Select all
<?php

require_once '/xataface/dataface-public-api.php';

df_init(__FILE__, '/xataface');

$app =& Dataface_Application::getInstance();

$app->display();
?>
rlevin
 
Posts: 32
Joined: Thu Mar 10, 2011 11:40 am

Re: Redirect error with dashboard

Postby shannah » Fri Apr 08, 2011 12:10 pm

This is likely an issue with permissions. Probably your user doesn't have permission to access your dashboard action, so it redirects to the login page, but you keep on changing the action back to dashboard.... hence endless loop of redirects.

By your samples here I'm a little puzzled, why is your actions.ini entry called [mydashboard] but everywhere else you reference it as "dashboard"?

-Steve
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm

Re: Redirect error with dashboard

Postby rlevin » Mon Apr 11, 2011 6:07 am

The [mydashboard] was a typo. Its actually [dashboard].

I have a permissions.ini file:
[ADMIN]
DataGrid:view_grid=1
DataGrid:update=1
----------------------------------
Heres my dashboard delegate file:
Code: Select all
<?php
class tables_dashboard {
    function getPermissions(&$record){
        if ( getUser() ){
            return Dataface_PermissionsTool::ALL();
        }
        return null;
    }
}

?>


I see what your saying about the endless redirects to the dashboard. I simply copied and pasted your code from the Creating_a_Dashboard page. I made those changes above to the permissions yet I still receive the error. I am stumped.
rlevin
 
Posts: 32
Joined: Thu Mar 10, 2011 11:40 am

Re: Redirect error with dashboard

Postby shannah » Tue Apr 12, 2011 12:02 pm

Question: Do you want to require users to log in to see your dashboard?

What is happening right now is that your [dashboard] action requires the "view" permission to access it. Currently you are giving anonymous users "NO ACCESS", which doesn't include the "view" permission. So when an anonymous user tries to access your site with any action, say "list", your beforeHandleRequest() method is changing this action to "dashboard" (correctly), but when xataface then discovers that the user doesn't have access to the "dashboard" action, it redirects the user to the "login_prompt" action. But when loading the the "login_prompt" action, your beforeHandleRequest method again preprocesses the request and switches the action to "dashboard", which brings us full circle in an infinite loop.

Solutions:

1. Give anonymous users access to the dashboard action
2. In your beforeHandleRequest method, don't change the action to "dashboard" if the action is "login_prompt"

-Steve
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm

Re: Redirect error with dashboard

Postby rlevin » Tue Apr 12, 2011 12:41 pm

Yes, I want users to log in to see the dashboard.

Thank you for logically explaining it. I'll try it tomorrow morning.
rlevin
 
Posts: 32
Joined: Thu Mar 10, 2011 11:40 am

Re: Redirect error with dashboard

Postby rlevin » Wed Apr 13, 2011 7:48 am

Code: Select all
<?php
class conf_ApplicationDelegate {
   

     function getPermissions(&$record){
         $auth =& Dataface_AuthenticationTool::getInstance();
         $user =& $auth->getLoggedInUser();
         if ( !isset($user) ) return Dataface_PermissionsTool::NO_ACCESS();
             // if the user is null then nobody is logged in... no access.
             // This will force a login prompt.
         $role = $user->val('role');
         return Dataface_PermissionsTool::getRolePermissions($role);
             // Returns all of the permissions for the user's current role.
      }
     
    function beforeHandleRequest(){
     
        $app =& Dataface_Application::getInstance();
    $query =& $app->getQuery();
    if ( $query['-table'] == 'dashboard' and ($query['-action'] == 'browse' or $query['-action'] == 'list') ){
       if($query['-action'] = 'login_prompt')
       {

       }
       else
       {
        $query['-action'] = 'dashboard';
      }
    }
       
       
    }
?>


I just added the if $query['-action'] = 'login_prompt' statement. Now I get an empty page.
rlevin
 
Posts: 32
Joined: Thu Mar 10, 2011 11:40 am

Re: Redirect error with dashboard

Postby shannah » Wed Apr 13, 2011 8:00 am

Check your error log.
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm

Re: Redirect error with dashboard

Postby rlevin » Wed Apr 13, 2011 8:20 am

Just tells me its returning a 500, which is pretty general...
rlevin
 
Posts: 32
Joined: Thu Mar 10, 2011 11:40 am

Re: Redirect error with dashboard

Postby shannah » Wed Apr 13, 2011 9:05 am

500 just means there was an error. It must say more than that in the error log.

It could be a syntax error, or just about anything else.
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm


Return to Xataface Developers

Who is online

Users browsing this forum: No registered users and 1 guest

cron
Powered by Dataface
© 2005-2007 Steve Hannah All rights reserved