2015-02-12 18:58:03 +01:00
|
|
|
<?php namespace App\Http\Controllers;
|
2015-02-15 07:12:44 +01:00
|
|
|
use Auth;
|
|
|
|
use Input;
|
|
|
|
use Validator;
|
|
|
|
use Password;
|
|
|
|
use DB;
|
2015-02-12 18:58:03 +01:00
|
|
|
|
|
|
|
class LoginController extends Controller {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a new controller instance.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function __construct()
|
|
|
|
{
|
2015-02-15 07:12:44 +01:00
|
|
|
//
|
2015-02-12 18:58:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Show the application dashboard to the user.
|
|
|
|
*
|
|
|
|
* @return Response
|
|
|
|
*/
|
|
|
|
public function index()
|
|
|
|
{
|
|
|
|
return view('auth.login');
|
|
|
|
}
|
|
|
|
|
2015-02-15 07:12:44 +01:00
|
|
|
public function authenticate()
|
|
|
|
{
|
|
|
|
$credentials = [
|
|
|
|
'email'=>Input::get('email'),
|
|
|
|
'password'=>Input::get('password')
|
|
|
|
];
|
|
|
|
$rules = [
|
|
|
|
'email' => 'required',
|
|
|
|
'password'=>'required'
|
|
|
|
];
|
|
|
|
$validator = Validator::make($credentials,$rules);
|
|
|
|
if($validator->passes())
|
|
|
|
{
|
|
|
|
if(Auth::attempt($credentials))
|
|
|
|
{
|
|
|
|
if (Auth::user()->admin == 1)
|
|
|
|
return redirect()->intended('admin');
|
|
|
|
else
|
|
|
|
return redirect()->intended('referent');
|
|
|
|
}
|
|
|
|
return redirect('login')->withErrors(['erreur' => 'Mail ou mot de passe incorrect!',]);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return redirect('login')->withErrors($validator)->withInput();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function logout()
|
|
|
|
{
|
|
|
|
Auth::logout();
|
|
|
|
return redirect('login');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function forgottenPassword()
|
|
|
|
{
|
|
|
|
return view('auth.password');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function initPassword()
|
|
|
|
{
|
|
|
|
switch ($response = Password::remind(Input::only('email')))
|
|
|
|
{
|
|
|
|
case Password::INVALID_USER:
|
2015-02-15 17:10:23 +01:00
|
|
|
return redirect('forgotten')->withErrors($response)->withInput();
|
2015-02-15 07:12:44 +01:00
|
|
|
case Password::REMINDER_SENT:
|
2015-02-15 17:10:23 +01:00
|
|
|
return redirect('forgotten')->withStatus($response)->withInput();
|
2015-02-15 07:12:44 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-02-12 18:58:03 +01:00
|
|
|
}
|