Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
| Total | |
0.00% |
0 / 1 |
|
0.00% |
0 / 4 |
CRAP | |
0.00% |
0 / 49 |
| LoginController | |
0.00% |
0 / 1 |
|
0.00% |
0 / 4 |
182 | |
0.00% |
0 / 49 |
| __construct | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 2 |
|||
| redirectToProvider | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 1 |
|||
| handleProviderCallback | |
0.00% |
0 / 1 |
20 | |
0.00% |
0 / 13 |
|||
| login | |
0.00% |
0 / 1 |
56 | |
0.00% |
0 / 33 |
|||
| <?php | |
| namespace App\Http\Controllers\Auth; | |
| use App\Http\Controllers\Controller; | |
| use Illuminate\Foundation\Auth\AuthenticatesUsers; | |
| use Illuminate\Support\Facades\Hash; | |
| use Illuminate\Http\Request; | |
| use Illuminate\Support\Facades\Auth; | |
| use Jenssegers\Agent\Agent; | |
| use Illuminate\Support\Facades\Session; | |
| use Socialite; | |
| use App\Models\Auth\User; | |
| 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 | |
| { | |
| login as protected parent_login; | |
| } | |
| /** | |
| * Where to redirect users after login. | |
| * | |
| * @var string | |
| */ | |
| protected $redirectTo = '/login'; | |
| /** | |
| * Create a new controller instance. | |
| * | |
| * @return void | |
| */ | |
| public function __construct() | |
| { | |
| $this->middleware('guest')->except('logout'); | |
| } | |
| public function redirectToProvider($provider) | |
| { | |
| return Socialite::driver($provider)->redirect(); | |
| } | |
| public function handleProviderCallback($provider) | |
| { | |
| try { | |
| $user = Socialite::driver($provider)->user(); | |
| } catch (Exception $e) { | |
| return redirect('/login'); | |
| } | |
| // check if they're an existing user | |
| $existingUser = User::where('email', $user->email)->first(); | |
| if($existingUser){ | |
| // log them in | |
| auth()->login($existingUser, true); | |
| if( ! $existingUser->google_id ) { | |
| $existingUser->google_id = $user->id; | |
| $existingUser->save(); | |
| } | |
| } else { | |
| Session::flash('message', 'Your Account Not Exist'); | |
| Session::flash('alert-class', 'alert-danger'); | |
| return redirect('/login'); | |
| } | |
| return redirect()->to('/home'); | |
| } | |
| /** | |
| * Handle an authentication attempt. | |
| * | |
| * @param \Illuminate\Http\Request $request | |
| * | |
| * @return Response | |
| */ | |
| public function login(Request $request) | |
| { | |
| $agent = new Agent(); | |
| $platform = $agent->platform(); | |
| if($platform=='AndroidOS') | |
| { | |
| Session::flash('message', 'Login not allowed from mobile device.'); | |
| Session::flash('alert-class', 'alert-danger'); | |
| return redirect()->back(); | |
| } | |
| else if($platform=='iOS') | |
| { | |
| Session::flash('message', 'Login not allowed from mobile device.'); | |
| Session::flash('alert-class', 'alert-danger'); | |
| return redirect()->back(); | |
| }else{ | |
| $useremail = $request->input('email'); | |
| $password = $request->input('password'); | |
| $user = User::where('email', $useremail)->first(); | |
| if (!$user) { | |
| // Email does not exist | |
| Session::flash('message', 'Your email is incorrect.'); | |
| Session::flash('alert-class', 'alert-danger'); | |
| return redirect()->back()->withInput(); | |
| } | |
| if (!Hash::check($password, $user->password)) { | |
| // Password is incorrect | |
| Session::flash('message', 'Your password is incorrect.'); | |
| Session::flash('alert-class', 'alert-danger'); | |
| return redirect()->back()->withInput(); | |
| } | |
| else{ | |
| $useremail = $request->email; | |
| $isChecked = User::select('is_checked') | |
| ->where('email', $useremail) | |
| ->get(); | |
| if($isChecked[0]->is_checked == "1"){ | |
| // return view('/auth/login'); | |
| Session::flash('message', 'You are not allowed to login.'); | |
| Session::flash('alert-class', 'alert-danger'); | |
| Session::flash('fadeout', 3000); | |
| return redirect()->back(); | |
| }else if($isChecked[0]->is_checked == "0"){ | |
| // return redirect()->route("home"); | |
| return $this->parent_login($request); | |
| } | |
| } | |
| } | |
| } | |
| } |