1
0
mirror of https://gitlab.com/comunic/comunicapiv2 synced 2024-11-22 05:19:22 +00:00

Start delete group method

This commit is contained in:
Pierre HUBERT 2019-12-27 18:49:40 +01:00
parent 2222873d69
commit 820b861ef8
4 changed files with 49 additions and 0 deletions

View File

@ -552,6 +552,20 @@ export class GroupsController {
h.success("Follow status has been successfully updated!");
}
/**
* Delete a group
*
* @param h Request handler
*/
public static async DeleteGroup(h: RequestHandler) {
const groupID = await h.postGroupIDWithAccess("groupID", GroupsAccessLevel.ADMIN_ACCESS);
await h.needUserPostPassword("password");
// TODO : implement method
h.error(500, "Method not implemented yet!");
}
/**
* Turn a GroupInfo object into a valid API object
*

View File

@ -128,4 +128,6 @@ export const Routes : Route[] = [
{path: "/groups/remove_membership", cb: (h) => GroupsController.RemoveMembership(h)},
{path: "/groups/set_following", cb: (h) => GroupsController.SetFollowing(h)},
{path: "/groups/delete", cb: (h) => GroupsController.DeleteGroup(h)},
]

View File

@ -374,6 +374,19 @@ export class RequestHandler {
this.error(412, "Please check your login tokens!");
}
/**
* Check the user password included in the request
*
* @param postField The name of the post field
* containing user password
*/
public async needUserPostPassword(postField: string) {
const password = this.postString(postField, 3);
if(!await AccountHelper.CheckUserPassword(this.getUserId(), password))
this.error(401, "Invalid password!");
}
/**
* Get information about API client
*/

View File

@ -121,6 +121,26 @@ export class AccountHelper {
});
}
/**
* Check out whether the password of a user is valid
* or not
*
* @param userID Target user ID
* @param password Target password
*/
public static async CheckUserPassword(userID: number, password: string) : Promise<boolean> {
const crypt_pass = this.CryptPassword(password);
return await DatabaseHelper.Count({
table: USER_TABLE,
where: {
ID: userID,
password: crypt_pass
}
}) > 0;
}
/**
* Crypt a password
*