2021-10-14 14:33:02 +00:00
|
|
|
<?php
|
|
|
|
defined('BASEPATH') OR exit('No direct script access allowed');
|
|
|
|
|
2021-11-04 17:01:59 +00:00
|
|
|
class Agent_password extends CI_Controller
|
2021-10-14 14:33:02 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
public function __construct()
|
|
|
|
{
|
|
|
|
parent::__construct();
|
|
|
|
$this->load->model('nano_health_model');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function index()
|
|
|
|
{
|
|
|
|
if (!$this->input->get('token')) {
|
|
|
|
echo "Lien incorrect";
|
|
|
|
}
|
|
|
|
else {
|
2021-11-04 17:01:59 +00:00
|
|
|
$db_token = $this->db->get_where('nh_validating_agents',['token' => $this->input->get('token')]);
|
2021-10-14 14:33:02 +00:00
|
|
|
if($db_token->num_rows() > 0 ){
|
|
|
|
$this->session->set_userdata('token', $this->input->get('token'));
|
2021-11-04 17:01:59 +00:00
|
|
|
$this->load->view('admin_update_password',['isValidatingAgent' => true]);
|
2021-10-14 14:33:02 +00:00
|
|
|
}else{
|
|
|
|
echo "Ce lien a déjà expiré";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public function create_password()
|
|
|
|
{
|
|
|
|
if (!$this->session->userdata('token')) {
|
|
|
|
echo "Ce lien a déjà expiré";
|
|
|
|
} else {
|
|
|
|
if(isset($_POST))
|
|
|
|
{
|
|
|
|
$password = $this->input->post('password');
|
|
|
|
$hash = hashSSHA($password);
|
|
|
|
$encrypted_password = $hash["encrypted"]; // encrypted password
|
|
|
|
$salt = $hash["salt"]; // salt
|
|
|
|
|
|
|
|
$this->db->where('token' , $this->session->userdata('token'));
|
2021-11-04 17:01:59 +00:00
|
|
|
$res = $this->db->update('nh_validating_agents',['password' => $encrypted_password, 'salt' => $salt]);
|
2021-10-14 14:33:02 +00:00
|
|
|
|
|
|
|
if($res==true){
|
|
|
|
$new_token = null;
|
|
|
|
do {
|
|
|
|
$new_token = bin2hex(openssl_random_pseudo_bytes(16));
|
2021-11-04 17:01:59 +00:00
|
|
|
$tokenExist = $this->db->get_where('nh_validating_agents',['token' => $new_token]);
|
2021-10-14 14:33:02 +00:00
|
|
|
} while ($tokenExist->num_rows() > 0);
|
|
|
|
|
|
|
|
|
|
|
|
$this->db->where('token' , $this->session->userdata('token'));
|
2021-11-04 17:01:59 +00:00
|
|
|
$res_token = $this->db->update('nh_validating_agents',['token'=>$new_token]);
|
2021-10-14 14:33:02 +00:00
|
|
|
|
|
|
|
if($res_token==true){
|
|
|
|
$data['alert'] = 'password';
|
|
|
|
$data['message'] = 'Votre mot de passe a été configuré avec succès';
|
|
|
|
$this->load->view('login', $data);
|
|
|
|
}else{
|
|
|
|
echo "Une erreur s'est produite";
|
|
|
|
}
|
|
|
|
}else{
|
|
|
|
echo "Une erreur s'est produite";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|