feat(users): implement fetch self / user, open dm

This commit is contained in:
Paul Makles
2022-01-31 22:30:02 +00:00
parent c1cd4bfa66
commit 1d5800a3b8
8 changed files with 55 additions and 40 deletions

View File

@@ -1,25 +1,26 @@
use revolt_quark::{EmptyResponse, Result};
use revolt_quark::{Error, EmptyResponse, Result, models::User, Database};
use crate::util::regex::RE_USERNAME;
use mongodb::bson::doc;
use rauth::entities::Account;
use rocket::serde::json::Json;
use rocket::{serde::json::Json, State};
use serde::{Deserialize, Serialize};
use validator::Validate;
#[derive(Validate, Serialize, Deserialize)]
pub struct Data {
#[validate(length(min = 2, max = 32), regex = "RE_USERNAME")]
username: Option<String>,
username: String,
#[validate(length(min = 8, max = 1024))]
password: String,
}
#[patch("/<_ignore_id>/username", data = "<data>")]
#[patch("/@me/username", data = "<data>")]
pub async fn req(
db: &State<Database>,
account: Account,
//user: UserRef,
user: User,
data: Json<Data>,
_ignore_id: String,
) -> Result<EmptyResponse> {
todo!()
account.verify_password(&data.password).map_err(|_| Error::InvalidCredentials)?;
user.update_username(db, &data.username).await
}