@@ -54,7 +54,7 @@ impl AuthCheck {
54
54
}
55
55
}
56
56
57
- pub fn check < B > ( & self , request : & Request < B > ) -> AppResult < AuthenticatedUser > {
57
+ pub fn check < B > ( & self , request : & Request < B > ) -> AppResult < Authentication > {
58
58
let auth = authenticate_user ( request) ?;
59
59
60
60
if let Some ( token) = auth. api_token ( ) {
@@ -111,23 +111,23 @@ impl AuthCheck {
111
111
}
112
112
113
113
#[ derive( Debug ) ]
114
- pub enum AuthenticatedUser {
115
- Cookie ( CookieUser ) ,
116
- Token ( TokenUser ) ,
114
+ pub enum Authentication {
115
+ Cookie ( CookieAuthentication ) ,
116
+ Token ( TokenAuthentication ) ,
117
117
}
118
118
119
119
#[ derive( Debug ) ]
120
- pub struct CookieUser {
120
+ pub struct CookieAuthentication {
121
121
user : User ,
122
122
}
123
123
124
124
#[ derive( Debug ) ]
125
- pub struct TokenUser {
125
+ pub struct TokenAuthentication {
126
126
token : ApiToken ,
127
127
user : User ,
128
128
}
129
129
130
- impl AuthenticatedUser {
130
+ impl Authentication {
131
131
pub fn user_id ( & self ) -> i32 {
132
132
self . user ( ) . id
133
133
}
@@ -138,20 +138,20 @@ impl AuthenticatedUser {
138
138
139
139
pub fn api_token ( & self ) -> Option < & ApiToken > {
140
140
match self {
141
- AuthenticatedUser :: Token ( token) => Some ( & token. token ) ,
141
+ Authentication :: Token ( token) => Some ( & token. token ) ,
142
142
_ => None ,
143
143
}
144
144
}
145
145
146
146
pub fn user ( & self ) -> & User {
147
147
match self {
148
- AuthenticatedUser :: Cookie ( cookie) => & cookie. user ,
149
- AuthenticatedUser :: Token ( token) => & token. user ,
148
+ Authentication :: Cookie ( cookie) => & cookie. user ,
149
+ Authentication :: Token ( token) => & token. user ,
150
150
}
151
151
}
152
152
}
153
153
154
- fn authenticate_user < B > ( req : & Request < B > ) -> AppResult < AuthenticatedUser > {
154
+ fn authenticate_user < B > ( req : & Request < B > ) -> AppResult < Authentication > {
155
155
controllers:: util:: verify_origin ( req) ?;
156
156
157
157
let conn = req. app ( ) . db_write ( ) ?;
@@ -168,7 +168,7 @@ fn authenticate_user<B>(req: &Request<B>) -> AppResult<AuthenticatedUser> {
168
168
169
169
req. add_custom_metadata ( "uid" , id) ;
170
170
171
- return Ok ( AuthenticatedUser :: Cookie ( CookieUser { user } ) ) ;
171
+ return Ok ( Authentication :: Cookie ( CookieAuthentication { user } ) ) ;
172
172
}
173
173
174
174
// Otherwise, look for an `Authorization` header on the request
@@ -194,7 +194,7 @@ fn authenticate_user<B>(req: &Request<B>) -> AppResult<AuthenticatedUser> {
194
194
req. add_custom_metadata ( "uid" , token. user_id ) ;
195
195
req. add_custom_metadata ( "tokenid" , token. id ) ;
196
196
197
- return Ok ( AuthenticatedUser :: Token ( TokenUser { user, token } ) ) ;
197
+ return Ok ( Authentication :: Token ( TokenAuthentication { user, token } ) ) ;
198
198
}
199
199
200
200
// Unable to authenticate the user
0 commit comments