@@ -144,7 +144,7 @@ impl AuthorizationGrantStage {
144144
145145pub  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        } 
@@ -333,13 +332,13 @@ mod tests {
333332        let  now = Utc :: now ( ) ; 
334333
335334        let  grant = AuthorizationGrant  { 
336-             login_hint :  Some ( String :: from ( "email: example@user" ) ) , 
335+             login_hint :  Some ( String :: from ( "example@user" ) ) , 
337336            ..AuthorizationGrant :: sample ( now,  & mut  rng) 
338337        } ; 
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]  
@@ -351,7 +350,7 @@ mod tests {
351350        let  now = Utc :: now ( ) ; 
352351
353352        let  grant = AuthorizationGrant  { 
354-             login_hint :  Some ( String :: from ( "email: example@user" ) ) , 
353+             login_hint :  Some ( String :: from ( "example@user" ) ) , 
355354            ..AuthorizationGrant :: sample ( now,  & mut  rng) 
356355        } ; 
357356
0 commit comments