Adding new TOTP generate and update methods. Fixes #191

This commit is contained in:
Dessalines 2023-09-27 10:44:10 -04:00
parent e270d67086
commit a0dba1f108
4 changed files with 36 additions and 2 deletions

0
copy_generated_types_from_lemmy.sh Normal file → Executable file
View file

View file

@ -129,6 +129,9 @@ import { UploadImage, UploadImageResponse, VERSION } from "./types/others";
import { HideCommunity } from "./types/HideCommunity";
import { BlockInstance } from "./types/BlockInstance";
import { BlockInstanceResponse } from "./types/BlockInstanceResponse";
import { GenerateTotpSecretResponse } from "./types/GenerateTotpSecretResponse";
import { UpdateTotp } from "./types/UpdateTotp";
import { UpdateTotpResponse } from "./types/UpdateTotpResponse";
enum HttpType {
Get = "GET",
@ -212,6 +215,38 @@ export class LemmyHttp {
);
}
/**
* Generate a TOTP / two-factor secret.
*
* Afterwards you need to call `/user/totp/update` with a valid token to enable it.
*
* `HTTP.POST /user/totp/generate`
*/
generateTotpSecret() {
return this.#wrapper<object, GenerateTotpSecretResponse>(
HttpType.Post,
"/user/totp/generate",
{},
);
}
/**
* Enable / Disable TOTP / two-factor authentication.
*
* To enable, you need to first call `/user/totp/generate` and then pass a valid token to this.
*
* Disabling is only possible if 2FA was previously enabled. Again it is necessary to pass a valid token.
*
* `HTTP.POST /user/totp/update`
*/
updateTotp(form: UpdateTotp) {
return this.#wrapper<object, UpdateTotpResponse>(
HttpType.Post,
"/user/totp/update",
form,
);
}
/**
* Get the modlog.
*

View file

@ -241,4 +241,4 @@ export { UpdateTotp } from "./types/UpdateTotp";
export { UpdateTotpResponse } from "./types/UpdateTotpResponse";
export { VerifyEmail } from "./types/VerifyEmail";
export { VerifyEmailResponse } from "./types/VerifyEmailResponse";
export { ImageFile, UploadImage, UploadImageResponse } from "./types/others";
export { UploadImage, UploadImageResponse, ImageFile } from "./types/others";

View file

@ -25,7 +25,6 @@ export interface SaveUserSettings {
show_read_posts?: boolean;
show_new_post_notifs?: boolean;
discussion_languages?: Array<LanguageId>;
generate_totp_2fa?: boolean;
open_links_in_new_tab?: boolean;
infinite_scroll_enabled?: boolean;
}