diff --git a/nerochan/models.py b/nerochan/models.py index 6618f2f..98b6b17 100644 --- a/nerochan/models.py +++ b/nerochan/models.py @@ -2,7 +2,7 @@ from os import path from datetime import datetime from secrets import token_urlsafe -from flask import url_for +from flask_login import login_user from PIL import Image, ImageSequence, ImageFilter from cv2 import VideoCapture @@ -52,6 +52,11 @@ class User(pw.Model): def regenerate_challenge(self): self.challenge = gen_challenge() self.save() + + def login(self): + login_user(self) + self.last_login_date = datetime.utcnow() + self.save() class Meta: database = db diff --git a/nerochan/routes/auth.py b/nerochan/routes/auth.py index d1ec624..1ca448e 100644 --- a/nerochan/routes/auth.py +++ b/nerochan/routes/auth.py @@ -1,6 +1,6 @@ from flask import Blueprint, render_template from flask import flash, redirect, url_for -from flask_login import login_user, logout_user, current_user +from flask_login import logout_user, current_user from nerochan.forms import UserForm, UserRegistration, UserChallenge from nerochan.helpers import make_wallet_rpc @@ -31,7 +31,7 @@ def register(): wallet_address=form.wallet_address.data, ) user.save() - login_user(user) + user.login() return redirect(url_for('main.index')) return render_template("auth/register.html", form=form) @@ -77,7 +77,7 @@ def challenge(handle): res = make_wallet_rpc('verify', data) if res['good']: user.regenerate_challenge() - login_user(user) + user.login() flash('Successful login!') return redirect(url_for('main.index')) else: diff --git a/nerochan/routes/user.py b/nerochan/routes/user.py index 3642e91..d72341d 100644 --- a/nerochan/routes/user.py +++ b/nerochan/routes/user.py @@ -1,7 +1,9 @@ -from flask import Blueprint, render_template, redirect, url_for, flash +from math import ceil + +from flask import Blueprint, render_template, redirect, url_for, flash, request from flask_login import login_required -from nerochan.models import User +from nerochan.models import User, Artwork, Transaction bp = Blueprint('user', 'user') @@ -16,9 +18,29 @@ def show(handle: str): if not user: flash('That user does not exist.', 'warning') return redirect(url_for('main.index')) + ipp = 20 + page = request.args.get("page", 1) + try: + page = int(page) + except: + flash('Invalid page number provided.', 'warning') + page = 1 + artwork = Artwork.select().where( + Artwork.user == user, + Artwork.approved == True, + Artwork.hidden == False + ).order_by(Artwork.upload_date.desc()) + # tips = Transaction.select().where( + # Transaction.verified == True, + # ) # need some join magic + paginated_posts = artwork.paginate(page, ipp) + total_pages = ceil(artwork.count() / ipp) return render_template( 'user/show.html', - user=user + user=user, + artwork=paginated_posts, + page=page, + total_pages=total_pages ) @bp.route('/profile') diff --git a/nerochan/templates/artwork/pending.html b/nerochan/templates/artwork/pending.html index ec489ee..3506fcc 100644 --- a/nerochan/templates/artwork/pending.html +++ b/nerochan/templates/artwork/pending.html @@ -14,7 +14,7 @@ {%- for _artwork in artwork | batch(4) %} {%- for art in _artwork %} - + {%- endfor %} {%- endfor %} diff --git a/nerochan/templates/user/show.html b/nerochan/templates/user/show.html index 3b1d604..448e405 100644 --- a/nerochan/templates/user/show.html +++ b/nerochan/templates/user/show.html @@ -3,10 +3,55 @@ {% block content %}
User details
+ADMIN
+ {% endif %} + {% if user.is_verified %} +VERIFIED
+ {% endif %} +There's nothing here yet...
+ {% endif %} +