gourami

[UNMAINTAINED] Activitypub server in Rust
Log | Files | Refs | README | LICENSE

commit dcdb036154b9420d3399fc91545a6b711ff71720
parent e1c7c719a89a6dc255edadd05fade192dd00445e
Author: alex wennerberg <alex@alexwennerberg.com>
Date:   Fri,  5 Jun 2020 15:33:18 -0500

Add website and fix some people

Diffstat:
Mmigrations/2020-04-13-014917_initialize/up.sql | 1+
Msrc/db/schema.rs | 1+
Msrc/db/user.rs | 1+
Msrc/lib.rs | 2++
Asrc/schema.rs | 74++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mtemplates/base.html | 2+-
Mtemplates/edit_user.html | 5++++-
Mtemplates/server_info.html | 19+------------------
Dtemplates/user.html | 4----
Mtemplates/user_header.html | 4+++-
10 files changed, 88 insertions(+), 25 deletions(-)

diff --git a/migrations/2020-04-13-014917_initialize/up.sql b/migrations/2020-04-13-014917_initialize/up.sql @@ -4,6 +4,7 @@ CREATE TABLE users ( id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, username VARCHAR(255), email VARCHAR(255), + website VARCHAR(255) default "", bio VARCHAR(1023) default "New here!", created_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP , password VARCHAR(255), diff --git a/src/db/schema.rs b/src/db/schema.rs @@ -22,6 +22,7 @@ table! { id -> Integer, username -> Varchar, email -> Nullable<Varchar>, + website -> Varchar, bio -> Text, created_time -> Timestamp, password -> Nullable<Varchar>, diff --git a/src/db/user.rs b/src/db/user.rs @@ -46,6 +46,7 @@ pub struct User { pub id: i32, pub username: String, pub email: Option<String>, // TODO option + pub website: String, // TODO option pub bio: String, pub created_time: String, pub password: Option<String>, diff --git a/src/lib.rs b/src/lib.rs @@ -571,6 +571,7 @@ pub async fn post_inbox( struct EditForm { redirect_url: String, bio: String, + website: String, show_email: Option<String>, email: String, } @@ -584,6 +585,7 @@ fn edit_user(user: Option<User>, user_name: String, f: EditForm) -> impl Reply { .set(( bio.eq(&f.bio), email.eq(&f.email), + website.eq(&f.website), show_email.eq(&f.show_email.is_some()), )) .execute(conn) diff --git a/src/schema.rs b/src/schema.rs @@ -0,0 +1,74 @@ +table! { + activities (id) { + id -> Integer, + json_text -> Nullable<Text>, + } +} + +table! { + notes (id) { + id -> Integer, + user_id -> Nullable<Integer>, + content -> Nullable<Text>, + created_time -> Nullable<Timestamp>, + in_reply_to -> Nullable<Binary>, + neighborhood -> Nullable<Bool>, + is_remote -> Nullable<Bool>, + remote_url -> Nullable<Text>, + remote_creator -> Nullable<Text>, + remote_id -> Nullable<Text>, + } +} + +table! { + registration_keys (value) { + value -> Nullable<Text>, + } +} + +table! { + server_mutuals (id) { + id -> Nullable<Integer>, + actor_id -> Nullable<Text>, + inbox_url -> Nullable<Text>, + accepted -> Nullable<Bool>, + followed_back -> Nullable<Bool>, + outbox_url -> Nullable<Text>, + } +} + +table! { + sessions (id) { + id -> Integer, + cookie -> Text, + user_id -> Integer, + created_time -> Nullable<Timestamp>, + } +} + +table! { + users (id) { + id -> Integer, + username -> Nullable<Text>, + email -> Nullable<Text>, + website -> Nullable<Text>, + bio -> Nullable<Text>, + created_time -> Nullable<Timestamp>, + password -> Nullable<Text>, + admin -> Nullable<Bool>, + show_email -> Nullable<Bool>, + remote_user -> Nullable<Bool>, + } +} + +joinable!(notes -> users (user_id)); +joinable!(sessions -> users (user_id)); + +allow_tables_to_appear_in_same_query!( + activities, + notes, + registration_keys, + server_mutuals, + sessions, + users, +); diff --git a/templates/base.html b/templates/base.html @@ -27,7 +27,7 @@ <a href="/">local</a>{% endif %} <a href="/?neighborhood=true">neighborhood</a> {% if global.logged_in %} <a href="/?search_string={{global.me.username}}&all=true">mentions</a> {% endif %} <a href="/server_info">server</a> {% if global.logged_in %} <a - href="/?user_id={{global.me.id}}">@{{global.me.username}}</a>{% else %} <a href="login">login</a>{% endif %} + href="/?user_id={{global.me.id}}">@{{global.me.username}}</a>{% else %} <a href="/register">register</a> <a href="login">login</a>{% endif %} </div> </div> <div class="padded main-content"> diff --git a/templates/edit_user.html b/templates/edit_user.html @@ -15,6 +15,9 @@ ""> {%endmatch%} <br> +<label for="bio"><b>website:</b></label> +<input class="basic-input" type="text" id="website" name="website" value="{{user.website}}"> +<br> <label for="show_email"><b>show_email?</b></label> <input type="checkbox" id="show_email" name="show_email" {% if user.show_email %} @@ -22,7 +25,7 @@ checked> {% else %} unchecked> {% endif %} -<input type="hidden" name="redirect_url" value="/user/{{user.username}}"> +<input type="hidden" name="redirect_url" value="/?user_id={{user.id}}"> <br> <button id="post" class="submit-button-style">submit</button> </form> diff --git a/templates/server_info.html b/templates/server_info.html @@ -17,25 +17,8 @@ Here is a list of users on this server -- maybe introduce yourself to someone you don't know! By default your email is not shared, but you can share it to other users on this instance on your edit user page. <br> -<table> -<tr> - <th>username</th> - <th>email</th> - <th>bio</th> -</tr> {% for user in users %} -<tr> - <td><a href="/user/{{user.username}}">{{user.username}}</a> {%if user.admin %}<em>admin</em>{%endif%}</td> - <td> - {% match user.email %} - {% when Some with (e) %} - {% if user.show_email %} - <a href="mailto:{{e}}">{{e}}</a></td> - {% endif %} - {% when None %} - {%endmatch%} - <td>{{user.bio}}</td> -</tr> +{% include "user_header.html" %} {% endfor %} </div> </table> diff --git a/templates/user.html b/templates/user.html @@ -1,4 +0,0 @@ -{% extends "base.html" %} -% include "noteslist.html" %} -</div> -{% endblock %} diff --git a/templates/user_header.html b/templates/user_header.html @@ -7,10 +7,11 @@ {%when Some with (e) %} {%if user.show_email%} <br> - <b>email:</b> <a href="mailto:{{e}}">{{e}}</a> + <b>email:</b> <a href="mailto:{{e}}">{{e}}</a><br> {%endif %} {% when None %} {%endmatch%} + <b>website:</b> <a href="{{user.website}}">{{user.website}}</a> {% if global.me.id == user.id%} <br> <a href="/user/{{user.username}}/edit">edit</a> @@ -20,4 +21,5 @@ class="link-button">logout</button></form> </div> {% endif %} + <br><br> </div>