2021-11-03 09:52:02 +00:00
|
|
|
//! Routes for ScuttleButt related functionality.
|
|
|
|
|
|
|
|
use rocket::{get, request::FlashMessage};
|
2021-11-04 11:03:40 +00:00
|
|
|
use rocket_dyn_templates::Template;
|
2021-10-28 08:01:31 +00:00
|
|
|
use serde::Serialize;
|
|
|
|
|
2021-11-08 15:38:10 +00:00
|
|
|
use crate::routes::authentication::Authenticated;
|
|
|
|
|
2021-11-03 09:52:02 +00:00
|
|
|
// HELPERS AND ROUTES FOR /messages
|
2021-10-28 08:01:31 +00:00
|
|
|
|
|
|
|
#[derive(Debug, Serialize)]
|
|
|
|
pub struct MessageContext {
|
|
|
|
pub back: Option<String>,
|
|
|
|
pub flash_name: Option<String>,
|
|
|
|
pub flash_msg: Option<String>,
|
|
|
|
pub title: Option<String>,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl MessageContext {
|
|
|
|
pub fn build() -> MessageContext {
|
|
|
|
MessageContext {
|
|
|
|
back: None,
|
|
|
|
flash_name: None,
|
|
|
|
flash_msg: None,
|
|
|
|
title: None,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[get("/messages")]
|
2021-11-08 15:38:10 +00:00
|
|
|
pub fn messages(flash: Option<FlashMessage>, auth: Authenticated) -> Template {
|
2021-10-28 08:01:31 +00:00
|
|
|
let mut context = MessageContext::build();
|
|
|
|
context.back = Some("/".to_string());
|
|
|
|
context.title = Some("Private Messages".to_string());
|
|
|
|
// check to see if there is a flash message to display
|
|
|
|
if let Some(flash) = flash {
|
|
|
|
// add flash message contents to the context object
|
2021-11-04 11:03:40 +00:00
|
|
|
context.flash_name = Some(flash.kind().to_string());
|
|
|
|
context.flash_msg = Some(flash.message().to_string());
|
2021-10-28 08:01:31 +00:00
|
|
|
};
|
|
|
|
Template::render("messages", &context)
|
|
|
|
}
|
|
|
|
|
2021-11-03 09:52:02 +00:00
|
|
|
// HELPERS AND ROUTES FOR /peers
|
2021-10-28 08:01:31 +00:00
|
|
|
|
|
|
|
#[derive(Debug, Serialize)]
|
|
|
|
pub struct PeerContext {
|
|
|
|
pub back: Option<String>,
|
|
|
|
pub flash_name: Option<String>,
|
|
|
|
pub flash_msg: Option<String>,
|
|
|
|
pub title: Option<String>,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl PeerContext {
|
|
|
|
pub fn build() -> PeerContext {
|
|
|
|
PeerContext {
|
|
|
|
back: None,
|
|
|
|
flash_name: None,
|
|
|
|
flash_msg: None,
|
|
|
|
title: None,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[get("/peers")]
|
2021-11-08 15:38:10 +00:00
|
|
|
pub fn peers(flash: Option<FlashMessage>, auth: Authenticated) -> Template {
|
2021-10-28 08:01:31 +00:00
|
|
|
let mut context = PeerContext::build();
|
|
|
|
context.back = Some("/".to_string());
|
|
|
|
context.title = Some("Scuttlebutt Peers".to_string());
|
|
|
|
// check to see if there is a flash message to display
|
|
|
|
if let Some(flash) = flash {
|
|
|
|
// add flash message contents to the context object
|
2021-11-04 11:03:40 +00:00
|
|
|
context.flash_name = Some(flash.kind().to_string());
|
|
|
|
context.flash_msg = Some(flash.message().to_string());
|
2021-10-28 08:01:31 +00:00
|
|
|
};
|
|
|
|
Template::render("peers", &context)
|
|
|
|
}
|
|
|
|
|
2021-11-03 09:52:02 +00:00
|
|
|
// HELPERS AND ROUTES FOR /profile
|
2021-10-28 08:01:31 +00:00
|
|
|
|
|
|
|
#[derive(Debug, Serialize)]
|
|
|
|
pub struct ProfileContext {
|
|
|
|
pub back: Option<String>,
|
|
|
|
pub flash_name: Option<String>,
|
|
|
|
pub flash_msg: Option<String>,
|
|
|
|
pub title: Option<String>,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl ProfileContext {
|
|
|
|
pub fn build() -> ProfileContext {
|
|
|
|
ProfileContext {
|
|
|
|
back: None,
|
|
|
|
flash_name: None,
|
|
|
|
flash_msg: None,
|
|
|
|
title: None,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[get("/profile")]
|
2021-11-08 15:38:10 +00:00
|
|
|
pub fn profile(flash: Option<FlashMessage>, auth: Authenticated) -> Template {
|
2021-10-28 08:01:31 +00:00
|
|
|
let mut context = ProfileContext::build();
|
|
|
|
context.back = Some("/".to_string());
|
|
|
|
context.title = Some("Profile".to_string());
|
|
|
|
// check to see if there is a flash message to display
|
|
|
|
if let Some(flash) = flash {
|
|
|
|
// add flash message contents to the context object
|
2021-11-04 11:03:40 +00:00
|
|
|
context.flash_name = Some(flash.kind().to_string());
|
|
|
|
context.flash_msg = Some(flash.message().to_string());
|
2021-10-28 08:01:31 +00:00
|
|
|
};
|
|
|
|
Template::render("profile", &context)
|
2021-11-03 09:52:02 +00:00
|
|
|
}
|