Compare commits

..

No commits in common. "f4aae9865659868110843defc882ebaf373de993" and "d8681700847f93196d0f2f1070b19d7608582803" have entirely different histories.

7 changed files with 16 additions and 214 deletions

View File

@ -14,8 +14,7 @@ use crate::svc::auth::{AuthError, Claims};
use super::{ use super::{
servek::{Server, ServerError}, servek::{Server, ServerError},
CreateProfileRequest, LoginRequest, NavType, Note, Notification, Profile, Redirect, Timeline, CreateProfileRequest, LoginRequest, NavType, Notification, Redirect, WithNav,
WithNav,
}; };
use rust_embed::RustEmbed; use rust_embed::RustEmbed;
@ -42,21 +41,6 @@ impl Server {
.fallback(routing::get(Self::handler_404)) .fallback(routing::get(Self::handler_404))
} }
fn get_auth(&self, cookies: Cookies) -> Result<Claims, ServerError> {
match cookies.get(AUTH_COOKIE_NAME) {
Some(cookie) => self
.auth
.get_claims(cookie.value().to_owned())
.map_err(|e| {
if e.expired() {
cookies.remove(Cookie::new(AUTH_COOKIE_NAME, ""));
}
e.into()
}),
None => Err(ServerError::NotLoggedIn),
}
}
fn from_cookies(&self, cookies: Cookies) -> Result<WithNav<Option<Claims>>, ServerError> { fn from_cookies(&self, cookies: Cookies) -> Result<WithNav<Option<Claims>>, ServerError> {
const LOGGED_OUT: Result<WithNav<Option<Claims>>, ServerError> = Ok(WithNav { const LOGGED_OUT: Result<WithNav<Option<Claims>>, ServerError> = Ok(WithNav {
obj: None, obj: None,
@ -84,49 +68,10 @@ impl Server {
Extension(srv): Extension<Server>, Extension(srv): Extension<Server>,
cookies: Cookies, cookies: Cookies,
) -> Result<impl IntoResponse, ServerError> { ) -> Result<impl IntoResponse, ServerError> {
// TODO: show actual posts, these are hardcoded currently to check Ok((
// out how they look
let profile1 = Box::new(Profile {
username: "@emilis@puff.place".to_string(),
display_name: "dusty rusty".to_string(),
avatar_url: "https://puff.place/files/thumbnail-501ec5ba-37d6-4163-8e8d-3478a689660d"
.to_string(),
});
let profile2 = Box::new(Profile::new("@emilk@another.place".to_string()));
let note1 = Note::new(profile1.clone(), Some("hey there goods".to_string()));
let note2 = Note::new(
profile2,
Some("@emilis@puff.place u dont got shit".to_string()),
);
let note3 = Note::new(profile1, Some("bithces :".to_string()));
match srv.get_auth(cookies) {
Ok(claims) => Ok((
StatusCode::OK, StatusCode::OK,
response::Html(srv.hb.render( response::Html(srv.hb.render("index", &srv.from_cookies(cookies)?)?),
"index", ))
&WithNav::new(
Timeline {
show_postbox: true,
notes: vec![note1, note2, note3],
},
NavType::LoggedIn,
),
)?),
)
.into_response()),
Err(e) => match e {
ServerError::NotLoggedIn => Ok((
StatusCode::OK,
response::Html(
srv.hb
.render("index", &WithNav::new((), NavType::LoggedOut))?,
),
)
.into_response()),
_ => Err(e),
},
}
} }
async fn favicon() -> impl IntoResponse { async fn favicon() -> impl IntoResponse {

View File

@ -2,53 +2,14 @@ use axum::response::{Html, IntoResponse};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use tower_cookies::{Cookie, Cookies}; use tower_cookies::{Cookie, Cookies};
use crate::svc::auth::{AuthError, Claims}; use crate::svc::{
auth::{Auth, AuthError, Claims},
profiles::User,
};
mod html; mod html;
pub mod servek; pub mod servek;
#[derive(Debug, Clone, Serialize)]
struct Timeline {
pub show_postbox: bool,
pub notes: Vec<Note>,
}
#[derive(Debug, Clone, Serialize)]
struct Note {
pub profile: Box<Profile>,
pub content: Option<String>,
}
impl Note {
fn new(profile: Box<Profile>, content: Option<String>) -> Self {
Self { profile, content }
}
}
#[derive(Debug, Clone, Serialize)]
struct Profile {
pub display_name: String,
pub username: String,
pub avatar_url: String,
}
impl Profile {
fn new(username: String) -> Self {
let display_name = username
.strip_prefix('@')
.unwrap()
.split_once('@')
.unwrap()
.0
.to_string();
Profile {
display_name,
username,
avatar_url: "/favicon.svg".to_string(),
}
}
}
#[derive(Debug, Clone, Serialize)] #[derive(Debug, Clone, Serialize)]
struct Notification { struct Notification {
pub message: String, pub message: String,

View File

@ -79,7 +79,6 @@ impl Server {
pub(super) enum ServerError { pub(super) enum ServerError {
Internal(String), Internal(String),
NotFound, NotFound,
NotLoggedIn,
BadRequest(String), BadRequest(String),
} }
@ -127,7 +126,6 @@ impl IntoResponse for ServerError {
) )
.into_response(), .into_response(),
ServerError::BadRequest(err) => (StatusCode::BAD_REQUEST, err).into_response(), ServerError::BadRequest(err) => (StatusCode::BAD_REQUEST, err).into_response(),
ServerError::NotLoggedIn => (StatusCode::UNAUTHORIZED, "unauthorized").into_response(),
} }
} }
} }

View File

@ -103,8 +103,8 @@ pub enum AuthError {
} }
impl AuthError { impl AuthError {
pub fn expired(&self) -> bool { pub fn expired(self) -> bool {
*self == Self::Expired self == Self::Expired
} }
} }

