2
votes

I need to be able to add pages and then restrict these by different types of user: Anonymous, Partial and Full.

When registering, a user can enter all details to get a full registration or only half their details e.g don't need to enter address, telephone etc to gain a partial registration type.

Then when adding a page I need to be able to select whether anonymous, partial and/or full have access to it. If they don't then it still needs to show the summary of the page as a teaser but they won't have access to the main content until they have registered and signed in.

I have installed the Simple Access plugin which allows me to create groups but unsure how to implement the registration form so that if the user only enters the required fields they will become a Partial user, otherwise they will become a Full user. Any suggestions?

3

3 Answers

3
votes

You can use the Rules module. Create a triggered rule that runs on new user creation, then check the fields and finally assign the user a role accordingly.

2
votes

I've ended up using a hook to implement whether a user is a normal authorised user or a full user. Can someone please check the hook below is correct? Im new to Drupal so not sure if any other tables are affected when adding/deleting roles.

function module_user_update(&$edit, $account, $category) {

$dob = field_get_items('user', $account, 'field_dob');
$address1 = field_get_items('user', $account, 'field_address1');
$address2 = field_get_items('user', $account, 'field_address2');
$address3 = field_get_items('user', $account, 'field_address3');
$city = field_get_items('user', $account, 'field_city');
$postcode = field_get_items('user', $account, 'field_postcode');
$county = field_get_items('user', $account, 'field_county');
$telephone = field_get_items('user', $account, 'field_telephone');


    if(empty($dob[0]['value']) || empty($address1[0]['value']) || empty($address2[0]['value']) || empty($address3[0]['value']) || empty($city[0]['value']) || empty($postcode[0]['value']) || empty($county[0][$
    {
            $userid = $account->uid;
            //remove full role from db so user is only an authorised user
            db_query("DELETE FROM {users_roles} WHERE uid = '".$userid."' && rid = '5'");
    } else {
            $userid = $account->uid;
            //delete full role if it already exists so it doesnt go in twice
            db_query("DELETE FROM {users_roles} WHERE uid = '".$userid."' && rid = '5'");
            //insert full role
            db_query("INSERT INTO {users_roles} (rid, uid) VALUES ('5',$userid)");
    }

}

1
votes

You would do well to look into some of the beginning Drupal tutorials. Roles, rules, triggers and CCK (and content_permissions) -- those are the modules/concepts you'll be looking at learning about.

They will arm you with what you need. CCK will allow for you to create specific content types, content_permissions (included in CCK) will allow for you to set visibility based on a user's role, roles will allow for you to create a new group of users, and as @Laxman13 said, rules will allow for you to set up rules to do what needs to be done (i.e. add this user to X role), and triggers will provide you with the functionality to do that.