2016-02-29 15:59:36 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
|
2016-03-05 00:18:10 +00:00
|
|
|
use Auth;
|
|
|
|
|
use Illuminate\Contracts\Auth\Guard;
|
2016-03-09 22:05:39 +00:00
|
|
|
use Illuminate\Http\Request;
|
2016-03-05 00:18:10 +00:00
|
|
|
use Input;
|
|
|
|
|
use Redirect;
|
|
|
|
|
use View;
|
|
|
|
|
|
|
|
|
|
class UserLoginController extends Controller
|
|
|
|
|
{
|
2016-02-29 15:59:36 +00:00
|
|
|
protected $auth;
|
|
|
|
|
|
2016-03-05 00:18:10 +00:00
|
|
|
public function __construct(Guard $auth)
|
|
|
|
|
{
|
2016-02-29 15:59:36 +00:00
|
|
|
$this->auth = $auth;
|
|
|
|
|
$this->middleware('guest');
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-09 22:05:39 +00:00
|
|
|
/**
|
|
|
|
|
* Shows login form.
|
|
|
|
|
*
|
|
|
|
|
* @param Request $request
|
|
|
|
|
*
|
|
|
|
|
* @return mixed
|
|
|
|
|
*/
|
|
|
|
|
public function showLogin(Request $request)
|
2016-03-05 00:18:10 +00:00
|
|
|
{
|
2016-02-29 15:59:36 +00:00
|
|
|
/*
|
|
|
|
|
* If there's an ajax request to the login page assume the person has been
|
|
|
|
|
* logged out and redirect them to the login page
|
|
|
|
|
*/
|
2016-03-09 22:05:39 +00:00
|
|
|
if ($request->ajax()) {
|
2016-06-16 02:12:44 +00:00
|
|
|
return response()->json([
|
2016-06-15 02:31:24 +00:00
|
|
|
'status' => 'success',
|
|
|
|
|
'redirectUrl' => route('login'),
|
2016-03-05 00:18:10 +00:00
|
|
|
]);
|
2016-02-29 15:59:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return View::make('Public.LoginAndRegister.Login');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2016-03-09 22:05:39 +00:00
|
|
|
* Handles the login request.
|
|
|
|
|
*
|
|
|
|
|
* @param Request $request
|
2016-03-05 00:18:10 +00:00
|
|
|
*
|
2016-03-09 22:05:39 +00:00
|
|
|
* @return mixed
|
2016-02-29 15:59:36 +00:00
|
|
|
*/
|
2016-03-09 22:05:39 +00:00
|
|
|
public function postLogin(Request $request)
|
2016-03-05 00:18:10 +00:00
|
|
|
{
|
2016-03-09 22:05:39 +00:00
|
|
|
$email = $request->get('email');
|
|
|
|
|
$password = $request->get('password');
|
|
|
|
|
|
|
|
|
|
if (empty($email) || empty($password)) {
|
|
|
|
|
return Redirect::back()
|
|
|
|
|
->with(['message' => 'Please fill in your email and password', 'failed' => true])
|
|
|
|
|
->withInput();
|
|
|
|
|
}
|
2016-02-29 15:59:36 +00:00
|
|
|
|
2016-03-09 22:05:39 +00:00
|
|
|
if ($this->auth->attempt(['email' => $email, 'password' => $password], true) === false) {
|
|
|
|
|
return Redirect::back()
|
|
|
|
|
->with(['message' => 'Your username/password combination was incorrect', 'failed' => true])
|
|
|
|
|
->withInput();
|
2016-02-29 15:59:36 +00:00
|
|
|
}
|
2016-03-05 00:18:10 +00:00
|
|
|
|
2016-03-09 22:05:39 +00:00
|
|
|
return Redirect::to(route('showSelectOrganiser'));
|
2016-02-29 15:59:36 +00:00
|
|
|
}
|
|
|
|
|
}
|