File tree Expand file tree Collapse file tree 3 files changed +29
-3
lines changed
Expand file tree Collapse file tree 3 files changed +29
-3
lines changed Original file line number Diff line number Diff line change @@ -4,24 +4,29 @@ use clap::{Parser, Subcommand};
44
55#[ derive( Debug , Parser ) ]
66#[ command( version, about, long_about = None ) ]
7- pub struct Args {
7+ struct Args {
88 #[ command( subcommand) ]
99 command : Option < Commands > ,
1010}
1111
1212#[ derive( Subcommand , Debug ) ]
13- pub enum Commands {
13+ enum Commands {
1414 /// Run an internal job
1515 #[ command( subcommand) ]
1616 Job ( JobCommand ) ,
1717}
1818
1919#[ derive( Debug , Subcommand ) ]
20- pub enum JobCommand {
20+ enum JobCommand {
2121 /// Cleans up mod_downloads from more than 30 days ago
2222 CleanupDownloads ,
2323 /// Cleans up auth and refresh tokens that are expired
2424 CleanupTokens ,
25+ /// Emergency logout for a developer
26+ LogoutDeveloper {
27+ /// Username of the developer
28+ username : String ,
29+ } ,
2530 /// Runs migrations
2631 Migrate ,
2732}
@@ -44,6 +49,12 @@ pub async fn maybe_cli(data: &AppData) -> anyhow::Result<bool> {
4449
4550 Ok ( true )
4651 }
52+ JobCommand :: LogoutDeveloper { username } => {
53+ let mut conn = data. db ( ) . acquire ( ) . await ?;
54+ jobs:: logout_user:: logout_user ( & username, & mut * conn) . await ?;
55+
56+ Ok ( true )
57+ }
4758 JobCommand :: CleanupTokens => {
4859 let mut conn = data. db ( ) . acquire ( ) . await ?;
4960 jobs:: token_cleanup:: token_cleanup ( & mut * conn) . await ?;
Original file line number Diff line number Diff line change 1+ use crate :: database:: repository:: { auth_tokens, developers, refresh_tokens} ;
2+ use crate :: types:: api:: ApiError ;
3+ use sqlx:: PgConnection ;
4+
5+ pub async fn logout_user ( username : & str , conn : & mut PgConnection ) -> Result < ( ) , ApiError > {
6+ let dev = developers:: get_one_by_username ( username, conn)
7+ . await ?
8+ . ok_or ( ApiError :: NotFound ( "Developer not found" . into ( ) ) ) ?;
9+
10+ auth_tokens:: remove_developer_tokens ( dev. id , conn) . await ?;
11+ refresh_tokens:: remove_developer_tokens ( dev. id , conn) . await ?;
12+
13+ Ok ( ( ) )
14+ }
Original file line number Diff line number Diff line change 11pub mod cleanup_downloads;
2+ pub mod logout_user;
23pub mod migrate;
34pub mod token_cleanup;
You can’t perform that action at this time.
0 commit comments