Last active
June 19, 2024 09:52
-
-
Save xorenio/b82e12d706a4a6b8eb6e8869cd33a38f to your computer and use it in GitHub Desktop.
bad ideas
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 | |
/* SWITCH USER ACCOUNTS */ | |
public function getChangeAccount($id) | |
{ | |
if(Session::has('old_id')) | |
if($id != Session::get('old_id')) | |
{ | |
Session::forget('old_id'); | |
if(Session::has('old_email')) | |
Session::forget('old_email'); | |
} | |
if(! Session::has('old_id')) | |
if(Session::has('old_email')) | |
Session::forget('old_email'); | |
if(Session::has('old_email') && strlen(trim(Session::get('old_email'))) > 4 ) | |
{ | |
$a = Customers::where('customers_email', Session::get('old_email'))->first(); | |
$a->checkData(); | |
$user = User::where('customers_email',Session::get('old_email'))->first(); | |
} | |
if(! isset($user) || (isset($user) && count($user)==0)) | |
{ | |
$user = User::find($id); | |
} | |
if(! isset($user) || (isset($user) && count($user)==0)) | |
{ | |
$a = Customers::find($id); | |
$a->checkData(); | |
$user = User::find($id); | |
} | |
if(! isset($user) || (isset($user) && (is_null($user) || count($user) == 0))) | |
return Redirect::to('/')->with('error', 'Cant find user'); | |
if(Session::has('old_id')) | |
{ | |
$success = 0; | |
if(Session::get('old_id') == $id) | |
{ | |
$success = 1; | |
} | |
if($success == 1) | |
{ | |
Session::forget('old_id'); | |
Session::forget('old_email'); | |
Auth::login($user); | |
if(in_array($user->admin, [1,2])) | |
return Redirect::to('/admin/customers'); | |
return Redirect::to('/'); | |
} | |
if($success == 0) | |
return returnErrorToClient('Please login.', '/login'); | |
} | |
if(is_null($user) || count($user) == 0) | |
{ | |
return returnErrorToClient('Please login...', '/login'); | |
}else | |
{ | |
if(! Session::has('old_id')) | |
{ | |
Session::put('old_id', Auth::id()); | |
Session::put('old_email', trim(Auth::user()->customers_email)); | |
} | |
Auth::login($user); | |
if(in_array($user->admin, [1,2])) | |
return Redirect::to('/admin/customers'); | |
return Redirect::to('/'); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment