From 3bb0e9db7ab8dfdea011a098b0debec5b995b638 Mon Sep 17 00:00:00 2001 From: Luke Carr Date: Thu, 21 May 2020 18:07:13 +0100 Subject: [PATCH] feat(modules): added auth_email_signup_user function --- src/modules/auth/email/index.ts | 12 ++++ src/modules/auth/email/sign-up-user.ts | 89 ++++++++++++++++++++++++++ 2 files changed, 101 insertions(+) create mode 100644 src/modules/auth/email/sign-up-user.ts diff --git a/src/modules/auth/email/index.ts b/src/modules/auth/email/index.ts index 8a21c40..8897270 100644 --- a/src/modules/auth/email/index.ts +++ b/src/modules/auth/email/index.ts @@ -1,5 +1,6 @@ import Module from "../.."; import { SignUpSettingsResponse } from "./sign-up-settings"; +import { SignUpUser, SignUpUserResponse } from "./sign-up-user"; /** * Functions relating to Moodle's email-based self-registration. @@ -15,4 +16,15 @@ export default class AuthEmailModule extends Module { "auth_email_get_signup_settings" )) as SignUpSettingsResponse; } + + /** + * Adds a new user to the site (pending user confirmation). + * + * @param user The user to sign up. + */ + public async signUpUser(user: SignUpUser): Promise { + return (await this.get("auth_email_signup_user", { + ...user, + })) as SignUpUserResponse; + } } diff --git a/src/modules/auth/email/sign-up-user.ts b/src/modules/auth/email/sign-up-user.ts new file mode 100644 index 0000000..a8dc8c0 --- /dev/null +++ b/src/modules/auth/email/sign-up-user.ts @@ -0,0 +1,89 @@ +import { Warning } from "../../shared"; +import { FunctionResponse } from "../../../functions"; + +interface ProfileField { + /** + * The field's type. + */ + type: string; + + /** + * The field's name. + */ + name: string; + + /** + * The field's value. + */ + value: string; +} + +export interface SignUpUser { + /** + * The user's username. + */ + username: string; + + /** + * The user's password (in plain text). + */ + password: string; + + /** + * The user's first name(s). + */ + firstname: string; + + /** + * The user's last/family name. + */ + lastname: string; + + /** + * The user's email address. This should + * be unique (not in use by an existing + * user). + */ + email: string; + + /** + * The user's home city. + */ + city?: string; + + /** + * The user's home country code. + */ + country?: string; + + /** + * The Google reCAPTCHA challenge hash. + */ + recaptchachallengehash?: string; + + /** + * The Google reCAPTCHA challenge response. + */ + recaptcharesponse?: string; + + /** + * The user's custom profile fields. + */ + customprofilefields?: ProfileField[]; + + /** + * The Moodle site URL to redirect the user + * to after confirmation. + */ + redirect?: string; +} + +export interface SignUpUserResponse extends FunctionResponse { + /** + * Whether the user was created (1) or + * not (0). + */ + success: number; + + warnings: Warning[]; +}