/** * Reset son propre mot de passe et l'envoi par mail * 0:Ok sa marche * 1:Pas d'email * 2:pas d'user * 3:Modif du pass impossible * 4:mail pas partie * @return int $state * @param String $usr_id * @param String $email */ public function resetKey($usr_id, $email) { $rand = rand(0, 9999); if ($rand < 100) { $rand = "00" . $rand; } else { if ($rand < 1000) { $rand = "0" . $rand; } } if (empty($email)) { return 1; } elseif (empty($usr_id)) { return 2; } $Buyer = new Buyer($usr_id, 1, '', '', 1); $this->db->query("UPDATE ts_user_usr SET usr_pwd='%s' WHERE usr_id='%u'", array(md5($rand), $Buyer->getId())); $nb = $this->db->affectedRows(); if ($nb != 1) { return 3; } $subject = 'Changement code PIN BuckUTT'; $message = "<p>Bonjour,</p>\n <p>Tu as demandé un nouveau code PIN et bah le voila</p>\n\t\t<p>CODE PIN = {$rand}</p>"; $headers = 'From: buckutt@utt.fr' . "\r\n" . 'Content-Type: text/html; charset="UTF-8"' . "\r\n" . 'Reply-To: buckutt@utt.fr' . "\r\n" . 'X-Mailer: PHP/' . phpversion(); $err = mail($email, $subject, $message, $headers); if (!$err) { return 4; } else { $this->db->query("UPDATE ts_user_usr SET usr_blocked=0 WHERE usr_id='" . $Buyer->getId() . "'"); $nb = $this->db->affectedRows(); // if($nb != 1){ // return 5; // } return 0; } }