Skip to content

Commit b0c949d

Browse files
committed
auth: Rename AuthenticatedUser and related structs
1 parent c4b9fce commit b0c949d

File tree

2 files changed

+15
-15
lines changed

2 files changed

+15
-15
lines changed

src/auth.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ impl AuthCheck {
5454
}
5555
}
5656

57-
pub fn check<B>(&self, request: &Request<B>) -> AppResult<AuthenticatedUser> {
57+
pub fn check<B>(&self, request: &Request<B>) -> AppResult<Authentication> {
5858
let auth = authenticate_user(request)?;
5959

6060
if let Some(token) = auth.api_token() {
@@ -111,23 +111,23 @@ impl AuthCheck {
111111
}
112112

113113
#[derive(Debug)]
114-
pub enum AuthenticatedUser {
115-
Cookie(CookieUser),
116-
Token(TokenUser),
114+
pub enum Authentication {
115+
Cookie(CookieAuthentication),
116+
Token(TokenAuthentication),
117117
}
118118

119119
#[derive(Debug)]
120-
pub struct CookieUser {
120+
pub struct CookieAuthentication {
121121
user: User,
122122
}
123123

124124
#[derive(Debug)]
125-
pub struct TokenUser {
125+
pub struct TokenAuthentication {
126126
token: ApiToken,
127127
user: User,
128128
}
129129

130-
impl AuthenticatedUser {
130+
impl Authentication {
131131
pub fn user_id(&self) -> i32 {
132132
self.user().id
133133
}
@@ -138,20 +138,20 @@ impl AuthenticatedUser {
138138

139139
pub fn api_token(&self) -> Option<&ApiToken> {
140140
match self {
141-
AuthenticatedUser::Token(token) => Some(&token.token),
141+
Authentication::Token(token) => Some(&token.token),
142142
_ => None,
143143
}
144144
}
145145

146146
pub fn user(&self) -> &User {
147147
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,
150150
}
151151
}
152152
}
153153

154-
fn authenticate_user<B>(req: &Request<B>) -> AppResult<AuthenticatedUser> {
154+
fn authenticate_user<B>(req: &Request<B>) -> AppResult<Authentication> {
155155
controllers::util::verify_origin(req)?;
156156

157157
let conn = req.app().db_write()?;
@@ -168,7 +168,7 @@ fn authenticate_user<B>(req: &Request<B>) -> AppResult<AuthenticatedUser> {
168168

169169
req.add_custom_metadata("uid", id);
170170

171-
return Ok(AuthenticatedUser::Cookie(CookieUser { user }));
171+
return Ok(Authentication::Cookie(CookieAuthentication { user }));
172172
}
173173

174174
// Otherwise, look for an `Authorization` header on the request
@@ -194,7 +194,7 @@ fn authenticate_user<B>(req: &Request<B>) -> AppResult<AuthenticatedUser> {
194194
req.add_custom_metadata("uid", token.user_id);
195195
req.add_custom_metadata("tokenid", token.id);
196196

197-
return Ok(AuthenticatedUser::Token(TokenUser { user, token }));
197+
return Ok(Authentication::Token(TokenAuthentication { user, token }));
198198
}
199199

200200
// Unable to authenticate the user

src/controllers/crate_owner_invitation.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use super::frontend_prelude::*;
22

33
use crate::auth::AuthCheck;
4-
use crate::auth::AuthenticatedUser;
4+
use crate::auth::Authentication;
55
use crate::controllers::helpers::pagination::{Page, PaginationOptions};
66
use crate::models::{Crate, CrateOwnerInvitation, Rights, User};
77
use crate::schema::{crate_owner_invitations, crates, users};
@@ -80,7 +80,7 @@ enum ListFilter {
8080

8181
fn prepare_list<B>(
8282
req: &Request<B>,
83-
auth: AuthenticatedUser,
83+
auth: Authentication,
8484
filter: ListFilter,
8585
) -> AppResult<PrivateListResponse> {
8686
let pagination: PaginationOptions = PaginationOptions::builder()

0 commit comments

Comments
 (0)