feat: make it possible to automatically join user to a guild on registration
This commit is contained in:
parent
6eb47fdb36
commit
19f64d413c
2 changed files with 14 additions and 11 deletions
|
@ -12,17 +12,11 @@ use uuid::Uuid;
|
|||
|
||||
use super::Response;
|
||||
use crate::{
|
||||
Data,
|
||||
error::Error,
|
||||
schema::{
|
||||
access_tokens::{self, dsl as adsl},
|
||||
refresh_tokens::{self, dsl as rdsl},
|
||||
users::{self, dsl as udsl},
|
||||
},
|
||||
utils::{
|
||||
EMAIL_REGEX, PASSWORD_REGEX, USERNAME_REGEX, generate_token,
|
||||
new_refresh_token_cookie,
|
||||
},
|
||||
error::Error, objects::Member, schema::{
|
||||
access_tokens::{self, dsl as adsl}, refresh_tokens::{self, dsl as rdsl}, users::{self, dsl as udsl}
|
||||
}, utils::{
|
||||
generate_token, new_refresh_token_cookie, EMAIL_REGEX, PASSWORD_REGEX, USERNAME_REGEX
|
||||
}, Data
|
||||
};
|
||||
|
||||
#[derive(Deserialize)]
|
||||
|
@ -145,6 +139,10 @@ pub async fn res(
|
|||
.execute(&mut conn)
|
||||
.await?;
|
||||
|
||||
if let Some(initial_guild) = data.config.instance.initial_guild {
|
||||
Member::new(&data, uuid, initial_guild).await?;
|
||||
}
|
||||
|
||||
return Ok(HttpResponse::Ok()
|
||||
.cookie(new_refresh_token_cookie(&data.config, refresh_token))
|
||||
.json(Response { access_token }));
|
||||
|
|
|
@ -5,6 +5,7 @@ use log::debug;
|
|||
use serde::Deserialize;
|
||||
use tokio::fs::read_to_string;
|
||||
use url::Url;
|
||||
use uuid::Uuid;
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
pub struct ConfigBuilder {
|
||||
|
@ -48,6 +49,7 @@ struct InstanceBuilder {
|
|||
name: Option<String>,
|
||||
registration: Option<bool>,
|
||||
require_email_verification: Option<bool>,
|
||||
initial_guild: Option<Uuid>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
|
@ -119,11 +121,13 @@ impl ConfigBuilder {
|
|||
name: instance.name.unwrap_or("Gorb".to_string()),
|
||||
registration: instance.registration.unwrap_or(true),
|
||||
require_email_verification: instance.require_email_verification.unwrap_or(false),
|
||||
initial_guild: instance.initial_guild,
|
||||
},
|
||||
None => Instance {
|
||||
name: "Gorb".to_string(),
|
||||
registration: true,
|
||||
require_email_verification: false,
|
||||
initial_guild: None,
|
||||
},
|
||||
};
|
||||
|
||||
|
@ -161,6 +165,7 @@ pub struct Instance {
|
|||
pub name: String,
|
||||
pub registration: bool,
|
||||
pub require_email_verification: bool,
|
||||
pub initial_guild: Option<Uuid>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue