Skip to content

Commit c745557

Browse files
committed
controllers::util: Move return statements into the condition branches
1 parent b6864fa commit c745557

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

src/controllers/util.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,14 @@ fn authenticate_user(req: &dyn RequestExt) -> AppResult<AuthenticatedUser> {
6262
let session = req.session();
6363
let user_id_from_session = session.get("user_id").and_then(|s| s.parse::<i32>().ok());
6464

65-
let (user, token_id) = if let Some(id) = user_id_from_session {
65+
if let Some(id) = user_id_from_session {
6666
let user = User::find(&conn, id)
6767
.chain_error(|| internal("user_id from cookie not found in database"))?;
6868

69-
(user, None)
69+
return Ok(AuthenticatedUser {
70+
user,
71+
token_id: None,
72+
});
7073
} else {
7174
// Otherwise, look for an `Authorization` header on the request
7275
let maybe_authorization = req
@@ -86,14 +89,15 @@ fn authenticate_user(req: &dyn RequestExt) -> AppResult<AuthenticatedUser> {
8689
let user = User::find(&conn, token.user_id)
8790
.chain_error(|| internal("user_id from token not found in database"))?;
8891

89-
(user, Some(token.id))
92+
return Ok(AuthenticatedUser {
93+
user,
94+
token_id: Some(token.id),
95+
});
9096
} else {
9197
// Unable to authenticate the user
9298
return Err(internal("no cookie session or auth header found")).chain_error(forbidden);
9399
}
94-
};
95-
96-
Ok(AuthenticatedUser { user, token_id })
100+
}
97101
}
98102

99103
impl<'a> UserAuthenticationExt for dyn RequestExt + 'a {

0 commit comments

Comments
 (0)