Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

#141 Assigning administrator privileges by username

open
nobody
None
5
2011-02-20
2011-02-20
JP
No

In Scuttle 0.9.0 you can assign administrator privileges by slightly changing services/userservice.php

function isAdmin($userid) {
return (
( $userid == 1 ) or // my username has user ID 1
( $userid ==23 ) // someone else's user ID
);

For readability, I want to be able to configure a username instead of a user-ID:

function isAdmin($userid) {
return (
( $userid == xyz['username_A'] ) or // my username has user ID 1
( $userid == xyz['username_B'] ) // someone else's user ID
);

but I haven't been able to figure out what xyz should read like. I figure that it needs a function from the same file:

function getUserByUsername($username)

But I know too little PHP to figure out how to retrieve the user-ID from the result. I think that function returns an array or a pointer to an array or so, that contains the whole database record (uId, username, password, uDatetime, uModified, name, email,homepage, uContent)

Suggestions anyone?

JP

Discussion

  • JP
    JP
    2011-10-16

    To make assigning admin privileges easier, I changed the original userservice.php with the following lines. Admin is assigned to named users on lines 140-142.

    127 ###
    128 ###
    129 ### JPH: Added code for easy admin assignment
    130 ###
    131 ###
    132 function getUIdByUsername($user) {
    133 $userinfo = $this->getUserByUsername($user);
    134 $userid =& $userinfo[$this->getFieldName('primary')];
    135 return $userid;
    136 }
    137
    138 function isAdmin($userid) {
    139 return (
    140 ( $userid == $this->getUIdByUsername( 'some_user' ) )
    141 or ( $userid == $this->getUIdByUsername( 'other_user' ) )
    142 or ( $userid == $this->getUIdByUsername( 'third_user' ) )
    143 );
    144 }