Skip to content

Commit 3d42a3f

Browse files
authored
Merge pull request #409 from leepeuker/add-default-login-credentials
Add optional enviornment variable to set default login credentials
2 parents e0dd46b + 430aa20 commit 3d42a3f

File tree

5 files changed

+20
-3
lines changed

5 files changed

+20
-3
lines changed

Diff for: docs/configuration.md

+2
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ The `Web UI` column is set to yes if an environment variable can alternatively b
2323
| `ENABLE_REGISTRATION` | `0` | Enables public user registration | |
2424
| `MIN_RUNTIME_IN_SECONDS_FOR_JOB_PROCESSING` | `15` | Minimum time between background jobs processing | |
2525
| `TIMEZONE` | `"Europe/Berlin"` | Supported timezones [here](https://www.php.net/manual/en/timezones.php) | |
26+
| `DEFAULT_LOGIN_EMAIL` | - | Email address to always autofill on login page | |
27+
| `DEFAULT_LOGIN_PASSWORD` | - | Password to always autofill on login page | |
2628

2729
### Database
2830

Diff for: src/Factory.php

+2
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,8 @@ public static function createLandingPageController(ContainerInterface $container
215215
$container->get(UserApi::class),
216216
$container->get(SessionWrapper::class),
217217
$config->getAsBool('ENABLE_REGISTRATION', false),
218+
$config->getAsStringNullable('DEFAULT_LOGIN_EMAIL'),
219+
$config->getAsStringNullable('DEFAULT_LOGIN_PASSWORD'),
218220
);
219221
}
220222

Diff for: src/HttpController/LandingPageController.php

+5-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ public function __construct(
1717
private readonly UserApi $userApi,
1818
private readonly SessionWrapper $sessionWrapper,
1919
private readonly bool $registrationEnabled,
20+
private readonly ?string $defaultEmail,
21+
private readonly ?string $defaultPassword,
2022
) {
2123
}
2224

@@ -42,7 +44,9 @@ public function render() : Response
4244
$this->twig->render('page/login.html.twig', [
4345
'failedLogin' => $failedLogin,
4446
'deletedAccount' => $deletedAccount,
45-
'registrationEnabled' => $this->registrationEnabled
47+
'registrationEnabled' => $this->registrationEnabled,
48+
'defaultEmail' => $this->defaultEmail,
49+
'defaultPassword' => $this->defaultPassword,
4650
]),
4751
);
4852
}

Diff for: src/ValueObject/Config.php

+9
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,15 @@ public function getAsString(string $key, ?string $fallbackValue = null) : string
5555
}
5656
}
5757

58+
public function getAsStringNullable(string $key, ?string $fallbackValue = null) : ?string
59+
{
60+
try {
61+
return $this->getAsString($key, $fallbackValue);
62+
} catch (ConfigKeyNotSetException) {
63+
return null;
64+
}
65+
}
66+
5867
/** @throws ConfigKeyNotSetException */
5968
private function get(string $key) : mixed
6069
{

Diff for: templates/page/login.html.twig

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@
1616
<form action="/login" method="post" enctype="multipart/form-data">
1717
<h1 id="header" class="text-{{ theme == 'dark' ? 'light' : 'dark' }}" style="margin-bottom: 1rem">Movary</h1>
1818
<div class="form-floating">
19-
<input type="email" name="email" class="form-control text-{{ theme == 'dark' ? 'light' : 'dark' }}" id="floatingInput" placeholder="[email protected]" required>
19+
<input type="email" name="email" value="{{ defaultEmail }}" class="form-control text-{{ theme == 'dark' ? 'light' : 'dark' }}" id="floatingInput" placeholder="[email protected]" required>
2020
<label for="floatingInput">Email address</label>
2121
</div>
2222
<div class="form-floating">
23-
<input type="password" name="password" class="form-control text-{{ theme == 'dark' ? 'light' : 'dark' }}" id="floatingPassword" placeholder="Password" required>
23+
<input type="password" name="password" value="{{ defaultPassword }}" class="form-control text-{{ theme == 'dark' ? 'light' : 'dark' }}" id="floatingPassword" placeholder="Password" required>
2424
<label for="floatingPassword">Password</label>
2525
</div>
2626

0 commit comments

Comments
 (0)