|
@@ -2,45 +2,20 @@
|
|
|
|
|
|
namespace App\Http\Controllers\AdminAuth;
|
|
namespace App\Http\Controllers\AdminAuth;
|
|
|
|
|
|
-use App\Http\Controllers\Controller;
|
|
|
|
|
|
+use App\Http\Controllers\Controller;
|
|
use Illuminate\Foundation\Auth\AuthenticatesUsers;
|
|
use Illuminate\Foundation\Auth\AuthenticatesUsers;
|
|
-use Illuminate\Support\Facades\Auth;
|
|
|
|
-use Hesto\MultiAuth\Traits\LogsoutGuard;
|
|
|
|
-use Illuminate\Http\Request;
|
|
|
|
-
|
|
|
|
|
|
+use Illuminate\Support\Facades\Auth;
|
|
|
|
+use Illuminate\Http\Request;
|
|
use App\Models\Admin;
|
|
use App\Models\Admin;
|
|
-use App\Models\LoginRecords;
|
|
|
|
|
|
+
|
|
use Session;
|
|
use Session;
|
|
|
|
|
|
class LoginController extends Controller
|
|
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, LogsoutGuard {
|
|
|
|
- LogsoutGuard::logout insteadof AuthenticatesUsers;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * Where to redirect users after login / registration.
|
|
|
|
- *
|
|
|
|
- * @var string
|
|
|
|
- */
|
|
|
|
|
|
+
|
|
public $redirectTo = '/admin/dashboard';
|
|
public $redirectTo = '/admin/dashboard';
|
|
|
|
|
|
- /**
|
|
|
|
- * Create a new controller instance.
|
|
|
|
- *
|
|
|
|
- * @return void
|
|
|
|
- */
|
|
|
|
|
|
+
|
|
public function __construct()
|
|
public function __construct()
|
|
{
|
|
{
|
|
$this->middleware('admin.guest', ['except' => 'logout']);
|
|
$this->middleware('admin.guest', ['except' => 'logout']);
|
|
@@ -53,67 +28,37 @@ class LoginController extends Controller
|
|
*/
|
|
*/
|
|
public function showLoginForm()
|
|
public function showLoginForm()
|
|
{
|
|
{
|
|
- return view('admin.auth.login');
|
|
|
|
|
|
+ return view('admin.auth.admin_login');
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
public function login(Request $request)
|
|
public function login(Request $request)
|
|
{
|
|
{
|
|
$admin = Admin::where('email',$request->email)->first();
|
|
$admin = Admin::where('email',$request->email)->first();
|
|
- if(!$admin){
|
|
|
|
- return redirect('/')->with('error','Unknown Email address!');
|
|
|
|
- }else{
|
|
|
|
- if($admin->status == '0'){
|
|
|
|
- return redirect('/')->with('error','Account Status is not Activated!');
|
|
|
|
|
|
|
|
- }else{
|
|
|
|
|
|
+ if(!$admin){
|
|
|
|
+ return redirect('/admin-login')->with('error','Unknown Email address!');
|
|
|
|
+ }elseif($admin->status){
|
|
|
|
|
|
|
|
+ $credentials = [
|
|
|
|
+ 'email' => $request->email,
|
|
|
|
+ 'password' => $request->password
|
|
|
|
+ ];
|
|
|
|
+
|
|
|
|
+ if (Auth::guard('admin')->attempt($credentials)){
|
|
|
|
|
|
- if($admin->type==5)
|
|
|
|
- return redirect('https://sales.samscrm.co.uk')->with('success','Please login here!');
|
|
|
|
|
|
+ return redirect('admin/dashboard');
|
|
|
|
|
|
|
|
+ }else{
|
|
|
|
|
|
- $credentials = [
|
|
|
|
- 'email' => $request->email,
|
|
|
|
- 'password' => $request->password,
|
|
|
|
- 'status' => '1'
|
|
|
|
- ];
|
|
|
|
-
|
|
|
|
- if (Auth::guard('admin')->attempt($credentials)) {
|
|
|
|
- $time = date('y-m-d h:i:s',time());
|
|
|
|
- $ip = $request->ip();
|
|
|
|
-
|
|
|
|
- $records = new LoginRecords;
|
|
|
|
- $records->auth_type = 'admins';
|
|
|
|
- $records->auth_id = $admin->id;
|
|
|
|
- $records->ip_address = $ip;
|
|
|
|
- $records->start_time = $time;
|
|
|
|
- $records->save();
|
|
|
|
|
|
+ return redirect('/admin-login')->with('error','Wrong Email/Password combination');
|
|
|
|
|
|
- $admin->active_status=1;
|
|
|
|
- $admin->last_logged_timezone=$request->last_logged_timezone;
|
|
|
|
- $admin->api_token=make_api_token('admins');
|
|
|
|
- $admin->update();
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- $previous_session = $admin->session_id;
|
|
|
|
- if($previous_session) {
|
|
|
|
- Session::getHandler()->destroy($previous_session);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- Session::put('session_start', $time);
|
|
|
|
- Session::put('login_record', $records->id);
|
|
|
|
- Session::put('admin_type', 'admins');
|
|
|
|
-
|
|
|
|
- $admin->session_id = Session::getId();
|
|
|
|
- $admin->update();
|
|
|
|
-
|
|
|
|
- return redirect('admin/dashboard');
|
|
|
|
- }else{
|
|
|
|
- return redirect('/')->with('error','Wrong Email/Password combination');
|
|
|
|
- }
|
|
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ }else{
|
|
|
|
+ return redirect('/admin-login')->with('error', 'Account Status is not Activated!');
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -127,45 +72,9 @@ class LoginController extends Controller
|
|
return Auth::guard('admin');
|
|
return Auth::guard('admin');
|
|
}
|
|
}
|
|
|
|
|
|
- public function logout(){
|
|
|
|
-
|
|
|
|
- $auth_user=Auth::guard('admin')->user();
|
|
|
|
-
|
|
|
|
- if($auth_user){
|
|
|
|
-
|
|
|
|
- $auth_user->update([
|
|
|
|
- 'active_status'=>0,
|
|
|
|
- 'api_token'=>NULL
|
|
|
|
- ]);
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if(Session::get('login_record')){
|
|
|
|
- $record_id = Session::get('login_record');
|
|
|
|
- $time = date('y-m-d h:i:s',time());
|
|
|
|
- $records = LoginRecords::find($record_id);
|
|
|
|
- if($records){
|
|
|
|
- $records->end_time = $time;
|
|
|
|
- $records->update();
|
|
|
|
-
|
|
|
|
- if($records->login_source){
|
|
|
|
- $source = $records->loginSource->source;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- $previous_session = Auth::guard('admin')->session_id;
|
|
|
|
- if($previous_session) {
|
|
|
|
- Session::getHandler()->destroy($previous_session);
|
|
|
|
- }
|
|
|
|
- Auth::guard('admin')->logout();
|
|
|
|
-
|
|
|
|
- if(!isset($source)){
|
|
|
|
- return redirect('/');
|
|
|
|
- }else{
|
|
|
|
- return redirect($source);
|
|
|
|
- }
|
|
|
|
- //return redirect('/admin');
|
|
|
|
|
|
+ public function logout(){
|
|
|
|
+ $this->guard('admin')->logout();
|
|
|
|
+ return redirect('/admin-login');
|
|
}
|
|
}
|
|
|
|
|
|
public function showRegisterForm()
|
|
public function showRegisterForm()
|