View File

@ -72,7 +72,7 @@ a {
font-weight: bold; font-weight: bold;
} }
.profile-avatar { .avatar {
width: 128px; width: 128px;
height: 128px; height: 128px;
border: 3px solid rebeccapurple; border: 3px solid rebeccapurple;
@ -152,91 +152,10 @@ nav ul li {
} }
nav>ul>li>a { nav>ul>li>a {
/* color: #aaa; */
/* background-color:#FF0; */
display: block; display: block;
line-height: 2em; line-height: 2em;
padding: 0.5em 0.5em; padding: 0.5em 0.5em;
text-decoration: none; text-decoration: none;
} }
.avatar {
width: 42px;
height: 42px;
}
button {
background-color: rgba(102, 51, 153, 0.75);
color: rgb(204, 179, 230);
border-color: rgba(102, 51, 153, 0.25);
border-style: initial;
font-size: large;
}
#postbox {
/* border: 3px solid rebeccapurple; */
/* padding: 5px; */
margin: 0 0 30px 0;
height: fit-content;
display: flex;
/* text-align: left; */
}
#timeline {
margin: 0;
padding: 0;
}
#timeline li {
display: grid;
list-style-type: none;
width: 85vw;
}
#post-content {
color: rgb(204, 179, 230);
background-color: rebeccapurple;
border-width: 0px;
height: 60px;
width: 85vw;
}
.note {
display: flex;
}
.content {
display: inline-flex;
flex-direction: column;
}
div>p {
font-size: small;
margin-left: 2px;
margin-right: 2px;
}
.display-name {
font-weight: bold;
}
.username {
color: rgba(102, 51, 153, 0.5);
}
.user-info {
display: inline-flex;
margin-top: 0px;
}
#timeline-box {
color: rgb(204, 179, 230);
display: flex;
flex-direction: column;
}
.note:nth-child(even) {
background: rgba(102, 51, 153, 0.25);
}
.note:nth-child(odd) {
background: rgba(102, 51, 153, 0.125);
}

View File

@ -9,28 +9,7 @@
<body> <body>
{{> (lookup this "nav_type") }} {{> (lookup this "nav_type") }}
<div class="main" id="timeline-box"> <h1>hi {{obj.username}}</h1>
{{#if obj.show_postbox}}
<div id="postbox">
<textarea id="post-content" placeholder="im tosti"></textarea>
<button>send</button>
</div>
{{/if}}
<div id="timeline">
{{#each obj.notes}}
<div class="note">
<img class="avatar" src="{{this.profile.avatar_url}}" alt="example" />
<div class="content">
<div class="user-info">
<p class="display-name">{{this.profile.display_name}}</p>
<p class="username">{{this.profile.username}}</p>
</div>
<p class="post-text">{{this.content}}</p>
</div>
</div>
{{/each}}
</div>
</div>
</body> </body>
</html> </html>

View File

@ -12,7 +12,7 @@
<div class="main"> <div class="main">
<div class="profile"> <div class="profile">
<div class="profile-header"> <div class="profile-header">
<img class="profile-avatar" src="{{obj.user.avatar_uri}}" alt="{{obj.user.username}}'s avatar" /> <img class="avatar" src="{{obj.user.avatar_uri}}" alt="{{obj.user.username}}'s avatar" />
<p class="name">{{obj.user.display_name}}</p> <p class="name">{{obj.user.display_name}}</p>
</div> </div>
<div class="profile-bio"> <div class="profile-bio">