1
0
mirror of https://gitlab.com/comunic/comunicapiv3 synced 2024-11-26 15:29:21 +00:00

Can disconnect a user from all its devices

This commit is contained in:
Pierre HUBERT 2020-07-13 11:56:49 +02:00
parent ee5f9bedc3
commit c2c6a24b29
3 changed files with 15 additions and 0 deletions

View File

@ -41,6 +41,13 @@ pub fn logout_user(request: &mut HttpRequestHandler) -> RequestResult {
request.success("User disconnected.")
}
/// Disconnect a user from all his devices
pub fn disconnect_all_devices(r: &mut HttpRequestHandler) -> RequestResult {
account_helper::destroy_all_user_tokens(r.user_id_ref()?)?;
r.success("Successfully disconnected!")
}
/// Get current user ID
pub fn user_id(request: &mut HttpRequestHandler) -> RequestResult {
request.set_response(CurrentUserID::new(&request.user_id()?))

View File

@ -71,6 +71,7 @@ pub fn get_routes() -> Vec<Route> {
Route::post_without_login("/user/connectUSER", Box::new(account_controller::login_user)),
Route::post("/account/logout", Box::new(account_controller::logout_user)),
Route::post("/user/disconnectUSER", Box::new(account_controller::logout_user)),
Route::post("/account/disconnect_all_devices", Box::new(account_controller::disconnect_all_devices)),
Route::post("/account/id", Box::new(account_controller::user_id)),
Route::post("/user/getCurrentUserID", Box::new(account_controller::user_id)),

View File

@ -87,6 +87,13 @@ pub fn destroy_login_tokens(id: &UserID, client: &APIClient) -> ResultBoxError<(
Ok(())
}
/// Destroy all login tokens of a user
pub fn destroy_all_user_tokens(id: &UserID) -> ResultBoxError {
database::DeleteQuery::new(USER_ACCESS_TOKENS_TABLE)
.cond_user_id("user_id", id)
.exec()
}
/// Check out whether a virtual directory is taken by a user or not
pub fn check_user_directory_availability(dir: &str, user_id: Option<UserID>) -> ResultBoxError<bool> {
let found_user = user_helper::find_user_by_virtual_directory(dir);