Commit 4dd60ce1 authored by Kylian ou Nathan's avatar Kylian ou Nathan
Browse files

Up

parent eb2154f1
......@@ -56,12 +56,13 @@ defined('BASEPATH') OR exit('No direct script access allowed');
$route['default_controller'] = 'Accueil/home';
$route['accueil'] = 'Accueil/home';
$route['edit'] = 'Accueil/edit';
$route['edit_profil'] = 'Accueil/edit_profil';
$route['deconnexion'] = 'Authentification/deconnexion';
$route['connexion'] = 'Authentification/connexion';
$route['inscription'] = 'Authentification/inscription';
$route['mot_de_passe_oublie'] = 'Authentification/mot_de_passe_oublie';
$route['nouveau_mot_de_passe'] = 'Authentification/nouveau_mot_de_passe';
$route['nouveau_mot_de_passe/(:any)'] = 'Authentification/nouveau_mot_de_passe/$1';
$route['camera/edit/(:any)'] = 'Camera/edit/$1';
$route['camera/view/(:any)'] = 'Camera/view/$1';
......
......@@ -7,6 +7,7 @@ class Accueil extends CI_Controller
parent::__construct();
$this->load->model("AccueilModele");
$this->load->model("ProfilModele");
$this->load->model("LogCapteurModele");
$this->load->model("LogEmailModele");
......@@ -36,8 +37,11 @@ class Accueil extends CI_Controller
}
// LISTER LES PROFILS EXISTANT
$data->listes_profils = $this->ProfilModele->getAll();
// CONNAITRE LE PROFIL ACTUEL
// ETAT DES CAPTEURS
$data->profil_actif = $this->ProfilModele->getActive();
$this->load->view('accueil/accueil', $data);
......@@ -91,4 +95,18 @@ class Accueil extends CI_Controller
}
// Permet de mettre a jour le profil depuis la page d'accueil
//
public function edit_profil(){
if ($this->input->server('REQUEST_METHOD') == 'POST' && $this->input->post('profilActif') != null) {
$this->ProfilModele->setActive($this->input->post('profilActif'));
}
redirect("/", "refresh");
}
}
......@@ -4,6 +4,7 @@ class Authentification extends CI_Controller {
public function __construct(){
parent::__construct();
$this->load->model("AuthentificationModele");
$this->load->model("MotDePasseOublieModele");
$this->load->helper("url_helper");
}
......@@ -113,8 +114,17 @@ class Authentification extends CI_Controller {
$mdpoublie = $this->AuthentificationModele->mot_de_passe_oublie($email);
if($mdpoublie == true){
$token = uniqid();
//If there is a token, we delete it
if($this->MotDePasseOublieModele->verify($email, $token))
{
$this->MotDePasseOublieModele->delete($email, $token);
}
$this->MotDePasseOublieModele->add($email, $token);
$this->send_email($email, $token);
$this->send_email(uniqid());
$msg = array("envoye" => true);
$this->load->view('auth/mot_de_passe_oublie', $msg);
......@@ -134,14 +144,8 @@ class Authentification extends CI_Controller {
}
}
private function send_email($token){
$users = $this->AuthentificationModele->users_accepting_notification();
private function send_email($email, $token){
$users_id = array_column($users, "id");
$users_email = array_column($users, "email");
$to = implode(",", $users_email);
$subject = "[LOCKHOME] Demande de changement de mot de passe.";
$message = file_get_contents("./application/email/mot_passe_oublie.html");
$message = str_replace('$$_TOKEN_$$', $token, $message);
......@@ -152,18 +156,27 @@ class Authentification extends CI_Controller {
$headers .= 'Reply-To: lockhome@lockhome.nrocher.fr' . "\r\n";
$headers .= 'X-Mailer: PHP/' . phpversion();
if(mail($to, $subject, $message, $headers)) {
if(mail($email, $subject, $message, $headers)) {
echo "<br>Email accepted by server";
} else {
echo "<br>Error: Email not accepted by server";
}
}
public function nouveau_mot_de_passe()
public function nouveau_mot_de_passe($token)
{
if(isset($_POST["email"]) && isset($_POST["password"]))
if(isset($_POST["email"]) && isset($_POST["mot_de_passe"]) && $token != '')
{
$this->AuthentificationModele->nouveau_mot_de_passe($_POST["password"], $_POST["email"]);
if($this->MotDePasseOublieModele->verify(isset($_POST["email"]), $token))
{
$this->MotDePasseOublieModele->resetPassword(isset($_POST["mot_de_passe"]), isset($_POST["email"]));
$this->MotDePasseOublieModele->delete(isset($_POST["email"]), $token);
}
}
else
{
echo "<br>email, password or token not set !";
}
}
}
\ No newline at end of file
......@@ -362,7 +362,7 @@
<p>Vous avez demander une réinitialisation de mot de passe.</p>
<p>Veuillez cliquer sur le lien suivant pour réinitialiser votre mot de passe.</p>
<p>
<a href="https://lockhome.nrocher.fr/nouveau_mot_de_passe/$$_TOKEN_$$"></a>
https://lockhome.nrocher.fr/nouveau_mot_de_passe/$$_TOKEN_$$
</p>
</td>
</tr>
......
......@@ -72,16 +72,4 @@ class AuthentificationModele extends CI_Model
return $query->result();
}
//METHODE PERMETTANT LE CHANGEMENT DE MOT DE PASSE
public function nouveau_mot_de_passe($password, $email)
{
$password = password_hash($password, PASSWORD_DEFAULT);
$sql = "UPDATE Authentification SET password = ? WHERE email = ?";
$query = $this->db->query($sql, array($password, $email));
return $query->num_rows();
}
}
......@@ -8,54 +8,77 @@ class MotDePasseOublieModele extends CI_Model
$this->load->database();
}
private function getIdUser()
private function getIdUser($email)
{
if($this->session->hes_userdata("email"))
{
$email = $this->session->hes_userdata("email");
$sqlUser = "SELECT id FROM Authentification WHERE email = ?";
return $this->db->query($sql, array($email));
$sql = "SELECT id FROM Authentification WHERE email = ? LIMIT 1";
$query = $this->db->query($sql, array($email));
if ($query->num_rows() > 0)
{
return $query->result()[0]->id;
}
else
{
return false; //Aucun id trouvé.
}
}
public function update($token)
public function verify($email, $token)
{
if($this->getIdUser())
$user = $this->getIdUser($email);
var_dump($user);
if($user)
{
$id = $this->getIdUser();
$sql = "SELECT * FROM MotDePasseOublie WHERE user = ? AND token = ? LIMIT 1";
$sql = "UPDATE MotDePasseOublie SET token = ? WHERE id = ?";
$query = $this->db->query($sql, array($token, $id));
return $this->db->affected_rows();
}
$query = $this->db->query($sql, array($user, $token));
return $this->db->affected_rows() > 0;
}
}
public function delete($token)
public function delete($email, $token)//Un fois le changement fait
{
if($this->getIdUser())
{
$id = $this->getIdUser();
$id = $this->getIdUser($email);
$sql = "DELETE FROM MotDePasseOublie WHERE id = ?";
$query = $this->db->query($sql, array($id));
if($id)
{
$this->db->delete('MotDePasseOublie', array("user" => $id));
return $this->db->affected_rows();
}
}
public function add($token)
public function add($email, $token) //mdp oublié premier form
{
if($this->getIdUser())
$id = $this->getIdUser($email);
if($id)
{
$id = $this->getIdUser();
$data = array();
$data["user"] = $id;
$data["token"] = $token;
$sql = "INSERT INTO MotDePasseOublie VALUES (?, ?)";
$query = $this->db->query($sql, array($id, $token));
$this->db->insert('MotDePasseOublie', $data);
return $this->db->affected_rows();
}
}
//METHODE PERMETTANT LE CHANGEMENT DE MOT DE PASSE
public function resetPassword($password, $email)
{
$password = password_hash($password, PASSWORD_DEFAULT);
$data = array();
$data["password"] = $password;
$this->db->update('Authentification', $date, array("email" => $email));
return $this->db->affected_rows();
}
}
?>
\ No newline at end of file
......@@ -23,7 +23,25 @@ class ProfilModele extends CI_Model
}
// METHODE PERMETTANT DE RECUPERER TOUT LES PROFILS
// METHODE PERMETTANT DE DENIFIR LE PROFIL ACTIF
public function setActive($idActif)
{
$data = array();
$data["profilactif"] = $idActif;
$this->db->update('Maison', $data, array());
if ($this->db->affected_rows() > 0) {
return true;
} else {
return false;
}
}
// METHODE PERMETTANT DE RECUPERER LE PROFIL ACTIF
public function getActive()
{
$sql = "SELECT Profil.* from Profil,Maison WHERE Maison.profilactif = Profil.id";
......
......@@ -21,6 +21,9 @@
<a href="<?= base_url("/edit") ?>">
<i class='uil uil-cog'></i>
</a>
<a href="<?= base_url("/deconnexion") ?>">
<i class='uil uil-sign-out-alt'></i>
</a>
</div>
</header>
<main>
......@@ -80,15 +83,36 @@
</div>
<div class="maison_profil">
<p class="title">Profil actif :</p>
<select class="profilActif" name="profilActif">
<option value="Vacance">Vacance</option>
<option value="Jour">Jour</option>
<option value="Nuit">Nuit</option>
</select>
<form action="<?= base_url("/edit_profil")?>" method="post">
<select class="profilActif" name="profilActif" onchange="this.parentElement.submit()">
<?php
foreach($listes_profils as $profil){
$selected = "";
if($profil_actif->id == $profil->id) {
$selected = "selected";
}
echo '<option '.$selected.' value="'.$profil->id.'">'.$profil->nom.'</option>';
}
?>
</select>
</form>
</div>
<div class="maison_horaire">
<p class="title">Plage horaire :</p>
<p>8h - 18h</p>
<p><?=$profil_actif->debut ?> - <?=$profil_actif->fin ?></p>
</div>
<div class="maison_capteur">
<p class="title">Etat des capteurs :</p>
......
......@@ -18,6 +18,7 @@
<h2>Changement de mot de passe</h2>
<form action="./nouveau_mot_de_passe" method="post">
<input type="email" name="email" placeholder="Email" required="required">
<input type="password" name="mot_de_passe" placeholder="Mot de passe" required="required">
<button type="submit">Mettre à jour</button>
</form>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment