noalyss-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Noalyss-commit] [noalyss] 04/39: Fix bug in recover password Include se


From: Dany De Bontridder
Subject: [Noalyss-commit] [noalyss] 04/39: Fix bug in recover password Include sendmail.class.php fix bug sending email with file (compatibility PHP7)
Date: Sat, 11 Jul 2020 13:20:35 -0400 (EDT)

sparkyx pushed a commit to branch master
in repository noalyss.

commit 92bd3eb5063805e97d236f61f58208a82bac26a5
Author: Dany De Bontridder <danydb@noalyss.eu>
AuthorDate: Mon May 11 00:03:41 2020 +0200

    Fix bug in recover password
        Include sendmail.class.php
        fix bug sending email with file (compatibility PHP7)
---
 include/lib/sendmail_core.class.php | 37 ++++++++++++++++++++-----------------
 include/recover.php                 | 23 +++++++++++++++++------
 2 files changed, 37 insertions(+), 23 deletions(-)

diff --git a/include/lib/sendmail_core.class.php 
b/include/lib/sendmail_core.class.php
index 11a5180..b62061d 100644
--- a/include/lib/sendmail_core.class.php
+++ b/include/lib/sendmail_core.class.php
@@ -78,7 +78,8 @@ class Sendmail_Core
      */
     function set_message($p_message)
     {
-        $this->message = $p_message;
+        // $this->message =wordwrap($p_message,70,"\r\n");
+        $this->message =$p_message;
     }
 
     /**
@@ -134,24 +135,26 @@ class Sendmail_Core
         $this->content .= "Content-Type: text/plain; charset=\"utf-8\"" . $eol;
         $this->content .= "Content-Transfer-Encoding: 7bit" . $eol.$eol ;
         $this->content .= $this->message . $eol ;
-
-        // attachment
-        for ($i = 0; $i < count($this->afile); $i++)
+        if ( ! empty($this->afile ) )
         {
-            $file = $this->afile[$i];
-            $file_size = filesize($file->full_name);
-            $handle = fopen($file->full_name, "r");
-            $content = fread($handle, $file_size);
-            fclose($handle);
-            $content = chunk_split(base64_encode($content));
-            $this->content .= "--" . $separator . $eol;
-            $this->content .= "Content-Type: " . $file->type . "; name=\"" . 
$file->filename . "\"" . $eol;
-            $this->content .= "Content-Disposition: attachment; filename=\"" . 
$file->filename . "\"" . $eol;
-            $this->content .= "Content-Transfer-Encoding: base64" . $eol;
-            $this->content.=$eol;
-            $this->content .= $content . $eol ;
+            // attachment
+            for ($i = 0; $i < count($this->afile); $i++)
+            {
+                $file = $this->afile[$i];
+                $file_size = filesize($file->full_name);
+                $handle = fopen($file->full_name, "r");
+                $content = fread($handle, $file_size);
+                fclose($handle);
+                $content = chunk_split(base64_encode($content));
+                $this->content .= "--" . $separator . $eol;
+                $this->content .= "Content-Type: " . $file->type . "; name=\"" 
. $file->filename . "\"" . $eol;
+                $this->content .= "Content-Disposition: attachment; 
filename=\"" . $file->filename . "\"" . $eol;
+                $this->content .= "Content-Transfer-Encoding: base64" . $eol;
+                $this->content.=$eol;
+                $this->content .= $content . $eol ;
+            }
         }
-        if ( count ($this->afile) == 0 ) $this->content.=$eol;
+        if ( empty ($this->afile) ) $this->content.=$eol;
 
         $this->content .= "--" . $separator . "--";
     }
diff --git a/include/recover.php b/include/recover.php
index ec082d1..cf9dac8 100644
--- a/include/recover.php
+++ b/include/recover.php
@@ -25,6 +25,7 @@ define('SIZE_REQUEST', 70);
 
 require_once NOALYSS_INCLUDE.'/lib/html_input.class.php';
 require_once NOALYSS_INCLUDE.'/lib/http_input.class.php';
+require_once NOALYSS_INCLUDE.'/class/sendmail.class.php';
 /**
  * @brief generate a random string of char
  * @param $car int length of the string
@@ -95,12 +96,22 @@ elseif ($action=="send_email") :
     if ($valid==true):
         $request_id=generate_random(SIZE_REQUEST);
         $user_password=generate_random(10);
-        /*
-         * save the request into 
-         */
-        $cn->exec_sql("insert into 
recover_pass(use_id,request,password,created_on,created_host) "
-                ." values ($1,$2,$3,now(),$4)", array($user_id, $request_id, 
$user_password, $_SERVER['REMOTE_ADDR']));
-
+        // exist a valid request for this user ?
+        $exist_request= $cn->get_array("select request , password from 
recover_pass 
+                        where use_id=$1 and created_on > now() - interval '12 
hours'",[$user_id]);
+        if ( empty($exist_request ) ) {
+             /* save the request into  */
+            $cn->exec_sql("insert into 
recover_pass(use_id,request,password,created_on,created_host) "
+                    ." values ($1,$2,$3,now(),$4)", array($user_id, 
$request_id, $user_password, $_SERVER['REMOTE_ADDR']));
+        } else {
+            $request_id=$exist_request[0]["request"];
+            $user_password=$exist_request[0]['password'];
+            /* if too many request , there is a bug somewhere , so record an 
warning */
+            if ( count($exist_request)> 1 ){
+                error_log("WRE109 Trop de request pour 
".var_export($exist_request,true));
+            }
+            
+        }
         /*
          * send an email
          */



reply via email to

[Prev in Thread] Current Thread [Next in Thread]