add registration_token in default cfg and DEPLOY #982
3 changed files with 39 additions and 18 deletions
|
@ -171,6 +171,11 @@ max_request_size = 20_000_000 # in bytes
|
||||||
# Enables registration. If set to false, no users can register on this server.
|
# Enables registration. If set to false, no users can register on this server.
|
||||||
allow_registration = true
|
allow_registration = true
|
||||||
|
|
||||||
|
# A static registration token that new users will have to provide when creating
|
||||||
|
# an account. If unset and `allow_registration` is true, registration is open
|
||||||
|
# without any condition. YOU NEED TO EDIT THIS
|
||||||
|
registration_token = "change this token for something specific to your server"
|
||||||
|
|
||||||
allow_federation = true
|
allow_federation = true
|
||||||
allow_check_for_updates = true
|
allow_check_for_updates = true
|
||||||
|
|
||||||
|
|
|
@ -38,6 +38,11 @@ max_request_size = 20_000_000 # in bytes
|
||||||
# Enables registration. If set to false, no users can register on this server.
|
# Enables registration. If set to false, no users can register on this server.
|
||||||
allow_registration = true
|
allow_registration = true
|
||||||
|
|
||||||
|
# A static registration token that new users will have to provide when creating
|
||||||
|
# an account. If unset and `allow_registration` is true, registration is open
|
||||||
|
# without any condition. YOU NEED TO EDIT THIS
|
||||||
|
registration_token = "change this token for something specific to your server"
|
||||||
|
|
||||||
allow_federation = true
|
allow_federation = true
|
||||||
allow_check_for_updates = true
|
allow_check_for_updates = true
|
||||||
|
|
||||||
|
|
|
@ -74,10 +74,7 @@ pub async fn get_register_available_route(
|
||||||
/// - Creates a new account and populates it with default account data
|
/// - Creates a new account and populates it with default account data
|
||||||
/// - If `inhibit_login` is false: Creates a device and returns device id and access_token
|
/// - If `inhibit_login` is false: Creates a device and returns device id and access_token
|
||||||
pub async fn register_route(body: Ruma<register::v3::Request>) -> Result<register::v3::Response> {
|
pub async fn register_route(body: Ruma<register::v3::Request>) -> Result<register::v3::Response> {
|
||||||
if !services().globals.allow_registration()
|
if !services().globals.allow_registration() && !body.from_appservice {
|
||||||
&& !body.from_appservice
|
|
||||||
&& services().globals.config.registration_token.is_none()
|
|
||||||
{
|
|
||||||
return Err(Error::BadRequest(
|
return Err(Error::BadRequest(
|
||||||
ErrorKind::Forbidden,
|
ErrorKind::Forbidden,
|
||||||
"Registration has been disabled.",
|
"Registration has been disabled.",
|
||||||
|
@ -122,21 +119,35 @@ pub async fn register_route(body: Ruma<register::v3::Request>) -> Result<registe
|
||||||
};
|
};
|
||||||
|
|
||||||
// UIAA
|
// UIAA
|
||||||
let mut uiaainfo = UiaaInfo {
|
let mut uiaainfo;
|
||||||
|
let skip_auth;
|
||||||
|
if services().globals.config.registration_token.is_some() {
|
||||||
|
// Registration token required
|
||||||
|
uiaainfo = UiaaInfo {
|
||||||
flows: vec![AuthFlow {
|
flows: vec![AuthFlow {
|
||||||
stages: if services().globals.config.registration_token.is_some() {
|
stages: vec![AuthType::RegistrationToken],
|
||||||
vec![AuthType::RegistrationToken]
|
|
||||||
} else {
|
|
||||||
vec![AuthType::Dummy]
|
|
||||||
},
|
|
||||||
}],
|
}],
|
||||||
completed: Vec::new(),
|
completed: Vec::new(),
|
||||||
params: Default::default(),
|
params: Default::default(),
|
||||||
session: None,
|
session: None,
|
||||||
auth_error: None,
|
auth_error: None,
|
||||||
};
|
};
|
||||||
|
skip_auth = body.from_appservice;
|
||||||
|
} else {
|
||||||
|
// No registration token necessary, but clients must still go through the flow
|
||||||
|
uiaainfo = UiaaInfo {
|
||||||
|
flows: vec![AuthFlow {
|
||||||
|
stages: vec![AuthType::Dummy],
|
||||||
|
}],
|
||||||
|
completed: Vec::new(),
|
||||||
|
params: Default::default(),
|
||||||
|
session: None,
|
||||||
|
auth_error: None,
|
||||||
|
};
|
||||||
|
skip_auth = body.from_appservice || is_guest;
|
||||||
|
}
|
||||||
|
|
||||||
if !body.from_appservice && !is_guest {
|
if !skip_auth {
|
||||||
if let Some(auth) = &body.auth {
|
if let Some(auth) = &body.auth {
|
||||||
let (worked, uiaainfo) = services().uiaa.try_auth(
|
let (worked, uiaainfo) = services().uiaa.try_auth(
|
||||||
&UserId::parse_with_server_name("", services().globals.server_name())
|
&UserId::parse_with_server_name("", services().globals.server_name())
|
||||||
|
|
Loading…
Reference in a new issue