1
0
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:
2019-12-30 13:44:54 +01:00
parent 48cb254b9b
commit 994d1540dc
5 changed files with 76 additions and 1 deletions

View File

@ -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
*

View File

@ -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