Skip to content

Commit

Permalink
Add env variables for default login credentials
Browse files Browse the repository at this point in the history
  • Loading branch information
leepeuker committed Jun 24, 2023
1 parent e0dd46b commit 430aa20
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 3 deletions.
2 changes: 2 additions & 0 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ The `Web UI` column is set to yes if an environment variable can alternatively b
| `ENABLE_REGISTRATION` | `0` | Enables public user registration | |
| `MIN_RUNTIME_IN_SECONDS_FOR_JOB_PROCESSING` | `15` | Minimum time between background jobs processing | |
| `TIMEZONE` | `"Europe/Berlin"` | Supported timezones [here](https://www.php.net/manual/en/timezones.php) | |
| `DEFAULT_LOGIN_EMAIL` | - | Email address to always autofill on login page | |
| `DEFAULT_LOGIN_PASSWORD` | - | Password to always autofill on login page | |

### Database

Expand Down
2 changes: 2 additions & 0 deletions src/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,8 @@ public static function createLandingPageController(ContainerInterface $container
$container->get(UserApi::class),
$container->get(SessionWrapper::class),
$config->getAsBool('ENABLE_REGISTRATION', false),
$config->getAsStringNullable('DEFAULT_LOGIN_EMAIL'),
$config->getAsStringNullable('DEFAULT_LOGIN_PASSWORD'),
);
}

Expand Down
6 changes: 5 additions & 1 deletion src/HttpController/LandingPageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ public function __construct(
private readonly UserApi $userApi,
private readonly SessionWrapper $sessionWrapper,
private readonly bool $registrationEnabled,
private readonly ?string $defaultEmail,
private readonly ?string $defaultPassword,
) {
}

Expand All @@ -42,7 +44,9 @@ public function render() : Response
$this->twig->render('page/login.html.twig', [
'failedLogin' => $failedLogin,
'deletedAccount' => $deletedAccount,
'registrationEnabled' => $this->registrationEnabled
'registrationEnabled' => $this->registrationEnabled,
'defaultEmail' => $this->defaultEmail,
'defaultPassword' => $this->defaultPassword,
]),
);
}
Expand Down
9 changes: 9 additions & 0 deletions src/ValueObject/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,15 @@ public function getAsString(string $key, ?string $fallbackValue = null) : string
}
}

public function getAsStringNullable(string $key, ?string $fallbackValue = null) : ?string
{
try {
return $this->getAsString($key, $fallbackValue);
} catch (ConfigKeyNotSetException) {
return null;
}
}

/** @throws ConfigKeyNotSetException */
private function get(string $key) : mixed
{
Expand Down
4 changes: 2 additions & 2 deletions templates/page/login.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@
<form action="/login" method="post" enctype="multipart/form-data">
<h1 id="header" class="text-{{ theme == 'dark' ? 'light' : 'dark' }}" style="margin-bottom: 1rem">Movary</h1>
<div class="form-floating">
<input type="email" name="email" class="form-control text-{{ theme == 'dark' ? 'light' : 'dark' }}" id="floatingInput" placeholder="[email protected]" required>
<input type="email" name="email" value="{{ defaultEmail }}" class="form-control text-{{ theme == 'dark' ? 'light' : 'dark' }}" id="floatingInput" placeholder="[email protected]" required>
<label for="floatingInput">Email address</label>
</div>
<div class="form-floating">
<input type="password" name="password" class="form-control text-{{ theme == 'dark' ? 'light' : 'dark' }}" id="floatingPassword" placeholder="Password" required>
<input type="password" name="password" value="{{ defaultPassword }}" class="form-control text-{{ theme == 'dark' ? 'light' : 'dark' }}" id="floatingPassword" placeholder="Password" required>
<label for="floatingPassword">Password</label>
</div>

Expand Down

0 comments on commit 430aa20

Please sign in to comment.