1
0
mirror of https://gitlab.com/comunic/comunicapiv2 synced 2025-06-20 08:35:17 +00:00

Can sign out user

This commit is contained in:
2019-11-23 14:03:14 +01:00
parent 6119d5d0ff
commit e635802296
4 changed files with 63 additions and 3 deletions

View File

@ -107,6 +107,19 @@ export class AccountHelper {
return Number(row.user_id);
}
/**
* Destroy user tokens
*
* @param client Information about the client
* @param userID Target user ID
*/
public static async DestroyUserTokens(client: APIClient, userID: number) {
return DatabaseHelper.DeleteRows(USERS_TOKENS_TABLE, {
service_id: client.id,
user_id: userID
});
}
/**
* Crypt a password
*

View File

@ -122,12 +122,43 @@ export class DatabaseHelper {
*/
static async InsertRow(table : string, values : any) : Promise<number> {
return new Promise((resolve, reject) => {
this.connection.query("INSERT INTO " + table + " SET ?", values, (err, results, fields) => {
this.connection.query("INSERT INTO " + table + " SET ?", values, (err, results, f) => {
if(err)
reject(err);
resolve(results.insertId);
else
resolve(results.insertId);
});
});
}
/**
* Delete entries from a table
*
* @param table Target table
* @param where Where arguments
*/
static async DeleteRows(table: string, where: any) {
let whereArgs = "";
let args = [];
// Process conditions
for (const key in where) {
if (where.hasOwnProperty(key)) {
const value = where[key];
whereArgs += (whereArgs == "" ? "" : " AND ") + key + " = ?";
args.push(value);
}
}
if(whereArgs == "")
throw Error("Error : table could accidentally get purged!");
return new Promise((resolve, reject) => {
this.connection.query("DELETE FROM " + table + " WHERE " + whereArgs, args, (err, r, f) => {
if(err) reject(err)
else resolve();
});
})
}
}