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 super::Response;
|
||||||
use crate::{
|
use crate::{
|
||||||
Data,
|
error::Error, objects::Member, schema::{
|
||||||
error::Error,
|
access_tokens::{self, dsl as adsl}, refresh_tokens::{self, dsl as rdsl}, users::{self, dsl as udsl}
|
||||||
schema::{
|
}, utils::{
|
||||||
access_tokens::{self, dsl as adsl},
|
generate_token, new_refresh_token_cookie, EMAIL_REGEX, PASSWORD_REGEX, USERNAME_REGEX
|
||||||
refresh_tokens::{self, dsl as rdsl},
|
}, Data
|
||||||
users::{self, dsl as udsl},
|
|
||||||
},
|
|
||||||
utils::{
|
|
||||||
EMAIL_REGEX, PASSWORD_REGEX, USERNAME_REGEX, generate_token,
|
|
||||||
new_refresh_token_cookie,
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
|
@ -145,6 +139,10 @@ pub async fn res(
|
||||||
.execute(&mut conn)
|
.execute(&mut conn)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
|
if let Some(initial_guild) = data.config.instance.initial_guild {
|
||||||
|
Member::new(&data, uuid, initial_guild).await?;
|
||||||
|
}
|
||||||
|
|
||||||
return Ok(HttpResponse::Ok()
|
return Ok(HttpResponse::Ok()
|
||||||
.cookie(new_refresh_token_cookie(&data.config, refresh_token))
|
.cookie(new_refresh_token_cookie(&data.config, refresh_token))
|
||||||
.json(Response { access_token }));
|
.json(Response { access_token }));
|
||||||
|
|
|
@ -5,6 +5,7 @@ use log::debug;
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use tokio::fs::read_to_string;
|
use tokio::fs::read_to_string;
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
use uuid::Uuid;
|
||||||
|
|
||||||
#[derive(Debug, Deserialize)]
|
#[derive(Debug, Deserialize)]
|
||||||
pub struct ConfigBuilder {
|
pub struct ConfigBuilder {
|
||||||
|
@ -48,6 +49,7 @@ struct InstanceBuilder {
|
||||||
name: Option<String>,
|
name: Option<String>,
|
||||||
registration: Option<bool>,
|
registration: Option<bool>,
|
||||||
require_email_verification: Option<bool>,
|
require_email_verification: Option<bool>,
|
||||||
|
initial_guild: Option<Uuid>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Deserialize)]
|
#[derive(Debug, Deserialize)]
|
||||||
|
@ -119,11 +121,13 @@ impl ConfigBuilder {
|
||||||
name: instance.name.unwrap_or("Gorb".to_string()),
|
name: instance.name.unwrap_or("Gorb".to_string()),
|
||||||
registration: instance.registration.unwrap_or(true),
|
registration: instance.registration.unwrap_or(true),
|
||||||
require_email_verification: instance.require_email_verification.unwrap_or(false),
|
require_email_verification: instance.require_email_verification.unwrap_or(false),
|
||||||
|
initial_guild: instance.initial_guild,
|
||||||
},
|
},
|
||||||
None => Instance {
|
None => Instance {
|
||||||
name: "Gorb".to_string(),
|
name: "Gorb".to_string(),
|
||||||
registration: true,
|
registration: true,
|
||||||
require_email_verification: false,
|
require_email_verification: false,
|
||||||
|
initial_guild: None,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -161,6 +165,7 @@ pub struct Instance {
|
||||||
pub name: String,
|
pub name: String,
|
||||||
pub registration: bool,
|
pub registration: bool,
|
||||||
pub require_email_verification: bool,
|
pub require_email_verification: bool,
|
||||||
|
pub initial_guild: Option<Uuid>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue