|
|
|
@ -14,7 +14,10 @@ use rocket::{get, options, post, put, routes, State}; |
|
|
|
use ruma_client_api::{ |
|
|
|
use ruma_client_api::{ |
|
|
|
error::{Error, ErrorKind}, |
|
|
|
error::{Error, ErrorKind}, |
|
|
|
r0::{ |
|
|
|
r0::{ |
|
|
|
account::register, |
|
|
|
account::{ |
|
|
|
|
|
|
|
register, AuthenticationFlow, UserInteractiveAuthenticationInfo, |
|
|
|
|
|
|
|
UserInteractiveAuthenticationResponse, |
|
|
|
|
|
|
|
}, |
|
|
|
alias::get_alias, |
|
|
|
alias::get_alias, |
|
|
|
filter::{self, create_filter, get_filter}, |
|
|
|
filter::{self, create_filter, get_filter}, |
|
|
|
keys::get_keys, |
|
|
|
keys::get_keys, |
|
|
|
@ -52,23 +55,19 @@ fn get_supported_versions_route() -> MatrixResult<get_supported_versions::Respon |
|
|
|
fn register_route( |
|
|
|
fn register_route( |
|
|
|
data: State<Data>, |
|
|
|
data: State<Data>, |
|
|
|
body: Ruma<register::Request>, |
|
|
|
body: Ruma<register::Request>, |
|
|
|
) -> MatrixResult<register::Response> { |
|
|
|
) -> MatrixResult<register::Response, UserInteractiveAuthenticationResponse> { |
|
|
|
/* |
|
|
|
|
|
|
|
if body.auth.is_none() { |
|
|
|
if body.auth.is_none() { |
|
|
|
return MatrixResult(Err(Error { |
|
|
|
return MatrixResult(Err(UserInteractiveAuthenticationResponse::AuthResponse( |
|
|
|
kind: ErrorKind::Unknown, |
|
|
|
UserInteractiveAuthenticationInfo { |
|
|
|
message: json!({ |
|
|
|
flows: vec![AuthenticationFlow { |
|
|
|
"flows": [ |
|
|
|
stages: vec!["m.login.dummy".to_owned()], |
|
|
|
{ "stages": [ "m.login.dummy" ] }, |
|
|
|
}], |
|
|
|
], |
|
|
|
completed: vec![], |
|
|
|
"params": {}, |
|
|
|
params: json!({}), |
|
|
|
"session": utils::random_string(SESSION_ID_LENGTH), |
|
|
|
session: Some(utils::random_string(SESSION_ID_LENGTH)), |
|
|
|
}) |
|
|
|
}, |
|
|
|
.to_string(), |
|
|
|
))); |
|
|
|
status_code: http::StatusCode::UNAUTHORIZED, |
|
|
|
|
|
|
|
})); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Validate user id
|
|
|
|
// Validate user id
|
|
|
|
let user_id: UserId = match (*format!( |
|
|
|
let user_id: UserId = match (*format!( |
|
|
|
@ -82,11 +81,13 @@ fn register_route( |
|
|
|
{ |
|
|
|
{ |
|
|
|
Err(_) => { |
|
|
|
Err(_) => { |
|
|
|
debug!("Username invalid"); |
|
|
|
debug!("Username invalid"); |
|
|
|
return MatrixResult(Err(Error { |
|
|
|
return MatrixResult(Err(UserInteractiveAuthenticationResponse::MatrixError( |
|
|
|
|
|
|
|
Error { |
|
|
|
kind: ErrorKind::InvalidUsername, |
|
|
|
kind: ErrorKind::InvalidUsername, |
|
|
|
message: "Username was invalid.".to_owned(), |
|
|
|
message: "Username was invalid.".to_owned(), |
|
|
|
status_code: http::StatusCode::BAD_REQUEST, |
|
|
|
status_code: http::StatusCode::BAD_REQUEST, |
|
|
|
})); |
|
|
|
}, |
|
|
|
|
|
|
|
))); |
|
|
|
} |
|
|
|
} |
|
|
|
Ok(user_id) => user_id, |
|
|
|
Ok(user_id) => user_id, |
|
|
|
}; |
|
|
|
}; |
|
|
|
@ -94,11 +95,13 @@ fn register_route( |
|
|
|
// Check if username is creative enough
|
|
|
|
// Check if username is creative enough
|
|
|
|
if data.user_exists(&user_id) { |
|
|
|
if data.user_exists(&user_id) { |
|
|
|
debug!("ID already taken"); |
|
|
|
debug!("ID already taken"); |
|
|
|
return MatrixResult(Err(Error { |
|
|
|
return MatrixResult(Err(UserInteractiveAuthenticationResponse::MatrixError( |
|
|
|
|
|
|
|
Error { |
|
|
|
kind: ErrorKind::UserInUse, |
|
|
|
kind: ErrorKind::UserInUse, |
|
|
|
message: "Desired user ID is already taken.".to_owned(), |
|
|
|
message: "Desired user ID is already taken.".to_owned(), |
|
|
|
status_code: http::StatusCode::BAD_REQUEST, |
|
|
|
status_code: http::StatusCode::BAD_REQUEST, |
|
|
|
})); |
|
|
|
}, |
|
|
|
|
|
|
|
))); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Create user
|
|
|
|
// Create user
|
|
|
|
@ -118,10 +121,9 @@ fn register_route( |
|
|
|
data.token_replace(&user_id, &device_id, token.clone()); |
|
|
|
data.token_replace(&user_id, &device_id, token.clone()); |
|
|
|
|
|
|
|
|
|
|
|
MatrixResult(Ok(register::Response { |
|
|
|
MatrixResult(Ok(register::Response { |
|
|
|
access_token: token, |
|
|
|
access_token: Some(token), |
|
|
|
home_server: data.hostname().to_owned(), |
|
|
|
|
|
|
|
user_id, |
|
|
|
user_id, |
|
|
|
device_id, |
|
|
|
device_id: Some(device_id), |
|
|
|
})) |
|
|
|
})) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|