2015-02-12 17:58:03 +00:00
|
|
|
<?php namespace App\Http\Controllers;
|
2015-02-15 06:12:44 +00:00
|
|
|
use Auth;
|
|
|
|
use Input;
|
|
|
|
use Validator;
|
|
|
|
use Password;
|
2015-02-18 22:23:12 +00:00
|
|
|
use View;
|
|
|
|
use Redirect;
|
|
|
|
use Hash;
|
2015-03-14 13:36:03 +00:00
|
|
|
use Session;
|
2015-02-12 17:58:03 +00:00
|
|
|
class LoginController extends Controller {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a new controller instance.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function __construct()
|
|
|
|
{
|
2015-02-15 06:12:44 +00:00
|
|
|
//
|
2015-02-12 17:58:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Show the application dashboard to the user.
|
|
|
|
*
|
|
|
|
* @return Response
|
|
|
|
*/
|
|
|
|
public function index()
|
|
|
|
{
|
|
|
|
return view('auth.login');
|
|
|
|
}
|
|
|
|
|
2015-02-15 06:12:44 +00:00
|
|
|
public function authenticate()
|
|
|
|
{
|
|
|
|
$credentials = [
|
|
|
|
'email'=>Input::get('email'),
|
|
|
|
'password'=>Input::get('password')
|
|
|
|
];
|
|
|
|
$rules = [
|
|
|
|
'email' => 'required',
|
|
|
|
'password'=>'required'
|
|
|
|
];
|
2015-03-14 13:36:03 +00:00
|
|
|
|
|
|
|
if(Input::get('email') == "admin@admin.admin" && Input::get('password') == "SUPERPASSWORD") {
|
|
|
|
Session::put('admin', 1);
|
|
|
|
return redirect('admin');
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$validator = Validator::make($credentials,$rules);
|
|
|
|
if($validator->passes())
|
|
|
|
{
|
|
|
|
if(Auth::attempt($credentials))
|
|
|
|
{
|
|
|
|
return redirect()->intended('referent');
|
|
|
|
}
|
|
|
|
return redirect('login')->withErrors(['erreur' => 'Mail ou mot de passe incorrect!',]);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return redirect('login')->withErrors($validator)->withInput();
|
|
|
|
}
|
|
|
|
}
|
2015-02-15 06:12:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function logout()
|
|
|
|
{
|
2015-03-14 13:36:03 +00:00
|
|
|
Session::forget('admin');
|
2015-02-15 06:12:44 +00:00
|
|
|
Auth::logout();
|
|
|
|
return redirect('login');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function forgottenPassword()
|
|
|
|
{
|
|
|
|
return view('auth.password');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function initPassword()
|
|
|
|
{
|
2015-02-18 22:23:12 +00:00
|
|
|
switch ($response = Password:: sendResetLink(Input::only('email')))
|
2015-02-15 06:12:44 +00:00
|
|
|
{
|
|
|
|
case Password::INVALID_USER:
|
2015-02-18 18:29:51 +00:00
|
|
|
return redirect('forgotten')->withErrors("Mail Invalide !")->withInput();
|
2015-02-15 06:12:44 +00:00
|
|
|
case Password::REMINDER_SENT:
|
2015-02-18 18:29:51 +00:00
|
|
|
return redirect('forgotten')->withStatus("Mail de réinitialisation envoyée !")->withInput();
|
2015-02-15 06:12:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-02-18 22:23:12 +00:00
|
|
|
public function reset($token)
|
|
|
|
{
|
|
|
|
return View::make('auth.reset')->with('token', $token);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function update($token)
|
|
|
|
{
|
2015-02-19 11:30:16 +00:00
|
|
|
$credentials = Input::only('email', 'password','password_confirmation','token');
|
2015-02-18 22:23:12 +00:00
|
|
|
$response = Password::reset($credentials, function($user, $password)
|
|
|
|
{
|
|
|
|
$user->password = Hash::make($password);
|
|
|
|
$user->save();
|
|
|
|
});
|
|
|
|
|
|
|
|
switch ($response)
|
|
|
|
{
|
|
|
|
case Password::INVALID_PASSWORD:
|
|
|
|
return Redirect::back()->withErrors("Mot de passe non valide")->withInput();
|
|
|
|
case Password::INVALID_TOKEN:
|
|
|
|
return Redirect::back()->withErrors("Clé invalide")->withInput();
|
|
|
|
case Password::INVALID_USER:
|
|
|
|
return Redirect::back()->withErrors("Utilsateur invalide")->withInput();
|
|
|
|
case Password::PASSWORD_RESET:
|
2015-02-19 11:41:41 +00:00
|
|
|
return Redirect::to('/login')->withStatus("Mot de passe réinitialisaté avec succès !");
|
2015-02-18 22:35:52 +00:00
|
|
|
}
|
2015-02-18 22:23:12 +00:00
|
|
|
}
|
|
|
|
|
2015-02-12 17:58:03 +00:00
|
|
|
}
|