Merge pull request #46 from fdb-hiroshima/login_redirect

fix redirection to login in src/routes/user.rs
This commit is contained in:
Baptiste Gelez 2018-06-07 18:43:51 +01:00 committed by GitHub
commit 87d39ba27f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 3 deletions

View File

@ -109,8 +109,10 @@ fn main() {
routes::user::details, routes::user::details,
routes::user::followers, routes::user::followers,
routes::user::edit, routes::user::edit,
routes::user::edit_auth,
routes::user::update, routes::user::update,
routes::user::follow, routes::user::follow,
routes::user::follow_auth,
routes::user::activity_details, routes::user::activity_details,
routes::user::outbox, routes::user::outbox,
routes::user::inbox, routes::user::inbox,

View File

@ -2,7 +2,9 @@ use activitystreams_types::{
activity::Follow, activity::Follow,
collection::OrderedCollection collection::OrderedCollection
}; };
use rocket::{request::Form, response::Redirect}; use rocket::{request::Form,
response::{Redirect, Flash}
};
use rocket_contrib::Template; use rocket_contrib::Template;
use serde_json; use serde_json;
@ -19,10 +21,14 @@ use models::{
reshares::Reshare, reshares::Reshare,
users::* users::*
}; };
use utils;
#[get("/me")] #[get("/me")]
fn me(user: User) -> Redirect { fn me(user: Option<User>) -> Result<Redirect,Flash<Redirect>> {
Redirect::to(format!("/@/{}/", user.username).as_ref()) match user {
Some(user) => Ok(Redirect::to(format!("/@/{}/", user.username).as_ref())),
None => Err(utils::requires_login("", "/me"))
}
} }
#[get("/@/<name>", rank = 2)] #[get("/@/<name>", rank = 2)]
@ -83,6 +89,11 @@ fn follow(name: String, conn: DbConn, user: User) -> Redirect {
Redirect::to(format!("/@/{}/", name).as_ref()) Redirect::to(format!("/@/{}/", name).as_ref())
} }
#[get("/@/<name>/follow", rank = 2)]
fn follow_auth(name: String) -> Flash<Redirect> {
utils::requires_login("You need to belogged in order to follow someone", &format!("/@/{}/follow", name))
}
#[get("/@/<name>/followers", rank = 2)] #[get("/@/<name>/followers", rank = 2)]
fn followers(name: String, conn: DbConn, account: Option<User>) -> Template { fn followers(name: String, conn: DbConn, account: Option<User>) -> Template {
let user = User::find_by_fqn(&*conn, name.clone()).unwrap(); let user = User::find_by_fqn(&*conn, name.clone()).unwrap();
@ -125,6 +136,11 @@ fn edit(name: String, user: User) -> Option<Template> {
} }
} }
#[get("/@/<name>/edit", rank = 2)]
fn edit_auth(name: String) -> Flash<Redirect> {
utils::requires_login("You need to be logged in order to edit your profile", &format!("/@/{}/edit", name))
}
#[derive(FromForm)] #[derive(FromForm)]
struct UpdateUserForm { struct UpdateUserForm {
display_name: Option<String>, display_name: Option<String>,