Skip to content

Commit 07ac7ca

Browse files
committed
rename Login:EMAIL to Login::Email + remove use of email prefix
1 parent aa466bd commit 07ac7ca

File tree

3 files changed

+14
-15
lines changed

3 files changed

+14
-15
lines changed

crates/data-model/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ rand.workspace = true
2424
regex = "1.11.1"
2525
woothee = "0.13.0"
2626
ruma-common.workspace = true
27+
lettre.workspace = true
2728

2829
mas-iana.workspace = true
2930
mas-jose.workspace = true
3031
oauth2-types.workspace = true
31-
# Emails
32-
lettre.workspace = true
32+

crates/data-model/src/oauth2/authorization_grant.rs

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ impl AuthorizationGrantStage {
144144

145145
pub enum LoginHint<'a> {
146146
MXID(&'a UserId),
147-
EMAIL(lettre::Address),
147+
Email(lettre::Address),
148148
None,
149149
}
150150

@@ -183,6 +183,15 @@ impl AuthorizationGrant {
183183

184184
// Return none if the format is incorrect
185185
let Some((prefix, value)) = login_hint.split_once(':') else {
186+
// If email supports for login_hint supports is enabled
187+
if login_with_email_allowed {
188+
// Validate the email
189+
let Ok(address) = lettre::Address::from_str(login_hint) else {
190+
return LoginHint::None;
191+
};
192+
return LoginHint::Email(address);
193+
}
194+
// Unknown hint type, treat as none
186195
return LoginHint::None;
187196
};
188197

@@ -200,16 +209,6 @@ impl AuthorizationGrant {
200209

201210
LoginHint::MXID(mxid)
202211
}
203-
"email" => {
204-
if !login_with_email_allowed {
205-
return LoginHint::None;
206-
}
207-
// Validate the email
208-
let Ok(address) = lettre::Address::from_str(value) else {
209-
return LoginHint::None;
210-
};
211-
LoginHint::EMAIL(address)
212-
}
213212
// Unknown hint type, treat as none
214213
_ => LoginHint::None,
215214
}
@@ -339,7 +338,7 @@ mod tests {
339338

340339
let hint = grant.parse_login_hint("example.com", true);
341340

342-
assert!(matches!(hint, LoginHint::EMAIL(email) if email.to_string() == "example@user"));
341+
assert!(matches!(hint, LoginHint::Email(email) if email.to_string() == "example@user"));
343342
}
344343

345344
#[test]

crates/handlers/src/views/login.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ fn handle_login_hint(
385385
site_config.login_with_email_allowed,
386386
) {
387387
LoginHint::MXID(mxid) => Some(mxid.localpart().to_owned()),
388-
LoginHint::EMAIL(email) => Some(email.to_string()),
388+
LoginHint::Email(email) => Some(email.to_string()),
389389
LoginHint::None => None,
390390
};
391391
form_state.set_value(LoginFormField::Username, value);

0 commit comments

Comments
 (0)