Created
July 29, 2017 21:58
-
-
Save worldwayii/f562befab693b5f72fd9d303d4dd8124 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Legitcar\Http\Controllers\Auth; | |
use Legitcar\Helpers; | |
use Illuminate\Http\Request; | |
use Legitcar\Api\V1\Models\User; | |
use Illuminate\Support\Facades\Auth; | |
use Legitcar\Http\Controllers\Controller; | |
use Legitcar\Http\Controllers\DashboardController; | |
use Illuminate\Foundation\Auth\AuthenticatesUsers; | |
class LoginController extends Controller | |
{ | |
/* | |
|-------------------------------------------------------------------------- | |
| Login Controller | |
|-------------------------------------------------------------------------- | |
| | |
| This controller handles authenticating users for the application and | |
| redirecting them to your home screen. The controller uses a trait | |
| to conveniently provide its functionality to your applications. | |
| | |
*/ | |
use AuthenticatesUsers; | |
/** | |
* Where to redirect users after log out. | |
* | |
* @var string | |
*/ | |
protected $redirectAfterLogout = '/'; | |
/** | |
* Create a new controller instance. | |
* | |
* @return void | |
*/ | |
public function __construct() | |
{ | |
$this->middleware('guest', ['except' => 'logout']); | |
} | |
/** | |
* Where to redirect users after login. | |
* | |
* @var string | |
*/ | |
protected function redirectTo() | |
{ | |
if(Auth::user()->role_id == Config::get('constants.roles.regular')) | |
{ | |
$userdata = Auth::user(); | |
return '/user/dashboard'; | |
} | |
} | |
public function login(Request $request) | |
{ | |
$request->except('_token'); | |
$credentials = $request->only('email', 'password'); | |
$email = $request->email; | |
$password = $request->password; | |
$field = filter_var($email, FILTER_VALIDATE_EMAIL) ? 'email' : 'phone_number'; | |
$user = User::where($field, '=', $email)->first(); | |
if ($user == null) { | |
$url = url('user/register'); | |
return View('user.auth.login')->with('message', "This email is not registerd with Legitcar, Click on Register to sign up for free. "); | |
} | |
if(Auth::attempt(array($field => $email, 'password' => $password), $request->remember)) | |
{ | |
if($user->comfirmed == 0) | |
{ | |
return View('user.auth.login')->with('message', "This account has not been verified. Please check your email to activate from the link"); | |
} | |
// dd("let me go"); | |
$user->last_login = date('Y-m-d H:i:s'); | |
$user->save(); | |
return redirect('user/dashboard'); | |
} | |
else | |
{ | |
$request->flash(); | |
return View('user.auth.login')->with('message', 'Incorrect login details. Please try again.'); | |
} | |
} | |
public function logout() | |
{ | |
Auth::logout(); | |
Session::flush(); | |
return redirect('/'); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment