pull in ruma so I do not have to write all requests and responses myself
Some checks failed
continuous-integration/drone Build is failing
Some checks failed
continuous-integration/drone Build is failing
This commit is contained in:
@ -1,9 +1,7 @@
|
||||
use std::{collections::HashMap, sync::Arc};
|
||||
|
||||
use argon2::{password_hash::SaltString, Argon2, PasswordHash, PasswordHasher};
|
||||
use axum::{
|
||||
extract::Query,
|
||||
http::StatusCode,
|
||||
routing::{get, post},
|
||||
Extension, Json,
|
||||
};
|
||||
@ -19,19 +17,19 @@ use crate::{
|
||||
authentication::{AuthenticationResponse, AuthenticationSuccess},
|
||||
registration::RegistrationResponse,
|
||||
},
|
||||
types::uuid::Uuid,
|
||||
};
|
||||
use crate::{
|
||||
models::devices::Device,
|
||||
responses::{flow::Flows, registration::RegistrationSuccess},
|
||||
ruma_wrapper::RumaResponse,
|
||||
};
|
||||
use crate::{models::devices::Device, responses::registration::RegistrationSuccess};
|
||||
use crate::{
|
||||
models::users::User,
|
||||
requests::registration::RegistrationRequest,
|
||||
responses::username_available::UsernameAvailable,
|
||||
types::{authentication_data::AuthenticationData, user_id::UserId},
|
||||
Config,
|
||||
};
|
||||
use ruma::api::client::{
|
||||
account,
|
||||
session::get_login_types::v3::{LoginType, PasswordLoginType},
|
||||
};
|
||||
|
||||
pub fn routes() -> axum::Router {
|
||||
axum::Router::new()
|
||||
@ -40,9 +38,12 @@ pub fn routes() -> axum::Router {
|
||||
.route("/r0/register/available", get(get_username_available))
|
||||
}
|
||||
|
||||
use ruma::api::client::session;
|
||||
#[tracing::instrument]
|
||||
async fn get_login() -> Result<Json<Flows>, ApiError> {
|
||||
Ok(Json(Flows::new()))
|
||||
async fn get_login() -> Result<RumaResponse<session::get_login_types::v3::Response>, ApiError> {
|
||||
Ok(RumaResponse(session::get_login_types::v3::Response::new(
|
||||
vec![LoginType::Password(PasswordLoginType::new())],
|
||||
)))
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip_all)]
|
||||
@ -92,7 +93,7 @@ async fn get_username_available(
|
||||
Extension(config): Extension<Arc<Config>>,
|
||||
Extension(db): Extension<SqlitePool>,
|
||||
Query(params): Query<HashMap<String, String>>,
|
||||
) -> Result<Json<UsernameAvailable>, ApiError> {
|
||||
) -> Result<RumaResponse<account::get_username_availability::v3::Response>, ApiError> {
|
||||
let username = params
|
||||
.get("username")
|
||||
.ok_or(RegistrationError::MissingUserId)?;
|
||||
@ -101,7 +102,9 @@ async fn get_username_available(
|
||||
.ok_or(RegistrationError::InvalidUserId)?;
|
||||
let exists = User::exists(&db, &user_id).await?;
|
||||
|
||||
Ok(Json(UsernameAvailable::new(!exists)))
|
||||
Ok(RumaResponse(
|
||||
account::get_username_availability::v3::Response::new(!exists),
|
||||
))
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip_all)]
|
||||
@ -110,7 +113,10 @@ async fn post_register(
|
||||
Extension(db): Extension<SqlitePool>,
|
||||
Json(body): Json<RegistrationRequest>,
|
||||
) -> Result<Json<RegistrationResponse>, ApiError> {
|
||||
config.enable_registration().then(|| true).ok_or(RegistrationError::RegistrationDisabled)?;
|
||||
config
|
||||
.enable_registration()
|
||||
.then(|| true)
|
||||
.ok_or(RegistrationError::RegistrationDisabled)?;
|
||||
body.auth()
|
||||
.ok_or(RegistrationError::AdditionalAuthenticationInformation)?;
|
||||
|
||||
|
17
src/api/client_server/r0/create_room.rs
Normal file
17
src/api/client_server/r0/create_room.rs
Normal file
@ -0,0 +1,17 @@
|
||||
use axum::routing::post;
|
||||
|
||||
use crate::api::client_server::errors::api_error::ApiError;
|
||||
use crate::ruma_wrapper::RumaRequest;
|
||||
|
||||
use ruma::api::client::room;
|
||||
|
||||
pub fn routes() -> axum::Router {
|
||||
axum::Router::new()
|
||||
.route("/r0/createRoom", post(post_create_room))
|
||||
.layer(axum::middleware::from_fn(super::authentication_middleware))
|
||||
}
|
||||
async fn post_create_room(
|
||||
RumaRequest(_req): RumaRequest<room::create_room::v3::IncomingRequest>,
|
||||
) -> Result<String, ApiError> {
|
||||
Ok("".into())
|
||||
}
|
@ -14,6 +14,7 @@ use super::errors::ErrorResponse;
|
||||
|
||||
pub mod auth;
|
||||
pub mod thirdparty;
|
||||
pub mod create_room;
|
||||
|
||||
async fn authentication_middleware<B>(mut req: Request<B>, next: Next<B>) -> impl IntoResponse {
|
||||
let db: &SqlitePool = req.extensions().get().unwrap();
|
||||
|
@ -1,9 +1,14 @@
|
||||
use std::sync::Arc;
|
||||
use std::{collections::BTreeMap, sync::Arc};
|
||||
|
||||
use axum::{routing::get, Extension};
|
||||
|
||||
use crate::{api::client_server::errors::api_error::ApiError, models::users::User};
|
||||
use crate::{
|
||||
api::client_server::errors::api_error::ApiError,
|
||||
models::users::User,
|
||||
ruma_wrapper::{RumaRequest, RumaResponse},
|
||||
};
|
||||
|
||||
use ruma::api::client::thirdparty;
|
||||
|
||||
pub fn routes() -> axum::Router {
|
||||
axum::Router::new()
|
||||
@ -12,6 +17,11 @@ pub fn routes() -> axum::Router {
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip_all)]
|
||||
async fn get_thirdparty_protocols(Extension(user): Extension<Arc<User>>) -> Result<String, ApiError> {
|
||||
Ok("{}".into())
|
||||
}
|
||||
async fn get_thirdparty_protocols(
|
||||
Extension(_user): Extension<Arc<User>>,
|
||||
RumaRequest(_req): RumaRequest<thirdparty::get_protocols::v3::IncomingRequest>,
|
||||
) -> Result<RumaResponse<thirdparty::get_protocols::v3::Response>, ApiError> {
|
||||
Ok(RumaResponse(thirdparty::get_protocols::v3::Response::new(
|
||||
BTreeMap::new(),
|
||||
)))
|
||||
}
|
||||
|
Reference in New Issue
Block a user