diff --git a/src/main.rs b/src/main.rs index 04403e2..3e6d3a0 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 606b0cf..35192b0 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