User Registration

I'm trying to implement User Registration on a database and have been following along with http://xataface.com/documentation/how-to/user_registration
However, I'm finding it not clear and apparently missing some pertinent details about just how to accomplish this. For example, the following code snippet:
1. Where exactly does this code go? How much of of do I really need, all or only some? I've put all of it in my ApplicationDelegate.php but I don't think it goes there. I've already got some other permissions stuff there that works OK, except it doesn't enable registration. In the tutorial the above code snippet is preceded by: "Here is a snippet from the Web Auction users table delegate class to show how the permissions are defined:". What exactly does that mean? Should I create a UsersTableDelegate.php in the Users Table folder and put it there? Would that then conflict with the permissions already in the ApplicationDelegate.php?
2. When I access the application, it displays the database immediately, and does not stop at the login screen, so apparently the added code is overriding the previous authentication code that worked OK. The user then has correct permissions, ie can add and edit/delete only records user adds. The "login" link displays in the upper right and if I select that it will then display the login form and the "Register" link opens the registration form, but allows the new User to select both the "User" and "Admin" roles. A new registrant should automatically be assigned the role User and not have access to changing that. How do I make that happen?
3. I pulled all of the above code snippet out of my ApplicationDelegate.php and created the file UsersTableDelegate.php inside the /tables/Users folder thus:
That got my login back, along with the Registration link. However, when I select the Registration link, no registration form displays. Am I getting closer?
Much appreciate your suggestions. By the way, the authentication and permissions code you did for me is working perfectly.
Michael
However, I'm finding it not clear and apparently missing some pertinent details about just how to accomplish this. For example, the following code snippet:
- Code: Select all
/**
* Permissions for records of the user table.
*/
function getPermissions(&$record){
if ( isAdmin() or ( $record and ($record->strval('username') == getUsername()))) {
$perms = Dataface_PermissionsTool::ALL();
} else {
$perms = Dataface_PermissionsTool::READ_ONLY();
}
$perms['new'] = 1; // Everyone gets the 'new' permission or registration won't work
return $perms;
}
/**
* Permissions for the username field.
*/
function username__permissions(&$record){
$perms = $this->role__permissions(&$record);
$perms['new'] = 1; // Everyone gets the 'new' permission
return $perms;
}
/**
* Permissions for the role field. The role field pertains to the user's
* access privileges so nobody should be able to change this except
* administrators.
*/
function role__permissions(&$record){
if ( isAdmin() ){
return Dataface_PermissionsTool::ALL();
} else {
return Dataface_PermissionsTool::READ_ONLY();
}
}
1. Where exactly does this code go? How much of of do I really need, all or only some? I've put all of it in my ApplicationDelegate.php but I don't think it goes there. I've already got some other permissions stuff there that works OK, except it doesn't enable registration. In the tutorial the above code snippet is preceded by: "Here is a snippet from the Web Auction users table delegate class to show how the permissions are defined:". What exactly does that mean? Should I create a UsersTableDelegate.php in the Users Table folder and put it there? Would that then conflict with the permissions already in the ApplicationDelegate.php?
2. When I access the application, it displays the database immediately, and does not stop at the login screen, so apparently the added code is overriding the previous authentication code that worked OK. The user then has correct permissions, ie can add and edit/delete only records user adds. The "login" link displays in the upper right and if I select that it will then display the login form and the "Register" link opens the registration form, but allows the new User to select both the "User" and "Admin" roles. A new registrant should automatically be assigned the role User and not have access to changing that. How do I make that happen?
3. I pulled all of the above code snippet out of my ApplicationDelegate.php and created the file UsersTableDelegate.php inside the /tables/Users folder thus:
- Code: Select all
<?php
class conf_UsersTableDelegate {
all of the above code snippet...
}
?>
That got my login back, along with the Registration link. However, when I select the Registration link, no registration form displays. Am I getting closer?

Much appreciate your suggestions. By the way, the authentication and permissions code you did for me is working perfectly.
Michael