1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
| namespace App\Http\Controllers\Commun;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\App;
use Illuminate\Support\Str;
use Illuminate\Support\Facades\Auth;
use App\Http\Controllers\Commun\FunctionController;
use App\Models\User;
class ConnexionController extends Controller
{
/**
* Tente une connexion SSO et renvoie des données si OK
* @return array
*/
public static function ConnexionSSO()
{
$authentifie = array(
'etat' => false,
'message' => "Vous n'avez pas pu être authentifié-e."
);
$non_autorise = "";
$identifiant = "";
$agident = 0;
$nom = "";
$prenom = "";
$courriel = "";
if (App::environment() == 'local') {
////////////////////
///
/// Pour le développement en local, on ne passe pas par l'authentification SSO, on teste juste l'environnement
///
////////////////////
$identifiant = 'IDENT_LOCAL';
$nom = 'IDENTIFIANT';
$prenom = 'POUR_LOCAL';
$authentifie = [
'etat' => true,
'message' => "Vous avez pu être authentifié-e."
];
$agident = 1;
} else if (isset($_SERVER['AUTH_USER']) && $_SERVER['AUTH_USER'] != '') {
$identifiant = $_SERVER['AUTH_USER'];
if (Str::contains($identifiant, '\\')) {
$identifiant = explode('\\', $identifiant);
$identifiant = $identifiant[1];
}
//////////////
///
/// Récupération des données de l'agent dans l'AD
///
//////////////
$agent = FunctionController::DataAgentIdentifiant($identifiant);
$nom = $agent['nom'];
$prenom = $agent['prenom'];
$courriel = $agent['mail'];
//////////////
///
/// Récupération de l'agident
///
//////////////
$select = "PS @nom='".$nom." ".$prenom."'";
$dataAgent = collect(DB::connection('sqlsrv')
->select($select))
->first();
$agident = $dataAgent->AgIdent;
$authentifie = [
'etat' => true,
'message' => "Vous avez pu être authentifié-e."
];
}
return array(
'authentifie' => $authentifie,
'non_autorise' => $non_autorise,
'identifiant' => $identifiant,
'agident' => $agident,
'nom' => $nom,
'prenom' => $prenom,
'courriel' => $courriel
);
}
} |
Partager