feat: add changing username, email and display_name to /me endpoint
This commit is contained in:
parent
1ff3fa69a7
commit
9728769b8c
6 changed files with 95 additions and 29 deletions
|
@ -9,10 +9,12 @@ use uuid::Uuid;
|
|||
|
||||
use crate::{
|
||||
Data,
|
||||
api::v1::auth::{EMAIL_REGEX, PASSWORD_REGEX, USERNAME_REGEX},
|
||||
error::Error,
|
||||
schema::*,
|
||||
utils::{generate_access_token, generate_refresh_token, refresh_token_cookie},
|
||||
utils::{
|
||||
EMAIL_REGEX, PASSWORD_REGEX, USERNAME_REGEX, generate_access_token, generate_refresh_token,
|
||||
refresh_token_cookie,
|
||||
},
|
||||
};
|
||||
|
||||
use super::Response;
|
||||
|
|
|
@ -22,15 +22,6 @@ struct Response {
|
|||
access_token: String,
|
||||
}
|
||||
|
||||
static EMAIL_REGEX: LazyLock<Regex> = LazyLock::new(|| {
|
||||
Regex::new(r"[-A-Za-z0-9!#$%&'*+/=?^_`{|}~]+(?:\.[-A-Za-z0-9!#$%&'*+/=?^_`{|}~]+)*@(?:[A-Za-z0-9](?:[-A-Za-z0-9]*[A-Za-z0-9])?\.)+[A-Za-z0-9](?:[-A-Za-z0-9]*[A-Za-z0-9])?").unwrap()
|
||||
});
|
||||
|
||||
static USERNAME_REGEX: LazyLock<Regex> = LazyLock::new(|| Regex::new(r"^[a-z0-9_.-]+$").unwrap());
|
||||
|
||||
// Password is expected to be hashed using SHA3-384
|
||||
static PASSWORD_REGEX: LazyLock<Regex> = LazyLock::new(|| Regex::new(r"[0-9a-f]{96}").unwrap());
|
||||
|
||||
pub fn web() -> Scope {
|
||||
web::scope("/auth")
|
||||
.service(register::res)
|
||||
|
|
|
@ -13,14 +13,16 @@ use uuid::Uuid;
|
|||
use super::Response;
|
||||
use crate::{
|
||||
Data,
|
||||
api::v1::auth::{EMAIL_REGEX, PASSWORD_REGEX, USERNAME_REGEX},
|
||||
error::Error,
|
||||
schema::{
|
||||
access_tokens::{self, dsl as adsl},
|
||||
refresh_tokens::{self, dsl as rdsl},
|
||||
users::{self, dsl as udsl},
|
||||
},
|
||||
utils::{generate_access_token, generate_refresh_token, refresh_token_cookie},
|
||||
utils::{
|
||||
EMAIL_REGEX, PASSWORD_REGEX, USERNAME_REGEX, generate_access_token, generate_refresh_token,
|
||||
refresh_token_cookie,
|
||||
},
|
||||
};
|
||||
|
||||
#[derive(Deserialize)]
|
||||
|
@ -68,9 +70,11 @@ pub async fn res(
|
|||
data: web::Data<Data>,
|
||||
) -> Result<HttpResponse, Error> {
|
||||
if !data.config.instance.registration {
|
||||
return Err(Error::Forbidden("registration is disabled on this instance".to_string()))
|
||||
return Err(Error::Forbidden(
|
||||
"registration is disabled on this instance".to_string(),
|
||||
));
|
||||
}
|
||||
|
||||
|
||||
let uuid = Uuid::now_v7();
|
||||
|
||||
if !EMAIL_REGEX.is_match(&account_information.email) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue