Skip to content

Commit 52bb16b

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

File tree

3 files changed

+20
-23
lines changed

3 files changed

+20
-23
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: 17 additions & 20 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

@@ -186,32 +186,29 @@ impl AuthorizationGrant {
186186
return LoginHint::None;
187187
};
188188

189-
match prefix {
190-
"mxid" => {
191-
// Instead of erroring just return none
192-
let Ok(mxid) = <&UserId>::try_from(value) else {
193-
return LoginHint::None;
194-
};
195-
196-
// Only handle MXIDs for current homeserver
197-
if mxid.server_name() != homeserver {
198-
return LoginHint::None;
199-
}
189+
if prefix == "mxid" {
190+
// Instead of erroring just return none
191+
let Ok(mxid) = <&UserId>::try_from(value) else {
192+
return LoginHint::None;
193+
};
200194

201-
LoginHint::MXID(mxid)
195+
// Only handle MXIDs for current homeserver
196+
if mxid.server_name() != homeserver {
197+
return LoginHint::None;
202198
}
203-
"email" => {
204-
if !login_with_email_allowed {
205-
return LoginHint::None;
206-
}
199+
200+
LoginHint::MXID(mxid)
201+
} else {
202+
// If email supports for login_hint supports is enabled
203+
if login_with_email_allowed {
207204
// Validate the email
208205
let Ok(address) = lettre::Address::from_str(value) else {
209206
return LoginHint::None;
210207
};
211-
LoginHint::EMAIL(address)
208+
return LoginHint::Email(address);
212209
}
213210
// Unknown hint type, treat as none
214-
_ => LoginHint::None,
211+
LoginHint::None
215212
}
216213
}
217214

@@ -339,7 +336,7 @@ mod tests {
339336

340337
let hint = grant.parse_login_hint("example.com", true);
341338

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

345342
#[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)