views:

226

answers:

2

I am working on a website which already has user access set up so that only members who are logged in can see certain pages. Now i need to go in and make the access for logged in users more specific. So, anyone who logs in can see the site, but there are 2 pages (called PDQ and Comm Plus) that should only be accessed by users that have PDQ or Comm Plus access. I use a filemaker 10 database to keep track of user information. If the user has PDQ access, then PDQ=1 in the database. the website is coded in Drupal,php, and html.

So right now I have a good idea of what to do but there are some pieces missing and im not very familiar with drupal or filemaker. I need for the page to get the user information and see what the value of PDQ is in the database. If 1 then grant access to the page, and if 0 go to the access denied page.

Here is what I have so far

<?php require_once('DatabaseName');

global $user;
//looks at the current user
$use = $user->uid;

//Not sure what goes here. I need code that looks at the filemaker database to see
//what the value of PDQ is and then stores it in a variable.

if (!session_id()) session_start();
if (!isset($variableGoesHere) || $variableGoesHere == '0'){
  drupal_goto("access-denied");
  exit();
  }
?>

Any help would be greatly appreciated. Also, let me know if im on the right track or if I need to be looking somewhere else. Thanks!

+2  A: 

First of all, using Drupal and not using the Drupal system to store info is a bad idea. If you use Drupal, you can use an external source to do the login, but your users should have a drupal user.

When your users are Drupal users things get a lot easier. You can use the Drupal access control system to check access etc.

If Drupal is serving the page, you should never write code like you have shown, hook_menu which is how you register paths has a access callback option, where you can handle your access, or you can just check if the user has a permission. This stuff only applies if you are doing the stuff in a custom module, which is what it seems like you are doing.

In any regard you should use the drupal_access_denied function if you want to return access denied yourself.

googletorp
I should probably provide a little more background. on my situation so that I may get a better idea of what I need to do. I do agree that it would be much easier to deal with user access on the Drupal system, but I took over this project with a website that was already up and running and databases already in place. So, we already have thousands of users in our Filemaker database with the correct boxes checked for each user to determine access. At this point it would take too long to manually enter the access restrictions for all of the users on the Drupal system. ....
NickPatt
If there where a simple way to merge databases or transfer some fields over that would be helpful. If not I am still looking for some php code that can help with my problem. I just need to make more specific access. Another quick note. I dont actually enter code as previously shown on the Drupal pages themselves. I usually do something like this<?phpinclude($_SERVER['DOCUMENT_ROOT'].'/folder/filename');?>This calls a file on our web-server and thats where I add in php and html. I am still looking for a solution. Please if anybody has any ideas please let me know. Thanks!
NickPatt
I agree with this comment -- if you're using Drupal then you should be using the Drupal user module; if you don't use basic stuff like that then you may as well not use Drupal at all. I'm working on a Drupal system that has to hook into an existing back-end database, including user accounts. We've worked out a mechanism such that our logins use the back-end DB but create dummy user accounts in Drupal that match the one in the back-end. This allows us to login using out back-end DB but still get the benefits of the Drupal Users module.
Spudley
Here's what we do: We have a custom login form. The input on that is posted to our back-end DB to log in. If that succeeds, then it tries to log in using the same credentials in Drupal. If that fails then the user is still valid because the back-end login was ok, so it assumes that it is the first time this user has visited the site, so it creates them as a Drupal user. We then have a Drupal user for every back-end user account who has visited the site. Now all we had to do was modify Drupal's account management code to post to the back-end DB as well as create/amend account details on Drupal.
Spudley
A: 

I figured this out a long time ago, but I never got around to answering the question. So heres what I did

    $WebAuth_find = $FILMAKER->newFindCommand('WebAccess');
$Search_findCriterions = array('Access::cntdPhoneNumberDisplayCalc'=>"==".$find,'Access::phoneType'=>"E-mail",'Access::phoneMain'=>"==1",'LoginAccess'=>'1');
foreach($Search_findCriterions as $key=>$value) {
    $WebAuth_find->AddFindCriterion($key,$value);
}
$WebAuth_Result = $WebAuth_find->execute();
if (FileMaker::isError($WebAuth_Result) && $WebAuth_Result->code == 401) {
                echo "FM ERROR CODE: ".$WebAuth_Result->code."<br>"."ERROR: ".$WebAuth_Result->getMessage();

This identifies the current user in the Filemaker database under the WebAccess layout. It throws an error message if there is a problem. Now that I am looking at the current user I have it look to see what is in the Comm Plus and PDQ fields in the database, and create a session to hold the information.

else{
 $FinalResult = current($WebAuth_Result->getRecords());

 $_SESSION['district']= $district;
 $PDQ = $FinalResult->getField('PDQ_subscription');
 $_SESSION['PDQ'] = $PDQ;
 $CommPlus = $FinalResult->getField('CommPlus_subscription');
 $_SESSION['CommPlus'] = $CommPlus;

Then I just add the following code to the top of whatever page I want to restrict access to. It looks at the session to see if the current user has credentials if not they are directed to the access denied page.

$PDQ_check = $_SESSION['PDQ'];
    if (!isset($PDQ_check) || $PDQ_check == '' || $PDQ_check == '0'){


       drupal_goto("access-denied");


    exit();


       }
NickPatt