Add ability to kick users
parent
7963ce9199
commit
c665951b9d
36
src/auth.rs
36
src/auth.rs
|
@ -284,6 +284,27 @@ pub fn get_user(name: String) -> JsonValue {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Kick a user (temporarilly log them out for a certain amount of time)
|
||||||
|
fn kick(name: &str) -> JsonValue {
|
||||||
|
if let Some(mut user) = db_read_user(&name.to_lowercase()).ok().flatten() {
|
||||||
|
user.session_token = "NULL".to_string();
|
||||||
|
db_remove(&user);
|
||||||
|
db_add(&user);
|
||||||
|
info!("succesfully kicked user {}", &user.name);
|
||||||
|
return json!({
|
||||||
|
"status": "ok",
|
||||||
|
"reason": "kicked user",
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
warn!("could not kick {}, user not found", &name);
|
||||||
|
return json!({
|
||||||
|
"status": "fail",
|
||||||
|
"reason": "user not found",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/* User Management */
|
/* User Management */
|
||||||
#[post("/mod", format = "json", data = "<data>")]
|
#[post("/mod", format = "json", data = "<data>")]
|
||||||
pub fn moderation_actions(data: Json<ModerationAction>, mut cookies: Cookies) -> JsonValue {
|
pub fn moderation_actions(data: Json<ModerationAction>, mut cookies: Cookies) -> JsonValue {
|
||||||
|
@ -307,16 +328,13 @@ pub fn moderation_actions(data: Json<ModerationAction>, mut cookies: Cookies) ->
|
||||||
} else if user.session_token == token.value() { // if token matches
|
} else if user.session_token == token.value() { // if token matches
|
||||||
if user.role == UserType::Normal {
|
if user.role == UserType::Normal {
|
||||||
match data.action {
|
match data.action {
|
||||||
ModActions::Kick => {
|
ModActions::Kick => kick(&data.target),
|
||||||
info!("kicked user {}", data.target)
|
ModActions::Ban => return json!({"status":"ok","reason":"banned user"}),
|
||||||
},
|
ModActions::Demote => return json!({"status":"ok","reason":"demoted user"}),
|
||||||
ModActions::Ban => info!("banned user {}", data.target),
|
ModActions::Premote => return json!({"status":"ok","reason":"premoted user"}),
|
||||||
_ => info!("F"),
|
_ => return json!({"status":"fail","reason":"bad command"}),
|
||||||
};
|
};
|
||||||
return json!({
|
return json!({"status":"fail","reason":"idk"});
|
||||||
"status": "ok",
|
|
||||||
"reason": "completed action",
|
|
||||||
});
|
|
||||||
} else {
|
} else {
|
||||||
warn!("user does not have sufficient permissions to perform that action!");
|
warn!("user does not have sufficient permissions to perform that action!");
|
||||||
return json!({
|
return json!({
|
||||||
|
|
Loading…
Reference in New Issue