phpBMS

Show
Ignore:
Timestamp:
04/07/09 11:44:18 (3 years ago)
Author:
nate
Message:
  • Merged Nathan branch back into trunk.
Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/phpbms/modules/base/include/users.php

    r427 r485  
    3939if(class_exists("phpbmsTable")){ 
    4040        class users extends phpbmsTable{ 
    41          
    42                 function updateRecord($variables, $modifiedby = NULL){   
    43                          
     41 
     42                var $usedLoginNames = array(); 
     43 
     44                function populateLoginNameArray(){ 
     45 
     46                        $querystatement=" 
     47                                SELECT 
     48                                        `id`, 
     49                                        `login` 
     50                                FROM 
     51                                        `users`; 
     52                                "; 
     53 
     54                        $queryresult = $this->db->query($querystatement); 
     55 
     56                        if($this->db->numRows($queryresult)){ 
     57                                while($therecord = $this->db->fetchArray($queryresult)){ 
     58 
     59                                        $login = $therecord["login"]; 
     60                                        $id = $therecord["id"]; 
     61                                        $this->usedLoginNames[$login]["id"] = $id; 
     62 
     63                                }//end while 
     64                        }else{ 
     65                                //if no valid login names, I put in a value that will 
     66                                //give the arrays a count but not actually match any realistic login names 
     67                                $login = "THIS is @ ve|2`/ D|_||\/|B |_0GI|\| and stupid too."; 
     68                                $id = -1; 
     69 
     70                                $this->usedLoginNames[$login]["id"] = $id; 
     71                        }//end if 
     72 
     73                }//end method 
     74 
     75 
     76                function verifyVariables($variables){ 
     77                        //---------[ check login names ]------------------------------ 
     78 
     79                        if(isset($variables["login"])){ 
     80                                if( $variables["login"] !== "" || $variables["login"] !== NULL ){ 
     81 
     82                                        if(!count($this->usedLoginNames)) 
     83                                                $this->populateLoginNameArray(); 
     84 
     85                                        if(!isset($variables["id"])) 
     86                                                $variables["id"] = 0; 
     87 
     88                                        if($variables["id"] < 0) 
     89                                                $variables["id"] = 0; 
     90 
     91                                        //check to see new login name is taken 
     92                                        $templogin = $variables["login"];// using this because it looks ugly to but the brackets within brackets 
     93                                        if( array_key_exists($variables["login"], $this->usedLoginNames) ){ 
     94 
     95                                                if( $this->usedLoginNames[$templogin]["id"] !== $variables["id"] ) 
     96                                                        $this->verifyErrors[] = "The `login` field must give an unique login name."; 
     97 
     98                                        }else{ 
     99                                                $this->availableProducts[$templogin]["id"] = -1;// impossible id put in (besides the type will through off the if anyways) 
     100                                        }//end if 
     101 
     102                                }else 
     103                                        $this->verifyErrors[] = "The `login` field must not be blank."; 
     104                        }else 
     105                                $this->verifyErrors[] = "The `login` field must be set."; 
     106 
     107                        //---------[ check email ]--------------------------------- 
     108                        if(isset($variables["email"])) 
     109                                if( $variables["email"] !== NULL && $variables["email"] !== "" && !validateEmail($variables["email"])) 
     110                                        $this->verifyErrors[] = "The `email` field must have a valid email or must be left blank."; 
     111 
     112                        //---------[ check booleans ]--------------------------------- 
     113                        if(isset($variables["revoked"])) 
     114                                if($variables["revoked"] && $variables["revoked"] != 1) 
     115                                        $this->verifyErrors[] = "The `revoked` field must be a boolean (equivalent to 0 or exactly 1)."; 
     116 
     117                        if(isset($variables["portalaccess"])) 
     118                                if($variables["portalaccess"] && $variables["portalaccess"] != 1) 
     119                                        $this->verifyErrors[] = "The `portalaccess` field must be a boolean (equivalent to 0 or exactly 1)."; 
     120 
     121                        if(isset($variables["admin"])) 
     122                                if($variables["admin"] && $variables["admin"] != 1) 
     123                                        $this->verifyErrors[] = "The `admin` field must be a boolean (equivalent to 0 or exactly 1)."; 
     124 
     125                        return parent::verifyVariables($variables); 
     126 
     127                }//end method --verifyVariables-- 
     128 
     129 
     130                function updateRecord($variables, $modifiedby = NULL){ 
     131 
    44132                        if($variables["password"]) 
    45133                                $this->fields["password"]["type"] = "password"; 
     
    48136 
    49137                        unset($this->fields["lastlogin"]); 
    50                  
     138 
    51139                        parent::updateRecord($variables, $modifiedby); 
    52                          
     140 
    53141                        if($variables["roleschanged"]==1) 
    54142                                $this->assignRoles($variables["id"],$variables["newroles"]); 
    55                          
     143 
    56144                        //reset field information 
    57145                        $this->fields = $this->db->tableInfo($this->maintable); 
    58146                } 
    59147 
    60          
    61                 function insertRecord($variables, $createdby = NULL){    
    62                          
     148 
     149                function insertRecord($variables, $createdby = NULL){ 
     150 
    63151                        $this->fields["password"]["type"] = "password"; 
    64152                        unset($this->fields["lastlogin"]); 
    65                                                  
     153 
    66154                        $theid = parent::insertRecord($variables, $createdby); 
    67          
     155 
    68156                        //reset field information 
    69157                        $this->fields = $this->db->tableInfo($this->maintable); 
     
    71159                        return $theid; 
    72160                } 
    73                  
     161 
    74162                function assignRoles($id,$roles){ 
    75163                        $querystatement="DELETE FROM rolestousers WHERE userid=".$id; 
    76164                        $queryresult=$this->db->query($querystatement); 
    77          
     165 
    78166                        $newroles=explode(",",$roles); 
    79          
     167 
    80168                        foreach($newroles as $therole) 
    81169                                if($therole!=""){ 
     
    84172                                } 
    85173                } 
    86                  
    87          
     174 
     175 
    88176                function displayRoles($id,$type){ 
    89177                        $querystatement="SELECT roles.id,roles.name 
    90                                                         FROM roles INNER JOIN rolestousers ON rolestousers.roleid=roles.id  
     178                                                        FROM roles INNER JOIN rolestousers ON rolestousers.roleid=roles.id 
    91179                                                        WHERE rolestousers.userid=".((int) $id); 
    92180                        $assignedquery=$this->db->query($querystatement); 
    93          
     181 
    94182                        $thelist=array(); 
    95                          
     183 
    96184                        if($type=="available"){ 
    97185                                $excludelist=array(); 
    98186                                while($therecord=$this->db->fetchArray($assignedquery)) 
    99187                                        $excludelist[]=$therecord["id"]; 
    100                                          
     188 
    101189                                $querystatement="SELECT id,name FROM roles WHERE inactive=0"; 
    102190                                $availablequery=$this->db->query($querystatement); 
    103191                                while($therecord=$this->db->fetchArray($availablequery)) 
    104192                                        if(!in_array($therecord["id"],$excludelist)) 
    105                                                 $thelist[]=$therecord;           
    106                         } else  
     193                                                $thelist[]=$therecord; 
     194                        } else 
    107195                                while($therecord=$this->db->fetchArray($assignedquery)) 
    108196                                        $thelist[]=$therecord; 
    109                                          
     197 
    110198                        foreach($thelist as $theoption){ 
    111199                                ?>      <option value="<?php echo $theoption["id"]?>"><?php echo htmlQuotes($theoption["name"])?></option> 
    112                 <?php  
     200                <?php 
    113201                        } 
    114202                }//end function 
     
    120208 
    121209                function delete_record(){ 
    122                          
     210 
    123211                        //passed variable is array of user ids to be revoked 
    124212                        $whereclause = $this->buildWhereClause(); 
    125                  
     213 
    126214                        $querystatement = "UPDATE users SET revoked=1,modifiedby=".$_SESSION["userinfo"]["id"]." WHERE ".$whereclause.";"; 
    127215                        $queryresult = $this->db->query($querystatement); 
    128                  
     216 
    129217                        $message = $this->buildStatusMessage(); 
    130218                        $message.=" revoked access."; 
    131                         return $message;         
    132                 } 
    133  
    134                  
     219                        return $message; 
     220                } 
     221 
     222 
    135223        }//end class 
    136224}//end if 
phpBMS vulnerability assesment provided by Orvant Inc. Copyright © 2010 Kreotek, LLC. All Rights reserved.