Some checks failed
docker-images / resolve-build-targets (push) Successful in 7s
ui-regression / playwright-regression (push) Failing after 13m4s
docker-images / build-and-push (admin) (push) Successful in 1m17s
docker-images / build-and-push (backend) (push) Successful in 28m13s
docker-images / build-and-push (frontend) (push) Successful in 47s
docker-images / submit-indexnow (push) Successful in 13s
style: enhance global CSS for better responsiveness of terminal chips and navigation pills test: remove inline subscription test and add maintenance mode access code test feat: implement media library picker dialog for selecting images from the media library feat: add media URL controls for uploading and managing media assets feat: add migration for music_enabled and maintenance_mode settings in site settings feat: implement maintenance mode functionality with access control feat: create maintenance page with access code input and error handling chore: add TypeScript declaration for QR code module
58 lines
1.6 KiB
Rust
58 lines
1.6 KiB
Rust
use axum::http::{HeaderName, HeaderValue};
|
|
use loco_rs::{TestServer, app::AppContext};
|
|
use termi_api::{models::users, views::auth::LoginResponse};
|
|
|
|
const USER_EMAIL: &str = "test@loco.com";
|
|
const USER_PASSWORD: &str = "1234";
|
|
|
|
pub struct LoggedInUser {
|
|
pub user: users::Model,
|
|
pub token: String,
|
|
}
|
|
|
|
pub async fn init_user_login(request: &TestServer, ctx: &AppContext) -> LoggedInUser {
|
|
let register_payload = serde_json::json!({
|
|
"name": "loco",
|
|
"email": USER_EMAIL,
|
|
"password": USER_PASSWORD
|
|
});
|
|
|
|
//Creating a new user
|
|
request
|
|
.post("/api/auth/register")
|
|
.json(®ister_payload)
|
|
.await;
|
|
let user = users::Model::find_by_email(&ctx.db, USER_EMAIL)
|
|
.await
|
|
.unwrap();
|
|
|
|
let verify_payload = serde_json::json!({
|
|
"token": user.email_verification_token,
|
|
});
|
|
|
|
request.post("/api/auth/verify").json(&verify_payload).await;
|
|
|
|
let response = request
|
|
.post("/api/auth/login")
|
|
.json(&serde_json::json!({
|
|
"email": USER_EMAIL,
|
|
"password": USER_PASSWORD
|
|
}))
|
|
.await;
|
|
|
|
let login_response: LoginResponse = serde_json::from_str(&response.text()).unwrap();
|
|
|
|
LoggedInUser {
|
|
user: users::Model::find_by_email(&ctx.db, USER_EMAIL)
|
|
.await
|
|
.unwrap(),
|
|
token: login_response.token,
|
|
}
|
|
}
|
|
|
|
pub fn auth_header(token: &str) -> (HeaderName, HeaderValue) {
|
|
let auth_header_value = HeaderValue::from_str(&format!("Bearer {}", &token)).unwrap();
|
|
|
|
(HeaderName::from_static("authorization"), auth_header_value)
|
|
}
|