From 4bd4bcbccb9e7772da337f30d9b62147877bc3d9 Mon Sep 17 00:00:00 2001 From: raven Date: Fri, 18 Jun 2021 21:10:57 +0000 Subject: view user profile at /user/ --- apioforum/__init__.py | 3 +++ apioforum/db.py | 4 ++++ apioforum/static/style.css | 11 +++++++++++ 3 files changed, 18 insertions(+) diff --git a/apioforum/__init__.py b/apioforum/__init__.py index 4283796..54d18c3 100644 --- a/apioforum/__init__.py +++ b/apioforum/__init__.py @@ -34,6 +34,9 @@ def create_app(): from . import admin app.register_blueprint(admin.bp) + from . import user + app.register_blueprint(user.bp) + from .fuzzy import fuzzy app.jinja_env.filters['fuzzy']=fuzzy diff --git a/apioforum/db.py b/apioforum/db.py index e1e8fa3..910118d 100644 --- a/apioforum/db.py +++ b/apioforum/db.py @@ -80,6 +80,10 @@ CREATE TABLE thread_tags ( """, """CREATE INDEX thread_tags_thread ON thread_tags (thread);""", """ALTER TABLE users ADD COLUMN admin INT NOT NULL DEFAULT 0""", +""" +ALTER TABLE users ADD COLUMN bio TEXT; +ALTER TABLE users ADD COLUMN joined TIMESTAMP; +""", ] def init_db(): diff --git a/apioforum/static/style.css b/apioforum/static/style.css index 935bde1..401fedb 100644 --- a/apioforum/static/style.css +++ b/apioforum/static/style.css @@ -43,6 +43,17 @@ body { font-family: sans-serif } font-size: .9rem; } +.user_info { + border: 1px solid black; + background-color: var(--alternating-colour-even); + width: 100%; + padding: 4px; +} +.user_bio_quote { width: max-content; } +.user_bio_attribution { text-align: right; } + +dt { font-weight: bold } + .un-col-1 { color: hsl(0, 100%, 30%) } .un-col-2 { color: hsl(22.5, 100%, 30%) } -- cgit v1.2.3 From a1cc107b3c65ff110124576d3609043f593a67f4 Mon Sep 17 00:00:00 2001 From: raven Date: Fri, 18 Jun 2021 21:13:56 +0000 Subject: actually add the files --- apioforum/templates/view_user.html | 22 ++++++++++++++++++++++ apioforum/user.py | 19 +++++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 apioforum/templates/view_user.html create mode 100644 apioforum/user.py diff --git a/apioforum/templates/view_user.html b/apioforum/templates/view_user.html new file mode 100644 index 0000000..c9d9c1c --- /dev/null +++ b/apioforum/templates/view_user.html @@ -0,0 +1,22 @@ +{% from 'common.html' import disp_post,ts %} +{% extends 'base.html' %} +{% block header %} +

{%block title %}{{user.username|e}}{% endblock %}

+{% endblock %} + +{%block content%} + +{% endblock %} diff --git a/apioforum/user.py b/apioforum/user.py new file mode 100644 index 0000000..cdf38d3 --- /dev/null +++ b/apioforum/user.py @@ -0,0 +1,19 @@ +# user pages + +from flask import ( + Blueprint, render_template, abort, g +) + +from .db import get_db +from .mdrender import render + +bp = Blueprint("user", __name__, url_prefix="/user") + +@bp.route("/") +def view_user(username): + db = get_db() + user = db.execute("SELECT * FROM users WHERE username = ?;",(username,)).fetchone() + if user is None: + abort(404) + return render_template("view_user.html", + user=user, rendered_bio=render(user['bio'] or "hail GEORGE")) -- cgit v1.2.3 From 8bf3a017837dfaae0210cfd0d7a7d75ae6a1d45c Mon Sep 17 00:00:00 2001 From: raven Date: Fri, 18 Jun 2021 21:24:00 +0000 Subject: make it actually record the join date --- apioforum/auth.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/apioforum/auth.py b/apioforum/auth.py index 80407eb..dae7b03 100644 --- a/apioforum/auth.py +++ b/apioforum/auth.py @@ -5,6 +5,7 @@ from flask import ( from werkzeug.security import check_password_hash, generate_password_hash from .db import get_db import functools +import datetime bp = Blueprint("auth", __name__, url_prefix="/auth") @@ -57,8 +58,8 @@ def register(): if err is None: db.execute( - "INSERT INTO users (username, password) VALUES (?,?);", - (username,generate_password_hash(password)) + "INSERT INTO users (username, password, joined) VALUES (?,?,?);", + (username,generate_password_hash(password),datetime.datetime.now()) ) db.commit() flash("successfully created account") -- cgit v1.2.3 From 4f75e30d9584566dca8f3c67a9451c22839d9da1 Mon Sep 17 00:00:00 2001 From: raven Date: Fri, 18 Jun 2021 21:38:54 +0000 Subject: recent posts --- apioforum/templates/view_user.html | 10 ++++++++++ apioforum/user.py | 8 +++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/apioforum/templates/view_user.html b/apioforum/templates/view_user.html index c9d9c1c..93618a5 100644 --- a/apioforum/templates/view_user.html +++ b/apioforum/templates/view_user.html @@ -19,4 +19,14 @@ {% endif %} +{% if posts %} +

recent posts

+
+ {% for post in posts %} + {% call disp_post(post, False) %} + {{ rendered_posts[loop.index0] | safe}} + {% endcall %} + {% endfor %} +
+{% endif %} {% endblock %} diff --git a/apioforum/user.py b/apioforum/user.py index cdf38d3..af0539a 100644 --- a/apioforum/user.py +++ b/apioforum/user.py @@ -15,5 +15,11 @@ def view_user(username): user = db.execute("SELECT * FROM users WHERE username = ?;",(username,)).fetchone() if user is None: abort(404) + posts = db.execute( + "SELECT * FROM posts WHERE author = ? ORDER BY created DESC LIMIT 25;",(username,)).fetchall() + rendered_posts = [render(post['content']) for post in posts] return render_template("view_user.html", - user=user, rendered_bio=render(user['bio'] or "hail GEORGE")) + user=user, + rendered_bio=render(user['bio'] or "hail GEORGE"), + posts=posts, + rendered_posts=rendered_posts) -- cgit v1.2.3 From f66dfff19be67a268fc36975a995e206cf41f91b Mon Sep 17 00:00:00 2001 From: citrons Date: Sat, 19 Jun 2021 08:03:09 +0000 Subject: user settings page, usernames link to user profiles --- apioforum/static/style.css | 14 +++++------- apioforum/templates/base.html | 10 ++++---- apioforum/templates/common.html | 7 +++++- apioforum/templates/user_settings.html | 26 +++++++++++++++++++++ apioforum/templates/view_forum.html | 6 ++--- apioforum/templates/view_user.html | 7 +++++- apioforum/user.py | 42 +++++++++++++++++++++++++++++++++- 7 files changed, 94 insertions(+), 18 deletions(-) create mode 100644 apioforum/templates/user_settings.html diff --git a/apioforum/static/style.css b/apioforum/static/style.css index 401fedb..d725165 100644 --- a/apioforum/static/style.css +++ b/apioforum/static/style.css @@ -1,4 +1,4 @@ -body { font-family: sans-serif } +body { font-family: sans-serif; word-wrap: break-word; } :root { --alternating-colour-even: hsl(0,0%,96%); @@ -16,10 +16,8 @@ body { font-family: sans-serif } } .post:last-of-type { border-bottom: 1px solid black; } -.post-heading { - color: hsl(0,0%,25%); - font-size: smaller; -} +.post-heading { font-size: smaller; } +.post-heading,.post-heading .username { color: hsl(0,0%,25%); } .post-heading-em { font-weight: bold; } .post-content * { margin-bottom: 8px; margin-top: 8px; } .post-content > *:first-child { margin-top: 2px } @@ -30,7 +28,7 @@ body { font-family: sans-serif } .post-anchor-link { color: hsl(0,0%,25%); } -.thread-top-bar { +.thread-top-bar, .user-top-bar { margin-bottom: 4px; } @@ -49,8 +47,8 @@ body { font-family: sans-serif } width: 100%; padding: 4px; } -.user_bio_quote { width: max-content; } -.user_bio_attribution { text-align: right; } +.user_bio_quote { width: max-content; max-width: 100% } +.user_bio_attribution { text-align: right; font-style: italic; } dt { font-weight: bold } diff --git a/apioforum/templates/base.html b/apioforum/templates/base.html index bf3748f..3eb112e 100644 --- a/apioforum/templates/base.html +++ b/apioforum/templates/base.html @@ -19,25 +19,25 @@

home

{% if g.user %} -

{{ g.user }}

+

{{g.user}}

{% if is_admin %}

admin

{% endif %}

- + logout

{% else %}

- + login

- + register

@@ -60,6 +60,8 @@ {% endblock %} + + diff --git a/apioforum/templates/common.html b/apioforum/templates/common.html index 2e59b2c..c484a9d 100644 --- a/apioforum/templates/common.html +++ b/apioforum/templates/common.html @@ -1,8 +1,13 @@ +{% macro disp_user(username) -%} +{{username}} +{%- endmacro %} + {% macro disp_post(post, buttons=False) %}
- {{post.author}} {{ts(post.created)}} + {{disp_user(post.author)}} + {{ts(post.created)}} {% if post.edited %} (edited {{ts(post.updated)}}) {% endif %} diff --git a/apioforum/templates/user_settings.html b/apioforum/templates/user_settings.html new file mode 100644 index 0000000..fdd447f --- /dev/null +++ b/apioforum/templates/user_settings.html @@ -0,0 +1,26 @@ +{% extends 'base.html' %} +{% block header %}

{% block title %}user settings{% endblock %}

{% endblock %} +{% block content %} +
+
+change password +

if you want to change your password, make sure you check the "change password?" box.

+ +
+ +
+ + +
+
+change bio +

if you want to change your bio, make sure you check the "change bio?" box.

+ +
+ +
+

confirm changes?

+ +cancel +
+{% endblock %} diff --git a/apioforum/templates/view_forum.html b/apioforum/templates/view_forum.html index 3edb7f0..59c594b 100644 --- a/apioforum/templates/view_forum.html +++ b/apioforum/templates/view_forum.html @@ -1,5 +1,5 @@ {% extends 'base.html' %} -{% from 'common.html' import ts, tag %} +{% from 'common.html' import ts, tag, disp_user %} {% block header %}

{% block title %}apioforum{%endblock%}

{%endblock%} {%block nmcontent%}
@@ -50,10 +50,10 @@ {{tag(the_tag)}} {% endfor %}
-
{{thread.creator}}
+
{{disp_user(thread.creator)}}
{{ts(thread.created)}}
{{ts(thread.updated)}}
-
{{thread.last_user}}
+
{{disp_user(thread.last_user)}}
{{thread.num_replies}}
{%endfor%} diff --git a/apioforum/templates/view_user.html b/apioforum/templates/view_user.html index 93618a5..f773978 100644 --- a/apioforum/templates/view_user.html +++ b/apioforum/templates/view_user.html @@ -5,6 +5,11 @@ {% endblock %} {%block content%} +
+ {% if g.user == user.username %} + settings + {% endif %} +