123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899 |
- <?php
- namespace App\Http\Controllers\TeacherAuth;
- use App\Http\Controllers\Controller;
- use Illuminate\Foundation\Auth\AuthenticatesUsers;
- use Illuminate\Support\Facades\Auth;
- use Illuminate\Http\Request;
- use App\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.
- |
- */
- /**
- * Where to redirect users after login / registration.
- *
- * @var string
- */
- public $redirectTo = '/teacher_profile';
- /**
- * Create a new controller instance.
- *
- * @return void
- */
- public function __construct()
- {
- $this->middleware('teacher.guest', ['except' => 'logout']);
- }
- /**
- * Show the application's login form.
- *
- * @return \Illuminate\Http\Response
- */
- public function showLoginForm()
- {
- return view('login-v2');
- }
- public function login(Request $request)
- {
- $teacher = User::where('user_type',2)->where('email',$request->email)->first();
- if(!$teacher){
- return redirect('/')->with('error','Unknown Email address!');
- }else{
- if($teacher->status == '0'){
- return redirect('/')->with('error', 'Account Status is not Activated!');
- }
- else{
- $credentials = [
- 'email' => $request->email,
- 'password' => $request->password,
- 'status' => '1'
- ];
- if (Auth::guard('teacher')->attempt($credentials)) {
- return redirect('teacher_profile');
- }
- else{
- return redirect('/')->with('error','Wrong Email/Password combination');
- }
- }
- }
- }
- public function logout(){
- $this->guard('teacher')->logout();
- request()->session()->invalidate();
- return redirect('/login-v2');
- }
- /**
- * Get the guard to be used during authentication.
- *
- * @return \Illuminate\Contracts\Auth\StatefulGuard
- */
- protected function guard()
- {
- return Auth::guard('teacher');
- }
- }
|