Skip to content

Commit

Permalink
feat(modules): added auth_email_signup_user function
Browse files Browse the repository at this point in the history
  • Loading branch information
Luke Carr committed May 21, 2020
1 parent 9d2fc91 commit 3bb0e9d
Show file tree
Hide file tree
Showing 2 changed files with 101 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/modules/auth/email/index.ts
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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<SignUpUserResponse> {
return (await this.get("auth_email_signup_user", {
...user,
})) as SignUpUserResponse;
}
}
89 changes: 89 additions & 0 deletions src/modules/auth/email/sign-up-user.ts
Original file line number Diff line number Diff line change
@@ -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[];
}

0 comments on commit 3bb0e9d

Please sign in to comment.