2015-02-12 20:00:23 +01:00
|
|
|
<?php namespace App\Http\Controllers;
|
|
|
|
|
2015-02-17 15:56:30 +01:00
|
|
|
use App\User;
|
2015-02-17 20:33:32 +01:00
|
|
|
use Input;
|
2015-02-18 01:21:24 +01:00
|
|
|
use Auth;
|
|
|
|
use Session;
|
2015-02-16 16:27:16 +01:00
|
|
|
|
2015-02-12 20:00:23 +01:00
|
|
|
class AdminController extends Controller {
|
|
|
|
|
2015-02-13 11:41:05 +01:00
|
|
|
|
2015-02-12 20:00:23 +01:00
|
|
|
/**
|
|
|
|
* Create a new controller instance.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function __construct()
|
|
|
|
{
|
2015-02-15 07:12:44 +01:00
|
|
|
//
|
2015-02-12 20:00:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Show the application dashboard to the user.
|
|
|
|
*
|
|
|
|
* @return Response
|
|
|
|
*/
|
|
|
|
public function index()
|
|
|
|
{
|
2015-02-17 15:56:30 +01:00
|
|
|
$me = User::current();
|
|
|
|
$user = User::all();
|
2015-02-16 16:27:16 +01:00
|
|
|
return view('admin', ['nameRoute' => 'Admin', 'users' => $user, 'me' => $me]);
|
2015-02-12 20:00:23 +01:00
|
|
|
}
|
|
|
|
|
2015-02-17 15:56:30 +01:00
|
|
|
/**
|
|
|
|
* Add an user in database.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
public function addUser()
|
|
|
|
{
|
2015-02-17 20:33:32 +01:00
|
|
|
$user = new User;
|
|
|
|
|
2015-02-17 20:53:30 +01:00
|
|
|
$user->firstname = Input::get('firstname');
|
2015-02-17 20:33:32 +01:00
|
|
|
$user->email = Input::get('email');
|
2015-02-17 23:07:12 +01:00
|
|
|
$user->droits = (Input::get('isadmin'))?1:0;
|
2015-02-17 20:53:30 +01:00
|
|
|
$user->city = Input::get('city');
|
|
|
|
$user->lastname = Input::get('lastname');
|
2015-02-17 21:57:41 +01:00
|
|
|
$user->image = "pictures/user_picture/default.png";
|
2015-02-17 20:33:32 +01:00
|
|
|
|
|
|
|
$user->save();
|
2015-02-18 00:31:21 +01:00
|
|
|
return redirect('/admin')->with('message_add', 'User ajouté avec succès');
|
2015-02-17 20:33:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-02-18 00:01:05 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* updateUser an user in database.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
public function updateUser()
|
|
|
|
{
|
|
|
|
$user = User::find(Input::get('idUser'));
|
|
|
|
|
|
|
|
$user->firstname = Input::get('firstname');
|
|
|
|
$user->email = Input::get('email');
|
|
|
|
$user->city = Input::get('city');
|
|
|
|
$user->lastname = Input::get('lastname');
|
|
|
|
//$user->image = "pictures/user_picture/default.png";
|
|
|
|
|
|
|
|
$user->save();
|
2015-02-18 00:31:21 +01:00
|
|
|
return redirect('/admin')->with('message_update', 'User mis à jour avec succès');
|
2015-02-18 00:01:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-02-17 20:33:32 +01:00
|
|
|
/**
|
|
|
|
* Delete an user
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
public function deleteUser()
|
|
|
|
{
|
2015-02-17 21:57:41 +01:00
|
|
|
$idUser = Input::get('idUser');
|
|
|
|
$user = User::find($idUser);
|
|
|
|
$user->delete();
|
2015-02-18 00:31:21 +01:00
|
|
|
return redirect('/admin')->with('message_delete', 'User supprimé avec succès');
|
2015-02-17 15:56:30 +01:00
|
|
|
}
|
|
|
|
|
2015-02-18 01:21:24 +01:00
|
|
|
/**
|
|
|
|
* Log as one user
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
public function logAs()
|
|
|
|
{
|
|
|
|
// Saving idUser in Session
|
|
|
|
$me = Auth::user()->id;
|
|
|
|
Session::put('admin', $me);
|
|
|
|
|
|
|
|
// logout from Auth
|
|
|
|
Auth::logout();
|
|
|
|
|
|
|
|
// Log as referent
|
|
|
|
$idUser = Input::get('idUser');
|
|
|
|
Auth::loginUsingId($idUser);
|
|
|
|
|
|
|
|
// Redirect referent route
|
|
|
|
return redirect('/referent');
|
|
|
|
}
|
|
|
|
|
2015-02-12 20:00:23 +01:00
|
|
|
}
|