@@ -27,7 +27,25 @@ impl AuthCheck {
27
27
}
28
28
29
29
pub fn check ( & self , request : & dyn RequestExt ) -> AppResult < AuthenticatedUser > {
30
- let auth = request. authenticate ( ) ?;
30
+ controllers:: util:: verify_origin ( request) ?;
31
+
32
+ let auth = authenticate_user ( request) ?;
33
+
34
+ if let Some ( reason) = & auth. user . account_lock_reason {
35
+ let still_locked = if let Some ( until) = auth. user . account_lock_until {
36
+ until > Utc :: now ( ) . naive_utc ( )
37
+ } else {
38
+ true
39
+ } ;
40
+ if still_locked {
41
+ return Err ( account_locked ( reason, auth. user . account_lock_until ) ) ;
42
+ }
43
+ }
44
+
45
+ log_request:: add_custom_metadata ( "uid" , auth. user_id ( ) ) ;
46
+ if let Some ( id) = auth. api_token_id ( ) {
47
+ log_request:: add_custom_metadata ( "tokenid" , id) ;
48
+ }
31
49
32
50
if !self . allow_token && auth. token_id . is_some ( ) {
33
51
let error_message = "API Token authentication was explicitly disallowed for this API" ;
@@ -101,37 +119,3 @@ fn authenticate_user(req: &dyn RequestExt) -> AppResult<AuthenticatedUser> {
101
119
// Unable to authenticate the user
102
120
return Err ( internal ( "no cookie session or auth header found" ) . chain ( forbidden ( ) ) ) ;
103
121
}
104
-
105
- pub trait UserAuthenticationExt {
106
- fn authenticate ( & self ) -> AppResult < AuthenticatedUser > ;
107
- }
108
-
109
- impl < ' a > UserAuthenticationExt for dyn RequestExt + ' a {
110
- /// Obtain `AuthenticatedUser` for the request or return an `Forbidden` error
111
- fn authenticate ( & self ) -> AppResult < AuthenticatedUser > {
112
- controllers:: util:: verify_origin ( self ) ?;
113
-
114
- let authenticated_user = authenticate_user ( self ) ?;
115
-
116
- if let Some ( reason) = & authenticated_user. user . account_lock_reason {
117
- let still_locked = if let Some ( until) = authenticated_user. user . account_lock_until {
118
- until > Utc :: now ( ) . naive_utc ( )
119
- } else {
120
- true
121
- } ;
122
- if still_locked {
123
- return Err ( account_locked (
124
- reason,
125
- authenticated_user. user . account_lock_until ,
126
- ) ) ;
127
- }
128
- }
129
-
130
- log_request:: add_custom_metadata ( "uid" , authenticated_user. user_id ( ) ) ;
131
- if let Some ( id) = authenticated_user. api_token_id ( ) {
132
- log_request:: add_custom_metadata ( "tokenid" , id) ;
133
- }
134
-
135
- Ok ( authenticated_user)
136
- }
137
- }
0 commit comments