Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix: user with uppercase letters in its username broke the Groups page #333

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 30 additions & 23 deletions src/classes/Account.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,14 +111,15 @@ public function __construct($login=NULL,$key=NULL){
//throw new Exception("Login $login not found");
return false;
}

/**
* Creates a new account in the base
*
* @param string $login
* @param string $password
* @author Thibaud Rohmer
*/

/**
* Creates a new account in the base
*
* @param string $login
* @param string $password
* @author Thibaud Rohmer
* @return bool
*/
public static function create($login, $password, $verif, $groups=array(),$name='',$email=''){

// Check if login already exists
Expand Down Expand Up @@ -162,7 +163,7 @@ public static function create($login, $password, $verif, $groups=array(),$name='
* Encrypt password
*
* @param string $password
* @return void
* @return string
* @author Thibaud Rohmer
*/
public static function password($password){
Expand All @@ -172,7 +173,7 @@ public static function password($password){
/**
* Generate key
*
* @return void
* @return string
* @author Thibaud Rohmer
*/
private function key(){
Expand Down Expand Up @@ -265,24 +266,30 @@ public function save(){
$xml->asXML($xml_infos);
}

/**
* Edit an account
*
* @param string $login
* @param string $old_password
* @param string $password
* @param string $name
* @param string $email
* @author Thibaud Rohmer
*/
/**
* Edit an account
*
* @param string $login
* @param string $old_password
* @param string $password
* @param string $name
* @param string $email
* @param array $groups
* @param string|null $language
* @throws Exception
* @author Thibaud Rohmer
*/
public static function edit($login=NULL, $old_password=NULL, $password=NULL, $name=NULL, $email=NULL, $groups=array(), $language=NULL){
/// Only the admin can modify other accounts
if( !CurrentUser::$admin && $login != CurrentUser::$account->login ){
return;
}

if(isset($login) && (preg_match("/^[A-Z][a-zA-Z -]+$/", $login) === 0) ){
$acc = new Account($login);
if(isset($login)){
$acc = new Account($login);
if(!$acc){
throw new Exception("Error: user with username '$login' not found.");
}
}else{
$acc = CurrentUser::$account;
}
Expand Down Expand Up @@ -415,7 +422,7 @@ public static function findAll(){
* Returns the rights of an account
*
* @param string $login
* @return void
* @return array
* @author Thibaud Rohmer
*/
public static function rights($login){
Expand Down
63 changes: 33 additions & 30 deletions src/classes/Group.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,14 @@ class Group
{
public $name;
public $rights;

/**
* Find group in base.
*
* @param string $name
* @author Thibaud Rohmer
*/

/**
* Find group in base.
*
* @param string $name
* @throws Exception
* @author Thibaud Rohmer
*/
public function __construct($name = NULL){

/// Check if group file exists
Expand Down Expand Up @@ -98,14 +99,15 @@ public static function create_group_file(){
Group::create("user");
}

/**
* Create group and save into base
*
* @param string $name
* @param string $rights
* @return void
* @author Thibaud Rohmer
*/
/**
* Create group and save into base
*
* @param string $name
* @param array $rights
* @return void
* @throws Exception
* @author Thibaud Rohmer
*/
public static function create($name,$rights=array()){
if(!isset($name)||strlen($name)<1){
return;
Expand All @@ -126,7 +128,7 @@ public static function create($name,$rights=array()){
$xml_rights=$g->addChild('rights');

foreach($rights as $r)
$xml_right->addChild($r);
$xml_rights->addChild($r);

$xml->asXML(CurrentUser::$groups_file);
}
Expand Down Expand Up @@ -160,12 +162,12 @@ public static function delete($groupname){
$xml->asXML($xml_infos);
}

/**
* Save group into base
*
* @return void
* @author Thibaud Rohmer
*/
/**
* Save group into base
* @return void
* @throws Exception
* @author Thibaud Rohmer
*/
public function save(){
/// Load file
$xml = simplexml_load_file(CurrentUser::$groups_file);
Expand Down Expand Up @@ -211,14 +213,15 @@ public static function exists($name){

return false;
}

/**
* Returns the rights of the group
*
* @param string $name
* @return void
* @author Thibaud Rohmer
*/

/**
* Returns the rights of the group
*
* @param string $name
* @return array
* @throws Exception
* @author Thibaud Rohmer
*/
public static function rights($name){
$rights = array();

Expand Down