Add a dashboard
This commit is contained in:
parent
7a3215edaa
commit
edbeeef640
|
@ -1,6 +1,5 @@
|
||||||
use activitypub::{
|
use activitypub::{
|
||||||
Actor,
|
Actor,
|
||||||
actor::Person,
|
|
||||||
activity::{Accept, Announce, Create, Follow, Like, Undo},
|
activity::{Accept, Announce, Create, Follow, Like, Undo},
|
||||||
object::Note
|
object::Note
|
||||||
};
|
};
|
||||||
|
|
|
@ -104,6 +104,8 @@ fn main() {
|
||||||
|
|
||||||
routes::user::me,
|
routes::user::me,
|
||||||
routes::user::details,
|
routes::user::details,
|
||||||
|
routes::user::dashboard,
|
||||||
|
routes::user::dashboard_auth,
|
||||||
routes::user::followers,
|
routes::user::followers,
|
||||||
routes::user::edit,
|
routes::user::edit,
|
||||||
routes::user::edit_auth,
|
routes::user::edit_auth,
|
||||||
|
|
|
@ -7,7 +7,7 @@ use reqwest::{
|
||||||
use serde_json;
|
use serde_json;
|
||||||
use url::Url;
|
use url::Url;
|
||||||
use chrono::NaiveDateTime;
|
use chrono::NaiveDateTime;
|
||||||
use diesel::{self, QueryDsl, RunQueryDsl, ExpressionMethods, PgConnection};
|
use diesel::{self, QueryDsl, RunQueryDsl, ExpressionMethods, PgConnection, dsl::any};
|
||||||
use openssl::{
|
use openssl::{
|
||||||
hash::MessageDigest,
|
hash::MessageDigest,
|
||||||
pkey::{PKey, Private},
|
pkey::{PKey, Private},
|
||||||
|
@ -71,6 +71,14 @@ impl Blog {
|
||||||
.into_iter().nth(0)
|
.into_iter().nth(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn find_for_author(conn: &PgConnection, author_id: i32) -> Vec<Blog> {
|
||||||
|
use schema::blog_authors;
|
||||||
|
let author_ids = blog_authors::table.filter(blog_authors::author_id.eq(author_id)).select(blog_authors::blog_id);
|
||||||
|
blogs::table.filter(blogs::id.eq(any(author_ids)))
|
||||||
|
.load::<Blog>(conn)
|
||||||
|
.expect("Couldn't load blogs ")
|
||||||
|
}
|
||||||
|
|
||||||
pub fn find_by_name(conn: &PgConnection, name: String, instance_id: i32) -> Option<Blog> {
|
pub fn find_by_name(conn: &PgConnection, name: String, instance_id: i32) -> Option<Blog> {
|
||||||
blogs::table.filter(blogs::actor_id.eq(name))
|
blogs::table.filter(blogs::actor_id.eq(name))
|
||||||
.filter(blogs::instance_id.eq(instance_id))
|
.filter(blogs::instance_id.eq(instance_id))
|
||||||
|
|
|
@ -15,6 +15,7 @@ use activity_pub::{
|
||||||
};
|
};
|
||||||
use db_conn::DbConn;
|
use db_conn::DbConn;
|
||||||
use models::{
|
use models::{
|
||||||
|
blogs::Blog,
|
||||||
follows,
|
follows,
|
||||||
instance::Instance,
|
instance::Instance,
|
||||||
posts::Post,
|
posts::Post,
|
||||||
|
@ -74,6 +75,20 @@ fn details(name: String, conn: DbConn, account: Option<User>) -> Template {
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[get("/dashboard")]
|
||||||
|
fn dashboard(user: User, conn: DbConn) -> Template {
|
||||||
|
let blogs = Blog::find_for_author(&*conn, user.id);
|
||||||
|
Template::render("users/dashboard", json!({
|
||||||
|
"account": user,
|
||||||
|
"blogs": blogs
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
|
||||||
|
#[get("/dashboard", rank = 2)]
|
||||||
|
fn dashboard_auth() -> Flash<Redirect> {
|
||||||
|
utils::requires_login("You need to be logged in order to access your dashboard", "/dashboard")
|
||||||
|
}
|
||||||
|
|
||||||
#[get("/@/<name>/follow")]
|
#[get("/@/<name>/follow")]
|
||||||
fn follow(name: String, conn: DbConn, user: User) -> Redirect {
|
fn follow(name: String, conn: DbConn, user: User) -> Redirect {
|
||||||
let target = User::find_by_fqn(&*conn, name.clone()).unwrap();
|
let target = User::find_by_fqn(&*conn, name.clone()).unwrap();
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
</nav>
|
</nav>
|
||||||
<nav>
|
<nav>
|
||||||
{% if account %}
|
{% if account %}
|
||||||
|
<a href="/dashboard">Dashboard</a>
|
||||||
<a href="/notifications">Notifications</a>
|
<a href="/notifications">Notifications</a>
|
||||||
<a href="/me">My account</a>
|
<a href="/me">My account</a>
|
||||||
<a href="/logout">Log Out</a>
|
<a href="/logout">Log Out</a>
|
||||||
|
|
|
@ -0,0 +1,25 @@
|
||||||
|
{% extends "base" %}
|
||||||
|
{% import "macros" as macros %}
|
||||||
|
|
||||||
|
{% block title %}
|
||||||
|
Dashboard
|
||||||
|
{% endblock title %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
<h1>Your Dashboard</h1>
|
||||||
|
|
||||||
|
<section>
|
||||||
|
<h2>Your Blogs</h2>
|
||||||
|
{% if blogs | length < 1 %}
|
||||||
|
<p>You don't have any blog yet. Create your own, or ask to join one.</p>
|
||||||
|
{% endif %}
|
||||||
|
<a class="button inline-block" href="/blogs/new">Start a new blog</a>
|
||||||
|
<div class="list">
|
||||||
|
{% for blog in blogs %}
|
||||||
|
<div class="card">
|
||||||
|
<h3><a href="/~/{{ blog.actor_id }}/">{{ blog.title }}</a></h3>
|
||||||
|
</div>
|
||||||
|
{% endfor %}
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
{% endblock content %}
|
Loading…
Reference in New Issue