This repository was archived by the owner on Aug 22, 2025. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathLoginController.php
More file actions
59 lines (46 loc) · 1.53 KB
/
LoginController.php
File metadata and controls
59 lines (46 loc) · 1.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<?php
declare(strict_types=1);
namespace Codedge\MagicLink\Http\Controllers\Cp\Auth;
use Codedge\MagicLink\Repositories\SettingsRepository;
use Illuminate\Http\Request;
use Statamic\Facades\OAuth;
use Statamic\Http\Controllers\CP\Auth\LoginController as StatamicLoginController;
class LoginController extends StatamicLoginController
{
protected SettingsRepository $settingsRepository;
public function __construct(SettingsRepository $settingsRepository)
{
parent::__construct();
$this->settingsRepository = $settingsRepository;
}
public function showLoginForm(Request $request)
{
if (! $this->settingsRepository->isEnabled()) {
return parent::showLoginForm($request);
}
$data = [
'title' => __('Log in'),
'oauth' => $enabled = OAuth::enabled(),
'providers' => $enabled ? OAuth::providers() : [],
'referer' => $this->getReferrer(),
'hasError' => $this->hasError(),
];
$view = view('magiclink::auth.login', $data);
if ($request->expired) {
return $view->withErrors(__('Session Expired'));
}
return $view;
}
private function hasError()
{
return function ($field) {
if (! $error = optional(session('errors'))->first($field)) {
return false;
}
return ! in_array($error, [
__('auth.failed'),
__('statamic::validation.required'),
]);
};
}
}