@@ -12,6 +12,7 @@ use axum_extra::TypedHeader;
12
12
use chrono:: Duration ;
13
13
use mas_axum_utils:: { cookies:: CookieJar , FancyError , SessionInfoExt as _} ;
14
14
use mas_data_model:: UserAgent ;
15
+ use mas_matrix:: BoxHomeserverConnection ;
15
16
use mas_router:: { PostAuthAction , UrlBuilder } ;
16
17
use mas_storage:: {
17
18
queue:: { ProvisionUserJob , QueueJobRepositoryExt as _} ,
@@ -36,6 +37,7 @@ pub(crate) async fn get(
36
37
activity_tracker : BoundActivityTracker ,
37
38
user_agent : Option < TypedHeader < headers:: UserAgent > > ,
38
39
State ( url_builder) : State < UrlBuilder > ,
40
+ homeserver : BoxHomeserverConnection ,
39
41
cookie_jar : CookieJar ,
40
42
Path ( id) : Path < Ulid > ,
41
43
) -> Result < impl IntoResponse , FancyError > {
@@ -72,6 +74,7 @@ pub(crate) async fn get(
72
74
// Check that this registration belongs to this browser
73
75
let registrations = UserRegistrationSessions :: load ( & cookie_jar) ;
74
76
if !registrations. contains ( & registration) {
77
+ // XXX: we should have a better error screen here
75
78
return Err ( FancyError :: from ( anyhow:: anyhow!(
76
79
"Could not find the registration in the browser cookies"
77
80
) ) ) ;
@@ -82,12 +85,21 @@ pub(crate) async fn get(
82
85
// address
83
86
84
87
if repo. user ( ) . exists ( & registration. username ) . await ? {
88
+ // XXX: this could have a better error message, but as this is unlikely to
89
+ // happen, we're fine with a vague message for now
85
90
return Err ( FancyError :: from ( anyhow:: anyhow!(
86
91
"Username is already taken"
87
92
) ) ) ;
88
93
}
89
94
90
- // TODO: query the homeserver
95
+ if !homeserver
96
+ . is_localpart_available ( & registration. username )
97
+ . await ?
98
+ {
99
+ return Err ( FancyError :: from ( anyhow:: anyhow!(
100
+ "Username is not available"
101
+ ) ) ) ;
102
+ }
91
103
92
104
// For now, we require an email address on the registration, but this might
93
105
// change in the future
@@ -115,6 +127,8 @@ pub(crate) async fn get(
115
127
. await ?
116
128
> 0
117
129
{
130
+ // XXX: this could have a better error message, but as this is unlikely to
131
+ // happen, we're fine with a vague message for now
118
132
return Err ( FancyError :: from ( anyhow:: anyhow!(
119
133
"Email address is already used"
120
134
) ) ) ;
0 commit comments