mirror of
https://gitlab.com/comunic/comunicapiv2
synced 2025-06-21 09:05:17 +00:00
Can create a new account
This commit is contained in:
@ -1,6 +1,8 @@
|
||||
import { RequestHandler } from "../entities/RequestHandler";
|
||||
import { AccountHelper } from "../helpers/AccountHelper";
|
||||
import { UserHelper } from "../helpers/UserHelper";
|
||||
import { NewAccount } from "../entities/NewAccount";
|
||||
import { removeHTMLNodes } from "../utils/StringUtils";
|
||||
|
||||
/**
|
||||
* Account controller
|
||||
@ -10,6 +12,35 @@ import { UserHelper } from "../helpers/UserHelper";
|
||||
|
||||
export class AccountController {
|
||||
|
||||
/**
|
||||
* Create a new account
|
||||
*
|
||||
* @param h Request handler
|
||||
*/
|
||||
public static async Create(h: RequestHandler) {
|
||||
// TODO : add API limit
|
||||
|
||||
// Get & check email address
|
||||
const email = h.postEmail("emailAddress");
|
||||
if(await AccountHelper.ExistsEmail(email))
|
||||
h.error(409, "This email address already belongs to an account!");
|
||||
|
||||
const newAccount = <NewAccount>{
|
||||
firstName: removeHTMLNodes(h.postString("firstName")),
|
||||
lastName: removeHTMLNodes(h.postString("lastName")),
|
||||
email: email,
|
||||
password: h.postString("password", 3)
|
||||
};
|
||||
|
||||
// Try to create the account
|
||||
await AccountHelper.Create(newAccount);
|
||||
|
||||
// TODO : trigger the API limit
|
||||
|
||||
// Success
|
||||
h.success("The account has been created!");
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempt to login user
|
||||
*
|
||||
|
@ -34,6 +34,8 @@ export const Routes : Route[] = [
|
||||
{type: RouteType.GET, path: "/", cb: WelcomeController.HomeMessage, needLogin: false},
|
||||
|
||||
// Account controller
|
||||
{path: "/account/create", cb: (h) => AccountController.Create(h), needLogin: false},
|
||||
|
||||
{path: "/account/login", cb: (h) => AccountController.LoginUser(h), needLogin: false},
|
||||
{path: "/user/connectUSER", cb: (h) => AccountController.LoginUser(h), needLogin: false}, // Legacy
|
||||
|
||||
|
Reference in New Issue
Block a user