Skip to content

Commit

Permalink
Merge #45: New endpoint to change users' passwords
Browse files Browse the repository at this point in the history
e762ab6 feat: [#44] new endpoint to change users passwords (Jose Celano)

Pull request description:

  Depends on: #45

  New endpoint to change users' passwords.

ACKs for top commit:
  josecelano:
    ACK e762ab6

Tree-SHA512: a0454daedcff3d606fe1d2c193028188509f3df24bbb873040b225f3496fff9f01dcbe77731da87d938b523423d3b2cf26f5133539c0382ff524864492e08dd3
  • Loading branch information
josecelano committed Jun 4, 2024
2 parents 44c7c58 + e762ab6 commit 6a30452
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
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);
});
}
}

0 comments on commit 6a30452

Please sign in to comment.