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

New endpoint to change users' passwords #45

Merged
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
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions src/modes/rest/resources/torrent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ type UploadTorrentParams = {
category: string
description: string
tags: Array<number>
// eslint-disable-next-line @typescript-eslint/no-explicit-any
file: any
}

Expand Down Expand Up @@ -102,6 +103,7 @@ export class TorrentResource implements IRestResource {
}

async deleteTorrent(infoHash: string): Promise<DeleteTorrentResponseData> {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
return await fetchDelete<any, DeleteTorrentResponse>(
`${this.client.apiBaseUrl}/torrent/${infoHash}`,
{},
Expand Down
23 changes: 23 additions & 0 deletions src/modes/rest/resources/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ type RegisterUserParams = {
confirm_password: string
}

type ChangePasswordParams = {
current_password: string
password: string
confirm_password: string
}

type Token = {
token: string
}
Expand Down Expand Up @@ -89,4 +95,21 @@ export class UserResource implements IRestResource {
return Promise.reject(err.response?.data?.error ?? err);
});
}

async changePassword(params: ChangePasswordParams, username: string): Promise<boolean> {
return await fetchPost<void>(
`${this.client.apiBaseUrl}/user/${username}/change-password`,
JSON.stringify(params),
{
"Authorization": `Bearer ${this.client.authToken}`,
"Content-Type": "application/json"
}
)
.then(() => {
return Promise.resolve(true);
})
.catch((err) => {
return Promise.reject(err.response?.data?.error ?? err);
});
}
}