Merge branch 'master' of github.com:Plume-org/Plume

This commit is contained in:
Bat 2018-09-08 20:32:12 +01:00
commit 0a70ff2594
17 changed files with 1096 additions and 736 deletions

1714
Cargo.lock generated

File diff suppressed because it is too large Load diff

View file

@ -3,10 +3,10 @@ authors = ["Bat' <baptiste@gelez.xyz>"]
name = "plume" name = "plume"
version = "0.1.0" version = "0.1.0"
[dependencies] [dependencies]
activitypub = "0.1.1" activitypub = "0.1.3"
atom_syndication = "0.6" atom_syndication = "0.6"
colored = "1.6" colored = "1.6"
dotenv = "*" dotenv = "0.13"
failure = "0.1" failure = "0.1"
gettext-rs = "0.4" gettext-rs = "0.4"
guid-create = "0.1" guid-create = "0.1"
@ -33,24 +33,24 @@ path = "plume-models"
[dependencies.rocket] [dependencies.rocket]
git = "https://github.com/SergioBenitez/Rocket" git = "https://github.com/SergioBenitez/Rocket"
rev = "df7111143e466c18d1f56377a8d9530a5a306aba" rev = "55459db7732b9a240826a5c120c650f87e3372ce"
[dependencies.rocket_codegen] [dependencies.rocket_codegen]
git = "https://github.com/SergioBenitez/Rocket" git = "https://github.com/SergioBenitez/Rocket"
rev = "df7111143e466c18d1f56377a8d9530a5a306aba" rev = "55459db7732b9a240826a5c120c650f87e3372ce"
[dependencies.rocket_contrib] [dependencies.rocket_contrib]
features = ["tera_templates", "json"] features = ["tera_templates", "json"]
git = "https://github.com/SergioBenitez/Rocket" git = "https://github.com/SergioBenitez/Rocket"
rev = "df7111143e466c18d1f56377a8d9530a5a306aba" rev = "55459db7732b9a240826a5c120c650f87e3372ce"
[dependencies.rocket_csrf] [dependencies.rocket_csrf]
git = "https://github.com/fdb-hiroshima/rocket_csrf" git = "https://github.com/fdb-hiroshima/rocket_csrf"
rev = "896fcaf14bd85b3f8266c0201e5f61937d05aec9" rev = "6fc55d26f91f057a20e89ece71d4443e797e7d21"
[dependencies.rocket_i18n] [dependencies.rocket_i18n]
git = "https://github.com/BaptisteGelez/rocket_i18n" git = "https://github.com/BaptisteGelez/rocket_i18n"
rev = "5b4225d5bed5769482dc926a7e6d6b79f1217be6" rev = "75a3bfd7b847324c078a355a7f101f8241a9f59b"
[workspace] [workspace]
members = ["plume-models", "plume-common"] members = ["plume-models", "plume-common"]

View file

@ -14,10 +14,10 @@ failure_derive = "0.1"
gettext-rs = "0.4" gettext-rs = "0.4"
heck = "0.3.0" heck = "0.3.0"
hex = "0.3" hex = "0.3"
hyper = "*" hyper = "0.11.27"
openssl = "0.10.6" openssl = "0.10.11"
reqwest = "0.8" reqwest = "0.8"
serde = "*" serde = "1.0"
serde_derive = "1.0" serde_derive = "1.0"
serde_json = "1.0" serde_json = "1.0"
@ -31,4 +31,4 @@ version = "0.1.2"
[dependencies.rocket] [dependencies.rocket]
git = "https://github.com/SergioBenitez/Rocket" git = "https://github.com/SergioBenitez/Rocket"
rev = "df7111143e466c18d1f56377a8d9530a5a306aba" rev = "55459db7732b9a240826a5c120c650f87e3372ce"

View file

@ -17,7 +17,7 @@ pub fn make_actor_id(name: String) -> String {
} }
pub fn requires_login(message: &str, url: Uri) -> Flash<Redirect> { 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()) Flash::new(Redirect::to(format!("/login?m={}", gettext(message.to_string()))), "callback", url.to_string())
} }
/// Returns (HTML, mentions) /// Returns (HTML, mentions)

View file

@ -5,13 +5,13 @@ authors = ["Baptiste Gelez <baptiste@gelez.xyz>"]
[dependencies] [dependencies]
activitypub = "0.1.1" activitypub = "0.1.1"
ammonia = "1.1.0" ammonia = "1.2.0"
bcrypt = "0.2" bcrypt = "0.2"
heck = "0.3.0" heck = "0.3.0"
lazy_static = "*" lazy_static = "*"
openssl = "0.10.6" openssl = "0.10.11"
reqwest = "0.8" reqwest = "0.8"
serde = "*" serde = "1.0"
serde_derive = "1.0" serde_derive = "1.0"
serde_json = "1.0" serde_json = "1.0"
url = "1.7" url = "1.7"
@ -23,11 +23,11 @@ version = "0.4"
[dependencies.diesel] [dependencies.diesel]
features = ["postgres", "r2d2", "chrono"] features = ["postgres", "r2d2", "chrono"]
version = "*" version = "1.3.2"
[dependencies.plume-common] [dependencies.plume-common]
path = "../plume-common" path = "../plume-common"
[dependencies.rocket] [dependencies.rocket]
git = "https://github.com/SergioBenitez/Rocket" git = "https://github.com/SergioBenitez/Rocket"
rev = "df7111143e466c18d1f56377a8d9530a5a306aba" rev = "55459db7732b9a240826a5c120c650f87e3372ce"

View file

@ -1,3 +1,5 @@
#![allow(proc_macro_derive_resolution_fallback)] // This can be removed after diesel-1.4
extern crate activitypub; extern crate activitypub;
extern crate ammonia; extern crate ammonia;
extern crate bcrypt; extern crate bcrypt;

View file

@ -1 +1 @@
nightly-2018-05-31 nightly-2018-07-17

View file

@ -1,4 +1,4 @@
#![feature(custom_derive, decl_macro, plugin)] #![feature(custom_derive, plugin, decl_macro)]
#![plugin(rocket_codegen)] #![plugin(rocket_codegen)]
extern crate activitypub; extern crate activitypub;
@ -13,6 +13,7 @@ extern crate heck;
extern crate multipart; extern crate multipart;
extern crate plume_common; extern crate plume_common;
extern crate plume_models; extern crate plume_models;
#[macro_use]
extern crate rocket; extern crate rocket;
extern crate rocket_contrib; extern crate rocket_contrib;
extern crate rocket_csrf; extern crate rocket_csrf;

View file

@ -65,7 +65,10 @@ fn new(user: User, conn: DbConn) -> Template {
#[get("/blogs/new", rank = 2)] #[get("/blogs/new", rank = 2)]
fn new_auth() -> Flash<Redirect>{ 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)] #[derive(FromForm, Validate, Serialize)]

View file

@ -170,8 +170,8 @@ fn shared_inbox(conn: DbConn, data: String) -> String {
match instance.received(&*conn, act) { match instance.received(&*conn, act) {
Ok(_) => String::new(), Ok(_) => String::new(),
Err(e) => { Err(e) => {
println!("Shared inbox error: {}\n{}", e.cause(), e.backtrace()); println!("Shared inbox error: {}\n{}", e.as_fail(), e.backtrace());
format!("Error: {}", e.cause()) format!("Error: {}", e.as_fail())
} }
} }
} }

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)] #[post("/~/<blog>/<slug>/like", rank = 2)]
fn create_auth(blog: String, slug: String) -> Flash<Redirect>{ 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()
)
} }

View file

@ -22,5 +22,8 @@ fn notifications(conn: DbConn, user: User) -> Template {
#[get("/notifications", rank = 2)] #[get("/notifications", rank = 2)]
fn notifications_auth() -> Flash<Redirect>{ 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()
)
} }

View file

@ -75,7 +75,10 @@ fn activity_details(blog: String, slug: String, conn: DbConn, _ap: ApRequest) ->
#[get("/~/<blog>/new", rank = 2)] #[get("/~/<blog>/new", rank = 2)]
fn new_auth(blog: String) -> Flash<Redirect> { 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)] #[get("/~/<blog>/new", rank = 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)] #[post("/~/<blog>/<slug>/reshare", rank=1)]
fn create_auth(blog: String, slug: String) -> Flash<Redirect> { 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()
)
} }

View file

@ -4,6 +4,7 @@ use rocket::{
request::{LenientForm,FlashMessage} request::{LenientForm,FlashMessage}
}; };
use rocket_contrib::Template; use rocket_contrib::Template;
use rocket::http::ext::IntoOwned;
use std::borrow::Cow; use std::borrow::Cow;
use validator::{Validate, ValidationError, ValidationErrors}; use validator::{Validate, ValidationError, ValidationErrors};
@ -72,10 +73,26 @@ fn create(conn: DbConn, data: LenientForm<LoginForm>, flash: Option<FlashMessage
if errors.is_empty() { if errors.is_empty() {
cookies.add_private(Cookie::new(AUTH_COOKIE, user.unwrap().id.to_string())); 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 }) let destination = flash
.unwrap_or("/".to_owned())) .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 { } else {
println!("{:?}", errors); println!("{:?}", errors);
Err(Template::render("session/login", json!({ Err(Template::render("session/login", json!({

View file

@ -36,7 +36,7 @@ use Worker;
fn me(user: Option<User>) -> Result<Redirect, Flash<Redirect>> { fn me(user: Option<User>) -> Result<Redirect, Flash<Redirect>> {
match user { match user {
Some(user) => Ok(Redirect::to(uri!(details: name = user.username))), 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)] #[get("/dashboard", rank = 2)]
fn dashboard_auth() -> Flash<Redirect> { 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")] #[get("/@/<name>/follow")]
@ -136,7 +139,10 @@ fn follow(name: String, conn: DbConn, user: User, worker: Worker) -> Redirect {
#[get("/@/<name>/follow", rank = 2)] #[get("/@/<name>/follow", rank = 2)]
fn follow_auth(name: String) -> Flash<Redirect> { 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>")] #[get("/@/<name>/followers?<page>")]
@ -195,7 +201,10 @@ fn edit(name: String, user: User, conn: DbConn) -> Option<Template> {
#[get("/@/<name>/edit", rank = 2)] #[get("/@/<name>/edit", rank = 2)]
fn edit_auth(name: String) -> Flash<Redirect> { 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)] #[derive(FromForm)]
@ -276,8 +285,8 @@ fn inbox(name: String, conn: DbConn, data: String) -> String {
match user.received(&*conn, act) { match user.received(&*conn, act) {
Ok(_) => String::new(), Ok(_) => String::new(),
Err(e) => { Err(e) => {
println!("User inbox error: {}\n{}", e.cause(), e.backtrace()); println!("User inbox error: {}\n{}", e.as_fail(), e.backtrace());
format!("Error: {}", e.cause()) format!("Error: {}", e.as_fail())
} }
} }
} }