67 lines
2.3 KiB
PHP
67 lines
2.3 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
namespace App\Http\Controllers;
|
||
|
|
|
||
|
|
use Illuminate\Http\Request;
|
||
|
|
use Illuminate\Support\Facades\Auth;
|
||
|
|
use App\Providers\RouteServiceProvider;
|
||
|
|
use App\User;
|
||
|
|
use CPCConnection;
|
||
|
|
use Exception;
|
||
|
|
|
||
|
|
class LoginController extends Controller
|
||
|
|
{
|
||
|
|
|
||
|
|
public function __construct() {
|
||
|
|
$this->middleware('guest')->except('logout');
|
||
|
|
}
|
||
|
|
|
||
|
|
public function index() {
|
||
|
|
return view('front.basic.login');
|
||
|
|
}
|
||
|
|
|
||
|
|
public function authenticate(Request $request)
|
||
|
|
{
|
||
|
|
$email = $request->email;
|
||
|
|
$password = $request->password;
|
||
|
|
$remember = $request->remember !== null ? true : false;
|
||
|
|
|
||
|
|
$userLocal = User::where('email', $email)->first();
|
||
|
|
|
||
|
|
if ($userLocal) {
|
||
|
|
if ($userLocal->role !== 1) {
|
||
|
|
try {
|
||
|
|
$cpcConnect = new CPCConnection(config('crm.CRM_PLATOS_WSDL'), config('crm.WS_SERVCE_LOGIN'), config('crm.WS_SERVCE_PASSWORD'));
|
||
|
|
$cpcConnect->connect();
|
||
|
|
try {
|
||
|
|
// ---- Authentification du user
|
||
|
|
$cpcConnect->authenticateUser ($email, $password);
|
||
|
|
} catch (Exception $e) {
|
||
|
|
return redirect()->back()->withInput($request->only("email", "password"))->withErrors("Email ou mot de passe incorrect.");
|
||
|
|
}
|
||
|
|
} catch (Exception $e) {
|
||
|
|
return redirect()->back()->withInput($request->only("email", "password"))->withErrors("La connexion est impossible pour le moment, veuillez réessayer plus tard.");
|
||
|
|
die();
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
if (Auth::attempt(["email" => $email, "password" => $password], $remember)) {
|
||
|
|
if ($userLocal->role === 1)
|
||
|
|
return redirect()->route('bo.dashboard');
|
||
|
|
return redirect()->route('home');
|
||
|
|
} else {
|
||
|
|
return redirect()->back()->withInput($request->only('email', 'remember'))->withErrors('Les identifiants entrés sont incorrects.');
|
||
|
|
}
|
||
|
|
} else {
|
||
|
|
return redirect()->back()->withInput($request->only('email', 'remember'))->withErrors('Les identifiants entrés sont incorrects.');
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
public function logout() {
|
||
|
|
Auth::logout();
|
||
|
|
return redirect()->route('home');
|
||
|
|
}
|
||
|
|
}
|