mirror of
https://gitlab.com/comunic/comunicapiv2
synced 2024-11-22 13:29:22 +00:00
Can sign out user
This commit is contained in:
parent
6119d5d0ff
commit
e635802296
@ -41,6 +41,19 @@ export class AccountController {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Disconnect user
|
||||||
|
*
|
||||||
|
* @param handler
|
||||||
|
*/
|
||||||
|
public static async LogoutUser(handler: RequestHandler) {
|
||||||
|
|
||||||
|
await AccountHelper.DestroyUserTokens(handler.getClientInfo(),
|
||||||
|
handler.getUserId());
|
||||||
|
|
||||||
|
handler.success("User has been disconnected!");
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get current user ID
|
* Get current user ID
|
||||||
*
|
*
|
||||||
|
@ -28,6 +28,9 @@ export const Routes : Route[] = [
|
|||||||
// Account controller
|
// Account controller
|
||||||
{path: "/account/login", cb: AccountController.LoginUser, needLogin: false},
|
{path: "/account/login", cb: AccountController.LoginUser, needLogin: false},
|
||||||
{path: "/user/connectUSER", cb: AccountController.LoginUser, needLogin: false}, // Legacy
|
{path: "/user/connectUSER", cb: AccountController.LoginUser, needLogin: false}, // Legacy
|
||||||
|
|
||||||
|
{path: "/account/logout", cb: AccountController.LogoutUser},
|
||||||
|
{path: "/user/disconnectUSER", cb: AccountController.LogoutUser}, // Legacy
|
||||||
|
|
||||||
{path: "/account/id", cb: AccountController.CurrentUserID},
|
{path: "/account/id", cb: AccountController.CurrentUserID},
|
||||||
{path: "/user/getCurrentUserID", cb: AccountController.CurrentUserID}, // Legacy
|
{path: "/user/getCurrentUserID", cb: AccountController.CurrentUserID}, // Legacy
|
||||||
|
@ -107,6 +107,19 @@ export class AccountHelper {
|
|||||||
return Number(row.user_id);
|
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
|
* Crypt a password
|
||||||
*
|
*
|
||||||
|
@ -122,12 +122,43 @@ export class DatabaseHelper {
|
|||||||
*/
|
*/
|
||||||
static async InsertRow(table : string, values : any) : Promise<number> {
|
static async InsertRow(table : string, values : any) : Promise<number> {
|
||||||
return new Promise((resolve, reject) => {
|
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)
|
if(err)
|
||||||
reject(err);
|
reject(err);
|
||||||
|
else
|
||||||
resolve(results.insertId);
|
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();
|
||||||
|
});
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user