Commit 51ef628 1 parent 8e179f4 commit 51ef628 Copy full SHA for 51ef628
File tree 3 files changed +29
-3
lines changed
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};
4
4
5
5
#[ derive( Debug , Parser ) ]
6
6
#[ command( version, about, long_about = None ) ]
7
- pub struct Args {
7
+ struct Args {
8
8
#[ command( subcommand) ]
9
9
command : Option < Commands > ,
10
10
}
11
11
12
12
#[ derive( Subcommand , Debug ) ]
13
- pub enum Commands {
13
+ enum Commands {
14
14
/// Run an internal job
15
15
#[ command( subcommand) ]
16
16
Job ( JobCommand ) ,
17
17
}
18
18
19
19
#[ derive( Debug , Subcommand ) ]
20
- pub enum JobCommand {
20
+ enum JobCommand {
21
21
/// Cleans up mod_downloads from more than 30 days ago
22
22
CleanupDownloads ,
23
23
/// Cleans up auth and refresh tokens that are expired
24
24
CleanupTokens ,
25
+ /// Emergency logout for a developer
26
+ LogoutDeveloper {
27
+ /// Username of the developer
28
+ username : String ,
29
+ } ,
25
30
/// Runs migrations
26
31
Migrate ,
27
32
}
@@ -44,6 +49,12 @@ pub async fn maybe_cli(data: &AppData) -> anyhow::Result<bool> {
44
49
45
50
Ok ( true )
46
51
}
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
+ }
47
58
JobCommand :: CleanupTokens => {
48
59
let mut conn = data. db ( ) . acquire ( ) . await ?;
49
60
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 1
1
pub mod cleanup_downloads;
2
+ pub mod logout_user;
2
3
pub mod migrate;
3
4
pub mod token_cleanup;
You can’t perform that action at this time.
0 commit comments