mirror of
https://git.joinplu.me/Plume/Plume.git
synced 2024-12-24 02:50:37 +00:00
Use uri! as much as possible instead of directly writing URLs
This commit is contained in:
parent
db248701b9
commit
8ab25b1ca2
8 changed files with 22 additions and 24 deletions
|
@ -46,7 +46,7 @@ fn new(user: User) -> Template {
|
|||
|
||||
#[get("/blogs/new", rank = 2)]
|
||||
fn new_auth() -> Flash<Redirect>{
|
||||
utils::requires_login("You need to be logged in order to create a new blog", "/blogs/new")
|
||||
utils::requires_login("You need to be logged in order to create a new blog", uri!(new))
|
||||
}
|
||||
|
||||
#[derive(FromForm)]
|
||||
|
@ -58,10 +58,8 @@ struct NewBlogForm {
|
|||
fn create(conn: DbConn, data: Form<NewBlogForm>, user: User) -> Redirect {
|
||||
let form = data.get();
|
||||
let slug = utils::make_actor_id(form.title.to_string());
|
||||
if slug.len() == 0 {
|
||||
return Redirect::to("/blogs/new")
|
||||
}
|
||||
if Blog::find_local(&*conn, slug.clone()).is_some() {
|
||||
|
||||
if Blog::find_local(&*conn, slug.clone()).is_some() || slug.len() == 0 {
|
||||
Redirect::to(uri!(new))
|
||||
} else {
|
||||
let blog = Blog::insert(&*conn, NewBlog::new_local(
|
||||
|
@ -78,7 +76,7 @@ fn create(conn: DbConn, data: Form<NewBlogForm>, user: User) -> Redirect {
|
|||
is_owner: true
|
||||
});
|
||||
|
||||
Redirect::to(format!("/~/{}/", slug))
|
||||
Redirect::to(uri!(details: name = slug))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -30,7 +30,7 @@ fn new(blog: String, slug: String, user: User, conn: DbConn) -> Template {
|
|||
|
||||
#[get("/~/<blog>/<slug>/comment", rank=2)]
|
||||
fn new_auth(blog: String, slug: String) -> Flash<Redirect>{
|
||||
utils::requires_login("You need to be logged in order to post a comment", &format!("~/{}/{}/comment", blog, slug))
|
||||
utils::requires_login("You need to be logged in order to post a comment", uri!(new: blog = blog, slug = slug))
|
||||
}
|
||||
|
||||
#[derive(FromForm)]
|
||||
|
|
|
@ -32,10 +32,10 @@ fn create(blog: String, slug: String, user: User, conn: DbConn) -> Redirect {
|
|||
broadcast(&*conn, &user, delete_act, user.get_followers(&*conn));
|
||||
}
|
||||
|
||||
Redirect::to(format!("/~/{}/{}/", blog, slug))
|
||||
Redirect::to(uri!(super::posts::details: blog = blog, slug = slug))
|
||||
}
|
||||
|
||||
#[get("/~/<blog>/<slug>/like", rank = 2)]
|
||||
fn create_auth(blog: String, slug: String) -> Flash<Redirect>{
|
||||
utils::requires_login("You need to be logged in order to like a post", &format!("/~/{}/{}/like", blog, slug))
|
||||
utils::requires_login("You need to be logged in order to like a post", uri!(create: blog = blog, slug = slug))
|
||||
}
|
||||
|
|
|
@ -16,5 +16,5 @@ fn notifications(conn: DbConn, user: User) -> Template {
|
|||
|
||||
#[get("/notifications", rank = 2)]
|
||||
fn notifications_auth() -> Flash<Redirect>{
|
||||
utils::requires_login("You need to be logged in order to see your notifications", "/notifications")
|
||||
utils::requires_login("You need to be logged in order to see your notifications", uri!(notifications))
|
||||
}
|
||||
|
|
|
@ -51,7 +51,7 @@ fn activity_details(blog: String, slug: String, conn: DbConn) -> ActivityPub {
|
|||
|
||||
#[get("/~/<blog>/new", rank = 2)]
|
||||
fn new_auth(blog: String) -> Flash<Redirect> {
|
||||
utils::requires_login("You need to be logged in order to write a new post", &format!("/~/{}/new",blog))
|
||||
utils::requires_login("You need to be logged in order to write a new post", uri!(new: blog = blog))
|
||||
}
|
||||
|
||||
#[get("/~/<blog>/new", rank = 1)]
|
||||
|
@ -110,6 +110,6 @@ fn create(blog_name: String, data: Form<NewPostForm>, user: User, conn: DbConn)
|
|||
let act = post.create_activity(&*conn);
|
||||
broadcast(&*conn, &user, act, user.get_followers(&*conn));
|
||||
|
||||
Redirect::to(format!("/~/{}/{}/", blog_name, slug))
|
||||
Redirect::to(uri!(details: blog = blog_name, slug = slug))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,10 +32,10 @@ fn create(blog: String, slug: String, user: User, conn: DbConn) -> Redirect {
|
|||
broadcast(&*conn, &user, delete_act, user.get_followers(&*conn));
|
||||
}
|
||||
|
||||
Redirect::to(format!("/~/{}/{}/", blog, slug))
|
||||
Redirect::to(uri!(super::posts::details: blog = blog, slug = slug))
|
||||
}
|
||||
|
||||
#[get("/~/<blog>/<slug>/reshare", rank=1)]
|
||||
fn create_auth(blog: String, slug: String) -> Flash<Redirect> {
|
||||
utils::requires_login("You need to be logged in order to reshare a post", &format!("/~/{}/{}/reshare",blog, slug))
|
||||
utils::requires_login("You need to be logged in order to reshare a post", uri!(create: blog = blog, slug = slug))
|
||||
}
|
||||
|
|
|
@ -27,8 +27,8 @@ use utils;
|
|||
#[get("/me")]
|
||||
fn me(user: Option<User>) -> Result<Redirect, Flash<Redirect>> {
|
||||
match user {
|
||||
Some(user) => Ok(Redirect::to(format!("/@/{}/", user.username))),
|
||||
None => Err(utils::requires_login("", "/me"))
|
||||
Some(user) => Ok(Redirect::to(uri!(details: name = user.username))),
|
||||
None => Err(utils::requires_login("", uri!(me)))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -65,7 +65,7 @@ fn dashboard(user: User, conn: DbConn) -> Template {
|
|||
|
||||
#[get("/dashboard", rank = 2)]
|
||||
fn dashboard_auth() -> Flash<Redirect> {
|
||||
utils::requires_login("You need to be logged in order to access your dashboard", "/dashboard")
|
||||
utils::requires_login("You need to be logged in order to access your dashboard", uri!(dashboard))
|
||||
}
|
||||
|
||||
#[get("/@/<name>/follow")]
|
||||
|
@ -82,12 +82,12 @@ fn follow(name: String, conn: DbConn, user: User) -> Redirect {
|
|||
|
||||
follows::Follow::notify(&*conn, act.clone(), user.clone().into_id());
|
||||
broadcast(&*conn, &user, act, vec![target]);
|
||||
Redirect::to(format!("/@/{}/", name))
|
||||
Redirect::to(uri!(details: name = name))
|
||||
}
|
||||
|
||||
#[get("/@/<name>/follow", rank = 2)]
|
||||
fn follow_auth(name: String) -> Flash<Redirect> {
|
||||
utils::requires_login("You need to be logged in order to follow someone", &format!("/@/{}/follow", name))
|
||||
utils::requires_login("You need to be logged in order to follow someone", uri!(follow: name = name))
|
||||
}
|
||||
|
||||
#[get("/@/<name>/followers", rank = 2)]
|
||||
|
@ -134,7 +134,7 @@ 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))
|
||||
utils::requires_login("You need to be logged in order to edit your profile", uri!(edit: name = name))
|
||||
}
|
||||
|
||||
#[derive(FromForm)]
|
||||
|
@ -151,7 +151,7 @@ fn update(_name: String, conn: DbConn, user: User, data: Form<UpdateUserForm>) -
|
|||
data.get().email.clone().unwrap_or(user.email.clone().unwrap()).to_string(),
|
||||
data.get().summary.clone().unwrap_or(user.summary.to_string())
|
||||
);
|
||||
Redirect::to("/me")
|
||||
Redirect::to(uri!(me))
|
||||
}
|
||||
|
||||
#[derive(FromForm)]
|
||||
|
@ -183,7 +183,7 @@ fn create(conn: DbConn, data: Form<NewUserForm>) -> Result<Redirect, String> {
|
|||
User::hash_pass(form.password.to_string()),
|
||||
inst.id
|
||||
)).update_boxes(&*conn);
|
||||
Ok(Redirect::to(format!("/@/{}/", data.get().username)))
|
||||
Ok(Redirect::to(uri!(super::session::new)))
|
||||
} else {
|
||||
Err(String::from("Passwords don't match"))
|
||||
}
|
||||
|
|
|
@ -15,6 +15,6 @@ pub fn make_actor_id(name: String) -> String {
|
|||
.collect()
|
||||
}
|
||||
|
||||
pub fn requires_login(message: &str, url: &str) -> Flash<Redirect> {
|
||||
Flash::new(Redirect::to(Uri::new(format!("/login?m={}", gettext(message.to_string())))), "callback", url)
|
||||
pub fn requires_login(message: &str, url: Uri) -> Flash<Redirect> {
|
||||
Flash::new(Redirect::to(Uri::new(format!("/login?m={}", gettext(message.to_string())))), "callback", url.as_str())
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue