diff --git a/src/classes/Account.php b/src/classes/Account.php index b424ef6..4e9ef82 100644 --- a/src/classes/Account.php +++ b/src/classes/Account.php @@ -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 @@ -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){ @@ -172,7 +173,7 @@ public static function password($password){ /** * Generate key * - * @return void + * @return string * @author Thibaud Rohmer */ private function key(){ @@ -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; } @@ -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){ diff --git a/src/classes/Group.php b/src/classes/Group.php index 176029f..991d10a 100644 --- a/src/classes/Group.php +++ b/src/classes/Group.php @@ -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 @@ -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; @@ -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); } @@ -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); @@ -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();