add fallback to url generating 404
This commit is contained in:
parent
2fde47d909
commit
8158f19b85
|
@ -71,9 +71,11 @@ fn main() {
|
|||
routes::blogs::activity_details,
|
||||
routes::blogs::outbox,
|
||||
routes::blogs::new,
|
||||
routes::blogs::new_auth,
|
||||
routes::blogs::create,
|
||||
|
||||
routes::comments::new,
|
||||
routes::comments::new_auth,
|
||||
routes::comments::create,
|
||||
|
||||
routes::instance::index,
|
||||
|
@ -82,8 +84,10 @@ fn main() {
|
|||
routes::instance::shared_inbox,
|
||||
|
||||
routes::likes::create,
|
||||
routes::likes::create_auth,
|
||||
|
||||
routes::notifications::notifications,
|
||||
routes::notifications::notifications_auth,
|
||||
|
||||
routes::posts::details,
|
||||
routes::posts::activity_details,
|
||||
|
@ -92,6 +96,7 @@ fn main() {
|
|||
routes::posts::create,
|
||||
|
||||
routes::reshares::create,
|
||||
routes::reshares::create_auth,
|
||||
|
||||
routes::session::new,
|
||||
routes::session::new_message,
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use activitystreams_types::collection::OrderedCollection;
|
||||
use rocket::{
|
||||
request::Form,
|
||||
response::Redirect
|
||||
response::{Redirect, Flash}
|
||||
};
|
||||
use rocket_contrib::Template;
|
||||
use serde_json;
|
||||
|
@ -53,6 +53,11 @@ fn new(user: User) -> Template {
|
|||
}))
|
||||
}
|
||||
|
||||
#[get("/blogs/new", rank = 2)]
|
||||
fn new_auth() -> Flash<Redirect>{
|
||||
utils::requires_login("You need to be logged in order to create a new blog", "/blogs/new")
|
||||
}
|
||||
|
||||
#[derive(FromForm)]
|
||||
struct NewBlogForm {
|
||||
pub title: String
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
use rocket::{ request::Form, response::Redirect};
|
||||
use rocket::{
|
||||
request::Form,
|
||||
response::{Redirect, Flash}
|
||||
};
|
||||
use rocket_contrib::Template;
|
||||
|
||||
use activity_pub::broadcast;
|
||||
|
@ -9,6 +12,8 @@ use models::{
|
|||
users::User
|
||||
};
|
||||
|
||||
use utils;
|
||||
|
||||
#[get("/~/<_blog>/<slug>/comment")]
|
||||
fn new(_blog: String, slug: String, user: User, conn: DbConn) -> Template {
|
||||
let post = Post::find_by_slug(&*conn, slug).unwrap();
|
||||
|
@ -18,6 +23,11 @@ fn new(_blog: String, slug: String, user: User, conn: DbConn) -> Template {
|
|||
}))
|
||||
}
|
||||
|
||||
#[get("/~/<blog>/<slug>/comment", rank=2)]
|
||||
fn new_auth(blog: String, slug: String) -> Flash<Redirect>{
|
||||
utils::requires_login("You need to be logged in order to post a comment", &format!("~/{}/{}/comment", blog, slug))
|
||||
}
|
||||
|
||||
#[derive(FromForm)]
|
||||
struct CommentQuery {
|
||||
responding_to: Option<i32>
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use rocket::response::Redirect;
|
||||
use rocket::response::{Redirect, Flash};
|
||||
|
||||
use activity_pub::broadcast;
|
||||
use db_conn::DbConn;
|
||||
|
@ -8,6 +8,8 @@ use models::{
|
|||
users::User
|
||||
};
|
||||
|
||||
use utils;
|
||||
|
||||
#[get("/~/<blog>/<slug>/like")]
|
||||
fn create(blog: String, slug: String, user: User, conn: DbConn) -> Redirect {
|
||||
let post = Post::find_by_slug(&*conn, slug.clone()).unwrap();
|
||||
|
@ -29,3 +31,8 @@ fn create(blog: String, slug: String, user: User, conn: DbConn) -> Redirect {
|
|||
|
||||
Redirect::to(format!("/~/{}/{}/", blog, slug).as_ref())
|
||||
}
|
||||
|
||||
#[get("/~/<blog>/<slug>/like", rank = 2)]
|
||||
fn create_auth(blog: String, slug: String) -> Flash<Redirect>{
|
||||
utils::requires_login("You need to be logged in order to like a post", &format!("/~/{}/{}/like", blog, slug))
|
||||
}
|
||||
|
|
|
@ -1,8 +1,11 @@
|
|||
use rocket::response::{Redirect, Flash};
|
||||
use rocket_contrib::Template;
|
||||
|
||||
use db_conn::DbConn;
|
||||
use models::{notifications::Notification, users::User};
|
||||
|
||||
use utils;
|
||||
|
||||
#[get("/notifications")]
|
||||
fn notifications(conn: DbConn, user: User) -> Template {
|
||||
Template::render("notifications/index", json!({
|
||||
|
@ -10,3 +13,8 @@ fn notifications(conn: DbConn, user: User) -> Template {
|
|||
"notifications": Notification::find_for_user(&*conn, &user)
|
||||
}))
|
||||
}
|
||||
|
||||
#[get("/notifications", rank = 2)]
|
||||
fn notifications_auth() -> Flash<Redirect>{
|
||||
utils::requires_login("You need to be logged in order to see your notifications", "/notifications")
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use comrak::{markdown_to_html, ComrakOptions};
|
||||
use heck::KebabCase;
|
||||
use rocket::request::Form;
|
||||
use rocket::response::Redirect;
|
||||
use rocket::response::{Redirect, Flash};
|
||||
use rocket_contrib::Template;
|
||||
use serde_json;
|
||||
|
||||
|
@ -57,9 +57,9 @@ fn activity_details(_blog: String, slug: String, conn: DbConn) -> ActivityPub {
|
|||
activity_pub(act)
|
||||
}
|
||||
|
||||
#[get("/~/<_blog>/new", rank = 2)]
|
||||
fn new_auth(_blog: String) -> Redirect {
|
||||
utils::requires_login()
|
||||
#[get("/~/<blog>/new", rank = 2)]
|
||||
fn new_auth(blog: String) -> Flash<Redirect> {
|
||||
utils::requires_login("You need to be logged in order to write a new post", &format!("/~/{}/new",blog))
|
||||
}
|
||||
|
||||
#[get("/~/<_blog>/new", rank = 1)]
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use rocket::response::Redirect;
|
||||
use rocket::response::{Redirect, Flash};
|
||||
|
||||
use activity_pub::broadcast;
|
||||
use db_conn::DbConn;
|
||||
|
@ -8,6 +8,8 @@ use models::{
|
|||
users::User
|
||||
};
|
||||
|
||||
use utils;
|
||||
|
||||
#[get("/~/<blog>/<slug>/reshare")]
|
||||
fn create(blog: String, slug: String, user: User, conn: DbConn) -> Redirect {
|
||||
let post = Post::find_by_slug(&*conn, slug.clone()).unwrap();
|
||||
|
@ -29,3 +31,8 @@ fn create(blog: String, slug: String, user: User, conn: DbConn) -> Redirect {
|
|||
|
||||
Redirect::to(format!("/~/{}/{}/", blog, slug).as_ref())
|
||||
}
|
||||
|
||||
#[get("/~/<blog>/<slug>/reshare", rank=1)]
|
||||
fn create_auth(blog: String, slug: String) -> Flash<Redirect> {
|
||||
utils::requires_login("You need to be logged in order to reshare a post", &format!("/~/{}/{}/reshare",blog, slug))
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
use heck::CamelCase;
|
||||
use rocket::response::Redirect;
|
||||
use rocket::response::{Redirect, Flash};
|
||||
|
||||
/// Remove non alphanumeric characters and CamelCase a string
|
||||
pub fn make_actor_id(name: String) -> String {
|
||||
|
@ -11,6 +11,6 @@ pub fn make_actor_id(name: String) -> String {
|
|||
.collect()
|
||||
}
|
||||
|
||||
pub fn requires_login() -> Redirect {
|
||||
Redirect::to("/login")
|
||||
pub fn requires_login(message: &str, url: &str) -> Flash<Redirect> {
|
||||
Flash::new(Redirect::to(&format!("/login?m={}", message)), "callback", url)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue