Merge pull request #205 from lthms/recent_rocket

Update to a more recent rocket and rust toolchain
This commit is contained in:
Baptiste Gelez
2018-09-08 19:06:52 +01:00
committed by GitHub
17 changed files with 1096 additions and 736 deletions
+2 -1
View File
@@ -1,4 +1,4 @@
#![feature(custom_derive, decl_macro, plugin)]
#![feature(custom_derive, plugin, decl_macro)]
#![plugin(rocket_codegen)]
extern crate activitypub;
@@ -13,6 +13,7 @@ extern crate heck;
extern crate multipart;
extern crate plume_common;
extern crate plume_models;
#[macro_use]
extern crate rocket;
extern crate rocket_contrib;
extern crate rocket_csrf;
+4 -1
View File
@@ -65,7 +65,10 @@ fn new(user: User, conn: DbConn) -> 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", uri!(new))
utils::requires_login(
"You need to be logged in order to create a new blog",
uri!(new).into()
)
}
#[derive(FromForm, Validate, Serialize)]
+2 -2
View File
@@ -144,8 +144,8 @@ fn shared_inbox(conn: DbConn, data: String) -> String {
match instance.received(&*conn, act) {
Ok(_) => String::new(),
Err(e) => {
println!("Shared inbox error: {}\n{}", e.cause(), e.backtrace());
format!("Error: {}", e.cause())
println!("Shared inbox error: {}\n{}", e.as_fail(), e.backtrace());
format!("Error: {}", e.as_fail())
}
}
}
+4 -1
View File
@@ -40,5 +40,8 @@ fn create(blog: String, slug: String, user: User, conn: DbConn, worker: State<Po
#[post("/~/<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", uri!(create: blog = blog, slug = slug))
utils::requires_login(
"You need to be logged in order to like a post",
uri!(create: blog = blog, slug = slug).into()
)
}
+4 -1
View File
@@ -22,5 +22,8 @@ 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", uri!(notifications))
utils::requires_login(
"You need to be logged in order to see your notifications",
uri!(notifications).into()
)
}
+4 -1
View File
@@ -75,7 +75,10 @@ fn activity_details(blog: String, slug: String, conn: DbConn, _ap: ApRequest) ->
#[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", uri!(new: blog = blog))
utils::requires_login(
"You need to be logged in order to write a new post",
uri!(new: blog = blog).into()
)
}
#[get("/~/<blog>/new", rank = 1)]
+4 -1
View File
@@ -40,5 +40,8 @@ fn create(blog: String, slug: String, user: User, conn: DbConn, worker: State<Po
#[post("/~/<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", uri!(create: blog = blog, slug = slug))
utils::requires_login(
"You need to be logged in order to reshare a post",
uri!(create: blog = blog, slug = slug).into()
)
}
+21 -4
View File
@@ -4,6 +4,7 @@ use rocket::{
request::{LenientForm,FlashMessage}
};
use rocket_contrib::Template;
use rocket::http::ext::IntoOwned;
use std::borrow::Cow;
use validator::{Validate, ValidationError, ValidationErrors};
@@ -72,10 +73,26 @@ fn create(conn: DbConn, data: LenientForm<LoginForm>, flash: Option<FlashMessage
if errors.is_empty() {
cookies.add_private(Cookie::new(AUTH_COOKIE, user.unwrap().id.to_string()));
Ok(Redirect::to(Uri::new(flash
.and_then(|f| if f.name() == "callback" { Some(f.msg().to_owned()) } else { None })
.unwrap_or("/".to_owned()))
))
let destination = flash
.and_then(|f| if f.name() == "callback" {
Some(f.msg().to_owned())
} else {
None
})
.unwrap_or("/".to_owned());
let uri = Uri::parse(&destination)
.map(|x| x.into_owned())
.map_err(|_| {
Template::render("session/login", json!({
"account": null,
"errors": errors.inner(),
"form": form
}))
})?;
Ok(Redirect::to(uri))
} else {
println!("{:?}", errors);
Err(Template::render("session/login", json!({
+15 -6
View File
@@ -36,7 +36,7 @@ use Worker;
fn me(user: Option<User>) -> Result<Redirect, Flash<Redirect>> {
match user {
Some(user) => Ok(Redirect::to(uri!(details: name = user.username))),
None => Err(utils::requires_login("", uri!(me)))
None => Err(utils::requires_login("", uri!(me).into()))
}
}
@@ -111,7 +111,10 @@ 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", uri!(dashboard))
utils::requires_login(
"You need to be logged in order to access your dashboard",
uri!(dashboard).into()
)
}
#[get("/@/<name>/follow")]
@@ -136,7 +139,10 @@ fn follow(name: String, conn: DbConn, user: User, worker: Worker) -> Redirect {
#[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", uri!(follow: name = name))
utils::requires_login(
"You need to be logged in order to follow someone",
uri!(follow: name = name).into()
)
}
#[get("/@/<name>/followers?<page>")]
@@ -195,7 +201,10 @@ fn edit(name: String, user: User, conn: DbConn) -> 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", uri!(edit: name = name))
utils::requires_login(
"You need to be logged in order to edit your profile",
uri!(edit: name = name).into()
)
}
#[derive(FromForm)]
@@ -276,8 +285,8 @@ fn inbox(name: String, conn: DbConn, data: String) -> String {
match user.received(&*conn, act) {
Ok(_) => String::new(),
Err(e) => {
println!("User inbox error: {}\n{}", e.cause(), e.backtrace());
format!("Error: {}", e.cause())
println!("User inbox error: {}\n{}", e.as_fail(), e.backtrace());
format!("Error: {}", e.as_fail())
}
}
}
+1 -1
View File
@@ -170,7 +170,7 @@ fn quick_setup(conn: DbConn) {
.output()
.map(|o| String::from_utf8(o.stdout).expect("Invalid output from openssl"))
.expect("Couldn't generate secret key.");
write_to_dotenv("ROCKET_SECRET_KEY", key);
write_to_dotenv("ROCKET_SECRET_KEY", key);
create_admin(instance, conn);
}