fix redirection to login in src/routes/user.rs
This commit is contained in:
parent
b88ee53188
commit
3dcd78f205
|
@ -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,
|
||||
|
|
|
@ -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<User>) -> Result<Redirect,Flash<Redirect>> {
|
||||
match user {
|
||||
Some(user) => Ok(Redirect::to(format!("/@/{}/", user.username).as_ref())),
|
||||
None => Err(utils::requires_login("", "/me"))
|
||||
}
|
||||
}
|
||||
|
||||
#[get("/@/<name>", rank = 2)]
|
||||
|
@ -83,6 +89,11 @@ fn follow(name: String, conn: DbConn, user: User) -> Redirect {
|
|||
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)]
|
||||
fn followers(name: String, conn: DbConn, account: Option<User>) -> Template {
|
||||
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)]
|
||||
struct UpdateUserForm {
|
||||
display_name: Option<String>,
|
||||
|
|
Loading…
Reference in New Issue