modularsoftware /
genealogy
| 1 | <?php |
||||||
| 2 | |||||||
| 3 | namespace App\Http\Controllers\Auth; |
||||||
| 4 | |||||||
| 5 | use App\Events\enso\core\Login; |
||||||
| 6 | use App\Http\Controllers\Controller; |
||||||
| 7 | use App\Models\User; |
||||||
| 8 | use App\Traits\ConnectionTrait; |
||||||
| 9 | use Illuminate\Foundation\Auth\AuthenticatesUsers; |
||||||
| 10 | use Illuminate\Http\Request; |
||||||
| 11 | use Illuminate\Support\Facades\Auth; |
||||||
| 12 | use Illuminate\Validation\ValidationException; |
||||||
| 13 | use LaravelEnso\Multitenancy\Enums\Connections; |
||||||
| 14 | use LaravelEnso\Multitenancy\Services\Tenant; |
||||||
| 15 | |||||||
| 16 | class LoginController extends Controller |
||||||
| 17 | { |
||||||
| 18 | use AuthenticatesUsers, ConnectionTrait; |
||||||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||||||
| 19 | |||||||
| 20 | protected $redirectTo = '/'; |
||||||
| 21 | |||||||
| 22 | public function __construct() |
||||||
| 23 | { |
||||||
| 24 | $this->middleware('guest')->except('logout'); |
||||||
| 25 | |||||||
| 26 | $this->maxAttempts = config('enso.auth.maxLoginAttempts'); |
||||||
|
0 ignored issues
–
show
|
|||||||
| 27 | } |
||||||
| 28 | |||||||
| 29 | public function logout(Request $request) |
||||||
| 30 | { |
||||||
| 31 | $this->guard()->logout(); |
||||||
| 32 | |||||||
| 33 | $request->session()->invalidate(); |
||||||
| 34 | } |
||||||
| 35 | |||||||
| 36 | protected function attemptLogin(Request $request) |
||||||
| 37 | { |
||||||
| 38 | $user = $this->loggableUser($request); |
||||||
| 39 | |||||||
| 40 | if (! $user) { |
||||||
| 41 | return false; |
||||||
| 42 | } |
||||||
| 43 | |||||||
| 44 | Auth::login($user, $request->input('remember')); |
||||||
| 45 | |||||||
| 46 | Login::dispatch($user, $request->ip(), $request->header('User-Agent')); |
||||||
| 47 | |||||||
| 48 | return true; |
||||||
| 49 | } |
||||||
| 50 | |||||||
| 51 | protected function authenticated(Request $request, $user) |
||||||
|
0 ignored issues
–
show
The parameter
$request is not used and could be removed.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for parameters that have been defined for a function or method, but which are not used in the method body. Loading history...
The parameter
$user is not used and could be removed.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for parameters that have been defined for a function or method, but which are not used in the method body. Loading history...
|
|||||||
| 52 | { |
||||||
| 53 | return response()->json([ |
||||||
| 54 | 'auth' => Auth::check(), |
||||||
| 55 | 'csrfToken' => csrf_token(), |
||||||
| 56 | ]); |
||||||
| 57 | } |
||||||
| 58 | |||||||
| 59 | private function loggableUser(Request $request) |
||||||
| 60 | { |
||||||
| 61 | $user = User::whereEmail($request->input('email'))->first(); |
||||||
| 62 | $company = $user->company(); |
||||||
| 63 | $tanent = false; |
||||||
|
0 ignored issues
–
show
|
|||||||
| 64 | if ($company) { |
||||||
| 65 | $tanent = true; |
||||||
| 66 | } |
||||||
| 67 | // set company id as default |
||||||
| 68 | $main_company = $user->person->company(); |
||||||
| 69 | if ($main_company !== null && ! ($user->isAdmin())) { |
||||||
| 70 | $c_id = $main_company->id; |
||||||
| 71 | $db = Connections::Tenant.$c_id; |
||||||
| 72 | $this->setConnection(Connections::Tenant, $db); |
||||||
| 73 | } |
||||||
| 74 | |||||||
| 75 | if (! optional($user)->currentPasswordIs($request->input('password'))) { |
||||||
| 76 | return; |
||||||
| 77 | } |
||||||
| 78 | |||||||
| 79 | if ($user->passwordExpired()) { |
||||||
| 80 | throw ValidationException::withMessages([ |
||||||
| 81 | 'email' => 'Password expired. Please set a new one.', |
||||||
| 82 | ]); |
||||||
| 83 | } |
||||||
| 84 | if ($user->isInactive()) { |
||||||
| 85 | throw ValidationException::withMessages([ |
||||||
| 86 | 'email' => 'Account disabled. Please contact the administrator.', |
||||||
| 87 | ]); |
||||||
| 88 | } |
||||||
| 89 | |||||||
| 90 | return $user; |
||||||
| 91 | } |
||||||
| 92 | } |
||||||
| 93 |