[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Noalyss-commit] [noalyss] 07/13: Code cleaning ; partial rewrite of use
From: |
Dany De Bontridder |
Subject: |
[Noalyss-commit] [noalyss] 07/13: Code cleaning ; partial rewrite of user management |
Date: |
Mon, 30 Aug 2021 10:11:59 -0400 (EDT) |
sparkyx pushed a commit to branch master
in repository noalyss.
commit 90f8169f53307871181bc66cdca1b5e5d7c0d782
Author: sparkyx <danydb@noalyss.eu>
AuthorDate: Thu Aug 26 00:07:46 2021 +0200
Code cleaning ; partial rewrite of user management
---
include/class/user.class.php | 2 +-
include/lib/ac_common.php | 2 +-
include/user.inc.php | 83 ++++++++++++++++++++++++++++++++++++++++++--
include/user_detail.inc.php | 72 --------------------------------------
4 files changed, 83 insertions(+), 76 deletions(-)
diff --git a/include/class/user.class.php b/include/class/user.class.php
index 130501a..45faa80 100644
--- a/include/class/user.class.php
+++ b/include/class/user.class.php
@@ -384,7 +384,7 @@ class User
$cn=new Database();
$this->id=$cn->get_value($Sql,
- array($this->first_name, $this->last_name, $this->login, 1, 0,
$this->pass, $this->email));
+ array($this->first_name, $this->last_name, $this->login, 1,
$this->admin, $this->pass, $this->email));
}
/**
diff --git a/include/lib/ac_common.php b/include/lib/ac_common.php
index 64cbb55..f706bda 100644
--- a/include/lib/ac_common.php
+++ b/include/lib/ac_common.php
@@ -1468,7 +1468,7 @@ function remove_divide_zero($p_formula)
function generate_random_string($car)
{
$string="";
-
$chaine="abcdefghijklmnpqrstuvwxyABCDEFGHIJKLMNPQRSTUVWXY0123456789*/+-=<>";
+ $chaine="abcdefghijklmnpqrstuvwxyABCDEFGHIJKLMNPQRSTUVWXY0123456789*/+-=";
srand((double) microtime()*1020030);
for ($i=0; $i<$car; $i++)
{
diff --git a/include/user.inc.php b/include/user.inc.php
index df3152f..2ab4094 100644
--- a/include/user.inc.php
+++ b/include/user.inc.php
@@ -62,9 +62,88 @@ if ( isset ($_POST["ADD"]) )
}
} //SET login
+/******************************************************/
+// Update user
+/******************************************************/
+$sbaction=$http->post('sbaction',"string", "");
+if ($sbaction == "save")
+{
+ $uid = $http->post("UID");
+
+ // Update User
+ $cn = new Database();
+ $UserChange = new User($cn, $uid);
+
+ if ($UserChange->load() == -1)
+ {
+ alert(_("Cet utilisateur n'existe pas"));
+ }
+ else
+ {
+ $UserChange->first_name =$http->post('fname');
+ $UserChange->last_name = $http->post('lname');
+ $UserChange->active = $http->post('Actif');
+ $UserChange->admin = $http->post('Admin');
+ $UserChange->email = $http->post('email');
+ if ($UserChange->active ==-1 || $UserChange->admin ==-1)
+ {
+ die ('Missing data');
+ }
+ else if ( trim($_POST['password'])<>'')
+ {
+ $UserChange->pass = md5($_POST['password']);
+ $UserChange->save();
+ }
+ else
+ {
+ $UserChange->pass=$UserChange->password;
+ $UserChange->save();
+ }
+ }
+}
+else if ($sbaction == "delete")
+{
+/******************************************************/
+// Delete the user
+/******************************************************/
+ // check that the control is correct
+ try {
+ $code=$http->post("userdel");
+ $ctl_code=$http->post('ctlcode');
+ $uid = $http->request('use_id');
+ } catch (Exception $ex) {
+ echo_error($ex->getMessage());
+ throw $ex;
+ }
+ if ( DEBUGNOALYSS > 1) {
+ echo "code [$code] code control [$ctl_code]";
+ }
+ if ( $code != $ctl_code) {
+ echo _("Code invalide, effacement refusé");
+ return;
+ }
+ $cn = new Database();
+ $auser=$cn->get_row('select use_login from ac_users where use_id =
$1',[$uid]);
+ if ( $auser == null) return;
+ $Res = $cn->exec_sql("delete from jnt_use_dos where use_id=$1",
array($uid));
+ $Res = $cn->exec_sql("delete from ac_users where use_id=$1", array($uid));
+ //------------------------------------
+ // Remove user from all the dossiers
+ //------------------------------------
+ $a_dossier=$cn->get_array('select dos_id from ac_dossier');
+ if ( is_array($a_dossier) ) {
+ $nb=count($a_dossier);
+ for ( $i=0;$i<$nb;$i++)
+ User::remove_inexistant_user($a_dossier[$i]['dos_id']);
+ }
+ User::audit_admin(sprintf('DELETE USER %s %s',$uid,$auser['use_login']));
+ echo "<H2 class=\"notice\">";
+ printf (_("Utilisateur %s %s est
effacé"),$http->post('fname'),$http->post('lname')) ;
+ echo " </H2>";
+}
// View user detail
-if ( isset($_REQUEST['det']))
+if ( isset($_REQUEST['det']) && $sbaction=="")
{
require_once NOALYSS_INCLUDE.'/user_detail.inc.php';
@@ -84,7 +163,7 @@ if ( isset($_REQUEST['det']))
<TR><TD style="text-align: right"> <?php echo _('Email')?></TD><TD>
<INPUT class="input_text" TYPE="TEXT" NAME="EMAIL"></TD></TR>
</TABLE>
<?php
-echo HtmlInput::submit("ADD",_('Créer Utilisateur'));
+echo HtmlInput::submit("ADD",_('Créer Utilisateur'),"",'button');
echo HtmlInput::button_action(_("Fermer"),
"$('create_user').style.display='none';");
?>
diff --git a/include/user_detail.inc.php b/include/user_detail.inc.php
index a872b69..8ae553f 100644
--- a/include/user_detail.inc.php
+++ b/include/user_detail.inc.php
@@ -39,79 +39,7 @@ if ($UserChange->id == false)
html_page_stop();
}
-/*
- * Update user changes
- */
-$sbaction=$http->post('sbaction',"string", "");
-if ($sbaction == "save")
-{
- $uid = $_POST['UID'];
-
- // Update User
- $cn = new Database();
- $UserChange = new User($cn, $uid);
-
- if ($UserChange->load() == -1)
- {
- alert(_("Cet utilisateur n'existe pas"));
- }
- else
- {
- $UserChange->first_name =$http->post('fname');
- $UserChange->last_name = $http->post('lname');
- $UserChange->active = $http->post('Actif');
- $UserChange->admin = $http->post('Admin');
- $UserChange->email = $http->post('email');
- if ($UserChange->active ==-1 || $UserChange->admin ==-1)
- {
- die ('Missing data');
- }
- else if ( trim($_POST['password'])<>'')
- {
- $UserChange->pass = md5($_POST['password']);
- $UserChange->save();
- }
- else
- {
- $UserChange->pass=$UserChange->password;
- $UserChange->save();
- }
- }
-}
-else if ($sbaction == "delete")
-{
-//
-// Delete the user
-//
- // check that the control is correct
- $code=$http->post("userdel");
- $ctl_code=$http->post('ctlcode');
- if ( $code != $ctl_code) {
- echo _("Code invalide, effacement refusé");
- return;
- }
- $cn = new Database();
- $auser=$cn->get_row('select use_login from ac_users where use_id =
$1',[$uid]);
- if ( $auser == null) return;
- $Res = $cn->exec_sql("delete from jnt_use_dos where use_id=$1",
array($uid));
- $Res = $cn->exec_sql("delete from ac_users where use_id=$1", array($uid));
- //------------------------------------
- // Remove user from all the dossiers
- //------------------------------------
- $a_dossier=$cn->get_array('select dos_id from ac_dossier');
- if ( is_array($a_dossier) ) {
- $nb=count($a_dossier);
- for ( $i=0;$i<$nb;$i++)
- User::remove_inexistant_user($a_dossier[$i]['dos_id']);
- }
- User::audit_admin(sprintf('DELETE USER %s %s',$uid,$auser['use_login']));
- echo "<H2 class=\"info\">";
- printf (_("Utilisateur %s %s est
effacé"),$http->post('fname'),$http->post('lname')) ;
- echo " </H2>";
- require_once NOALYSS_INCLUDE.'/user.inc.php';
- return;
-}
$UserChange->load();
$it_pass=new IText('password');
$it_pass->value="";
- [Noalyss-commit] [noalyss] branch master updated (07f215d -> 0fbb377), Dany De Bontridder, 2021/08/30
- [Noalyss-commit] [noalyss] 01/13: Bug : export currency in CSV bad column name, Dany De Bontridder, 2021/08/30
- [Noalyss-commit] [noalyss] 06/13: Bug : fix security , clean completely the session and prevent to set the menu public to an user, Dany De Bontridder, 2021/08/30
- [Noalyss-commit] [noalyss] 09/13: security, Dany De Bontridder, 2021/08/30
- [Noalyss-commit] [noalyss] 02/13: Fix code + add phpunit, Dany De Bontridder, 2021/08/30
- [Noalyss-commit] [noalyss] 03/13: Bug : fiche account not created automatically when empty , improve test, Dany De Bontridder, 2021/08/30
- [Noalyss-commit] [noalyss] 05/13: Add a button search_card, Dany De Bontridder, 2021/08/30
- [Noalyss-commit] [noalyss] 08/13: Bug fix : duplicate operation last date was not proposed, Dany De Bontridder, 2021/08/30
- [Noalyss-commit] [noalyss] 07/13: Code cleaning ; partial rewrite of user management,
Dany De Bontridder <=
- [Noalyss-commit] [noalyss] 10/13: Cosmetic : export PDF of an operation, set decimal to 2 and add info, Dany De Bontridder, 2021/08/30
- [Noalyss-commit] [noalyss] 12/13: Apply patch when creating a DB, Dany De Bontridder, 2021/08/30
- [Noalyss-commit] [noalyss] 04/13: Cosmetic, Dany De Bontridder, 2021/08/30
- [Noalyss-commit] [noalyss] 13/13: cosmetic, Dany De Bontridder, 2021/08/30
- [Noalyss-commit] [noalyss] 11/13: Typo correct profile, Dany De Bontridder, 2021/08/30