commit
ffb4f6e6d8
@ -19,7 +19,7 @@ use utils;
|
||||
|
||||
#[get("/~/<name>", rank = 2)]
|
||||
fn details(name: String, conn: DbConn, user: Option<User>) -> Template {
|
||||
may_fail!(Blog::find_by_fqn(&*conn, name), "Requested blog couldn't be found", |blog| {
|
||||
may_fail!(user, Blog::find_by_fqn(&*conn, name), "Requested blog couldn't be found", |blog| {
|
||||
let recents = Post::get_recents_for_blog(&*conn, &blog, 5);
|
||||
|
||||
Template::render("blogs/details", json!({
|
||||
|
@ -1,15 +1,22 @@
|
||||
use rocket_contrib::Template;
|
||||
use rocket::Request;
|
||||
use rocket::request::FromRequest;
|
||||
use models::users::User;
|
||||
|
||||
#[catch(404)]
|
||||
fn not_found() -> Template {
|
||||
fn not_found(req: &Request) -> Template {
|
||||
let user = User::from_request(req).succeeded();
|
||||
Template::render("errors/404", json!({
|
||||
"error_message": "Page not found"
|
||||
"error_message": "Page not found",
|
||||
"account": user
|
||||
}))
|
||||
}
|
||||
|
||||
#[catch(500)]
|
||||
fn server_error() -> Template {
|
||||
fn server_error(req: &Request) -> Template {
|
||||
let user = User::from_request(req).succeeded();
|
||||
Template::render("errors/500", json!({
|
||||
"error_message": "Server error"
|
||||
"error_message": "Server error",
|
||||
"account": user
|
||||
}))
|
||||
}
|
||||
|
@ -2,7 +2,7 @@ use rocket::response::NamedFile;
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
macro_rules! may_fail {
|
||||
($expr:expr, $template:expr, $msg:expr, | $res:ident | $block:block) => {
|
||||
($account:expr, $expr:expr, $template:expr, $msg:expr, | $res:ident | $block:block) => {
|
||||
{
|
||||
let res = $expr;
|
||||
if res.is_some() {
|
||||
@ -10,18 +10,19 @@ macro_rules! may_fail {
|
||||
$block
|
||||
} else {
|
||||
Template::render(concat!("errors/", $template), json!({
|
||||
"error_message": $msg
|
||||
"error_message": $msg,
|
||||
"account": $account
|
||||
}))
|
||||
}
|
||||
}
|
||||
};
|
||||
($expr:expr, $msg:expr, | $res:ident | $block:block) => {
|
||||
may_fail!($expr, "404", $msg, |$res| {
|
||||
($account:expr, $expr:expr, $msg:expr, | $res:ident | $block:block) => {
|
||||
may_fail!($account, $expr, "404", $msg, |$res| {
|
||||
$block
|
||||
})
|
||||
};
|
||||
($expr:expr, | $res:ident | $block:block) => {
|
||||
may_fail!($expr, "", |$res| {
|
||||
($account:expr, $expr:expr, | $res:ident | $block:block) => {
|
||||
may_fail!($account, $expr, "", |$res| {
|
||||
$block
|
||||
})
|
||||
};
|
||||
|
@ -27,8 +27,8 @@ fn details(blog: String, slug: String, conn: DbConn, user: Option<User>) -> Temp
|
||||
|
||||
#[get("/~/<blog>/<slug>?<query>")]
|
||||
fn details_response(blog: String, slug: String, conn: DbConn, user: Option<User>, query: Option<CommentQuery>) -> Template {
|
||||
may_fail!(Blog::find_by_fqn(&*conn, blog), "Couldn't find this blog", |blog| {
|
||||
may_fail!(Post::find_by_slug(&*conn, slug, blog.id), "Couldn't find this post", |post| {
|
||||
may_fail!(user, Blog::find_by_fqn(&*conn, blog), "Couldn't find this blog", |blog| {
|
||||
may_fail!(user, Post::find_by_slug(&*conn, slug, blog.id), "Couldn't find this post", |post| {
|
||||
let comments = Comment::list_by_post(&*conn, post.id);
|
||||
|
||||
Template::render("posts/details", json!({
|
||||
|
@ -33,7 +33,7 @@ fn me(user: Option<User>) -> Result<Redirect, Flash<Redirect>> {
|
||||
|
||||
#[get("/@/<name>", rank = 2)]
|
||||
fn details(name: String, conn: DbConn, account: Option<User>) -> Template {
|
||||
may_fail!(User::find_by_fqn(&*conn, name), "Couldn't find requested user", |user| {
|
||||
may_fail!(account, User::find_by_fqn(&*conn, name), "Couldn't find requested user", |user| {
|
||||
let recents = Post::get_recents_for_author(&*conn, &user, 6);
|
||||
let reshares = Reshare::get_recents_for_author(&*conn, &user, 6);
|
||||
let user_id = user.id.clone();
|
||||
@ -92,7 +92,7 @@ fn follow_auth(name: String) -> Flash<Redirect> {
|
||||
|
||||
#[get("/@/<name>/followers", rank = 2)]
|
||||
fn followers(name: String, conn: DbConn, account: Option<User>) -> Template {
|
||||
may_fail!(User::find_by_fqn(&*conn, name.clone()), "Couldn't find requested user", |user| {
|
||||
may_fail!(account, User::find_by_fqn(&*conn, name.clone()), "Couldn't find requested user", |user| {
|
||||
let user_id = user.id.clone();
|
||||
|
||||
Template::render("users/followers", json!({
|
||||
|
@ -11,7 +11,7 @@
|
||||
</h1>
|
||||
|
||||
{% if is_self %}
|
||||
<a href="edit" class="button inline-block">{{ "Edit your profile" | _ }}</a>
|
||||
<a href="/@/{{ user.username }}/edit" class="button inline-block">{{ "Edit your profile" | _ }}</a>
|
||||
{% endif %}
|
||||
|
||||
{% if is_remote %}
|
||||
|
Loading…
Reference in New Issue
Block a user