mirror of
				https://gitlab.com/comunic/comunicapiv2
				synced 2025-10-29 16:44:42 +00:00 
			
		
		
		
	Start delete group method
This commit is contained in:
		| @@ -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 | ||||
| 	 *  | ||||
|   | ||||
| @@ -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)}, | ||||
| ] | ||||
| @@ -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 | ||||
| 	 */ | ||||
|   | ||||
| @@ -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 | ||||
| 	 *  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user