From 3dcd78f205d06e138f5a5d2b50f7bece14446912 Mon Sep 17 00:00:00 2001 From: Trinity Pointard Date: Thu, 7 Jun 2018 10:39:22 +0200 Subject: [PATCH] fix redirection to login in src/routes/user.rs --- src/main.rs | 2 ++ src/routes/user.rs | 22 +++++++++++++++++++--- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/src/main.rs b/src/main.rs index 04403e25..3e6d3a03 100644 --- a/src/main.rs +++ b/src/main.rs @@ -109,8 +109,10 @@ fn main() { routes::user::details, routes::user::followers, routes::user::edit, + routes::user::edit_auth, routes::user::update, routes::user::follow, + routes::user::follow_auth, routes::user::activity_details, routes::user::outbox, routes::user::inbox, diff --git a/src/routes/user.rs b/src/routes/user.rs index 606b0cf5..35192b09 100644 --- a/src/routes/user.rs +++ b/src/routes/user.rs @@ -2,7 +2,9 @@ use activitystreams_types::{ activity::Follow, collection::OrderedCollection }; -use rocket::{request::Form, response::Redirect}; +use rocket::{request::Form, + response::{Redirect, Flash} +}; use rocket_contrib::Template; use serde_json; @@ -19,10 +21,14 @@ use models::{ reshares::Reshare, users::* }; +use utils; #[get("/me")] -fn me(user: User) -> Redirect { - Redirect::to(format!("/@/{}/", user.username).as_ref()) +fn me(user: Option) -> Result> { + match user { + Some(user) => Ok(Redirect::to(format!("/@/{}/", user.username).as_ref())), + None => Err(utils::requires_login("", "/me")) + } } #[get("/@/", rank = 2)] @@ -83,6 +89,11 @@ fn follow(name: String, conn: DbConn, user: User) -> Redirect { Redirect::to(format!("/@/{}/", name).as_ref()) } +#[get("/@//follow", rank = 2)] +fn follow_auth(name: String) -> Flash { + utils::requires_login("You need to belogged in order to follow someone", &format!("/@/{}/follow", name)) +} + #[get("/@//followers", rank = 2)] fn followers(name: String, conn: DbConn, account: Option) -> Template { let user = User::find_by_fqn(&*conn, name.clone()).unwrap(); @@ -125,6 +136,11 @@ fn edit(name: String, user: User) -> Option