Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add basic admin password reset #483

Draft
wants to merge 10 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .env.development.example
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ LOG_LEVEL=debug
LOG_ENABLE_STACKTRACE=1

# Email
#EMAIL_ENABLED=
#SMTP_HOST=
#SMTP_PORT=
#SMTP_SENDER_ADDRESS=
Expand Down
1 change: 1 addition & 0 deletions .env.production.example
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ TMDB_ENABLE_IMAGE_CACHING=1
LOG_LEVEL=warning

# Email
#EMAIL_ENABLED=
#SMTP_HOST=
#SMTP_PORT=
#SMTP_SENDER_ADDRESS=
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?php
declare(strict_types=1);
<?php declare(strict_types=1);

use Phinx\Migration\AbstractMigration;

Expand Down
27 changes: 27 additions & 0 deletions db/migrations/mysql/20230828152640_AddPasswordResetTable.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php declare(strict_types=1);

use Phinx\Migration\AbstractMigration;

final class AddPasswordResetTable extends AbstractMigration
{
public function down() : void
{
$this->execute('DROP TABLE `user_password_reset`');
}

public function up() : void
{
$this->execute(
<<<SQL
CREATE TABLE `user_password_reset` (
`user_id` INT(10) UNSIGNED NOT NULL,
`token` CHAR(36) NOT NULL,
`expires_at` DATETIME NOT NULL,
`created_at` DATETIME NOT NULL,
PRIMARY KEY (`token`),
FOREIGN KEY (`user_id`) REFERENCES `user`(`id`) ON DELETE CASCADE
) COLLATE="utf8mb4_unicode_ci" ENGINE=InnoDB
SQL,
);
}
}
27 changes: 27 additions & 0 deletions db/migrations/sqlite/20230828152640_AddPasswordResetTable.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php declare(strict_types=1);

use Phinx\Migration\AbstractMigration;

final class AddPasswordResetTable extends AbstractMigration
{
public function down() : void
{
$this->execute('DROP TABLE `user_password_reset`');
}

public function up() : void
{
$this->execute(
<<<SQL
CREATE TABLE `user_password_reset` (
`user_id` INT(10) NOT NULL,
`token` CHAR(36) NOT NULL,
`expires_at` TEXT NOT NULL,
`created_at` TEXT NOT NULL,
PRIMARY KEY (`token`),
FOREIGN KEY (`user_id`) REFERENCES `user`(`id`) ON DELETE CASCADE
)
SQL,
);
}
}
23 changes: 12 additions & 11 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,17 +55,18 @@ Required for some third party integrations. Only necessary if the relevant third

### Email

Required when email support is wanted

| NAME | DEFAULT VALUE | INFO | Web UI |
|:--------------------|:-------------:|:-------------------------------------|:------:|
| `SMTP_HOST` | - | | yes |
| `SMTP_PORT` | - | | yes |
| `SMTP_FROM_ADDRESS` | - | Email address used as sender address | yes |
| `SMTP_ENCRYPTION` | - | `SSL` and `TSL` supported | yes |
| `SMTP_WITH_AUTH` | - | `0` or `1` | yes |
| `SMTP_USER` | - | Required if auth is enabled | yes |
| `SMTP_PASSWORD` | - | Required if auth is enabled | yes |
Required when email sending is wanted.

| NAME | DEFAULT VALUE | INFO | Web UI |
|:--------------------|:-------------:|:---------------------------------------------|:------:|
| `EMAIL_ENABLED` | `0` | Enable sending of emails for the application | yes |
| `SMTP_HOST` | - | | yes |
| `SMTP_PORT` | - | | yes |
| `SMTP_FROM_ADDRESS` | - | Email address used as sender address | yes |
| `SMTP_ENCRYPTION` | - | `SSL` and `TSL` supported | yes |
| `SMTP_WITH_AUTH` | - | `0` or `1` | yes |
| `SMTP_USER` | - | Required if auth is enabled | yes |
| `SMTP_PASSWORD` | - | Required if auth is enabled | yes |

### Logging

Expand Down
36 changes: 36 additions & 0 deletions public/js/password-reset.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
document.getElementById('updatePassword').addEventListener('click', async () => {
const newPassword = document.getElementById('newPassword').value

if (newPassword.length < 8) {
addAlert('alertPasswordResetDiv', 'Password is too short', 'danger', true, .7)

return
}
if (document.getElementById('repeatPassword').value !== newPassword) {
addAlert('alertPasswordResetDiv', 'Passwords not matching', 'danger', true, .7)
return
}

const response = await fetch('/password-reset', {
method: 'post',
headers: {
'Content-type': 'application/json',
},
body: JSON.stringify({
'newPassword': newPassword,
'token': document.getElementById('token').value
})
})

if (response.status === 400) {
addAlert('alertPasswordResetDiv', await response.text(), 'danger', true, .7)
return
}

if (response.ok === false) {
addAlert('alertPasswordResetDiv', 'Could not reset password', 'danger', true, .7)
return
}

window.location.href = '/'
});
Loading
Loading