users now have anonymous username option

This commit is contained in:
crunk 2022-03-18 14:58:30 +01:00
parent 6a475024d3
commit 6507b05c64
7 changed files with 35 additions and 15 deletions

View File

@ -7,7 +7,7 @@ class Distribusis(db.Model):
__tablename__ = "distribusis" __tablename__ = "distribusis"
id = db.Column(db.Integer, primary_key=True) id = db.Column(db.Integer, primary_key=True)
distribusiname = db.Column(db.String(300), nullable=True, unique=True) distribusiname = db.Column(db.String(300), nullable=False, unique=True)
userid = db.Column(db.Integer, db.ForeignKey("users.id")) userid = db.Column(db.Integer, db.ForeignKey("users.id"))
term = db.Column(db.String(5), nullable=False, unique=False) term = db.Column(db.String(5), nullable=False, unique=False)
course = db.Column(db.String(500), nullable=True, unique=False) course = db.Column(db.String(500), nullable=True, unique=False)
@ -15,6 +15,8 @@ class Distribusis(db.Model):
# Academic year eg:2020-2021, so no need for a Datetime object # Academic year eg:2020-2021, so no need for a Datetime object
year = db.Column(db.String(9), nullable=True, unique=False) year = db.Column(db.String(9), nullable=True, unique=False)
tags = db.Column(db.String(500), nullable=True, unique=False) tags = db.Column(db.String(500), nullable=True, unique=False)
publictheme = db.Column(db.String(300), unique=True, nullable=True)
visible = db.Column(db.Boolean, default=False) visible = db.Column(db.Boolean, default=False)
def __repr__(self): def __repr__(self):

View File

@ -12,6 +12,10 @@ from flask_wtf import FlaskForm
class RegisterForm(FlaskForm): class RegisterForm(FlaskForm):
"""Register for distribusi-verse form class""" """Register for distribusi-verse form class"""
username = StringField(
"Username:",
validators=[validators.InputRequired(), Length(6, 150)],
)
email = StringField( email = StringField(
"Email address:", "Email address:",

View File

@ -4,7 +4,6 @@ import zipfile
import shutil import shutil
from datetime import timedelta from datetime import timedelta
from flask import ( from flask import (
render_template, render_template,
redirect, redirect,
@ -32,20 +31,24 @@ from forms.editorform import EditorForm
from forms.selectorform import SelectorForm from forms.selectorform import SelectorForm
# CRUD! # CRUD!
from selector import SelectNewDistribusi from selector import (
from selector import SelectUpdateDistribusi SelectNewDistribusi,
from selector import DeleteDistribusi SelectUpdateDistribusi,
from selector import SelectorVisible DeleteDistribusi,
SelectorVisible,
)
# Upload # Upload
from upload import UploadNewDistribusi from upload import UploadNewDistribusi, UploadUpdatedFiles
from upload import UploadUpdatedFiles
# UserPengguna # UserPengguna
from statuspengguna.helper import IsZipUploaded from statuspengguna.helper import (
from statuspengguna.helper import IsCssSelected IsZipUploaded,
from statuspengguna.helper import CurrentDistribusi IsCssSelected,
from statuspengguna.helper import ResetUserState CurrentDistribusi,
HasDistribusi,
ResetUserState,
)
from statuspengguna.loginuser import LoginUser from statuspengguna.loginuser import LoginUser
from statuspengguna.registeruser import RegisterUser from statuspengguna.registeruser import RegisterUser
@ -73,7 +76,7 @@ def index():
for distribusi in distribusis: for distribusi in distribusis:
user = User.query.filter_by(id=distribusi.userid).first() user = User.query.filter_by(id=distribusi.userid).first()
singledistribusi = { singledistribusi = {
"useremail": user.email, "username": user.username,
"term": distribusi.term, "term": distribusi.term,
"course": distribusi.course, "course": distribusi.course,
"year": distribusi.year, "year": distribusi.year,
@ -160,7 +163,7 @@ def upload():
selectorvisible = SelectorVisible() selectorvisible = SelectorVisible()
current_distribusi = CurrentDistribusi() current_distribusi = CurrentDistribusi()
if current_distribusi == "new": if current_distribusi == "new" or HasDistribusi() == False:
uploadform = UploadNewDistribusi(APP.config["UPLOAD_FOLDER"]) uploadform = UploadNewDistribusi(APP.config["UPLOAD_FOLDER"])
else: else:
uploadform = UploadUpdatedFiles(APP.config["UPLOAD_FOLDER"]) uploadform = UploadUpdatedFiles(APP.config["UPLOAD_FOLDER"])

View File

@ -23,10 +23,12 @@ def RegisterUser():
registerform = RegisterForm() registerform = RegisterForm()
if registerform.validate_on_submit(): if registerform.validate_on_submit():
try: try:
username = registerform.username.data
email = registerform.email.data email = registerform.email.data
password = registerform.confirmpassword.data password = registerform.confirmpassword.data
newuser = User( newuser = User(
username=username,
email=email, email=email,
password=generate_password_hash(password), password=generate_password_hash(password),
) )

View File

@ -46,7 +46,7 @@
<ul> <ul>
{% for name, distribusi in distribusies.items() %} {% for name, distribusi in distribusies.items() %}
<li class='distribusi filter {{ distribusi["term"] }} {{ distribusi["year"] }} {{ distribusi["course"] }}'> <li class='distribusi filter {{ distribusi["term"] }} {{ distribusi["year"] }} {{ distribusi["course"] }}'>
<a href='stash/{{name}}/index.html'>{{distribusi["useremail"]}}:{{name}}</a> <a href='stash/{{name}}/index.html'>{{distribusi["username"]}}:{{name}}</a>
{% for tag in distribusi["tags"] %} {% for tag in distribusi["tags"] %}
<span class="tags">{{tag}}</span> <span class="tags">{{tag}}</span>
{% endfor%} {% endfor%}

View File

@ -3,6 +3,13 @@
<div id="login"> <div id="login">
<form class="form" action="{{ url_for('register') }}" method="post"> <form class="form" action="{{ url_for('register') }}" method="post">
{{ registerform.csrf_token }} {{ registerform.csrf_token }}
<fieldset class="required">
{{ registerform.username.label }}
{{ registerform.username }}
{% for message in registerform.username.errors %}
<div class="error">{{ message }}</div>
{% endfor %}
</fieldset>
<fieldset class="required"> <fieldset class="required">
{{ registerform.email.label }} {{ registerform.email.label }}
{{ registerform.email }} {{ registerform.email }}

View File

@ -8,10 +8,12 @@ class User(UserMixin, db.Model):
__tablename__ = "users" __tablename__ = "users"
id = db.Column(db.Integer, primary_key=True) id = db.Column(db.Integer, primary_key=True)
username = db.Column(db.String(150), unique=True, nullable=False)
email = db.Column(db.String(150), unique=True, nullable=False) email = db.Column(db.String(150), unique=True, nullable=False)
password = db.Column(db.String(300), nullable=False, unique=False) password = db.Column(db.String(300), nullable=False, unique=False)
currentdistribusi = db.Column(db.String(300), nullable=True, unique=False) currentdistribusi = db.Column(db.String(300), nullable=True, unique=False)
admin = db.Column(db.Boolean, server_default="false") admin = db.Column(db.Boolean, server_default="false")
tutor = db.Column(db.Boolean, server_default="false")
def __repr__(self): def __repr__(self):
return "<User %r>" % self.email return "<User %r>" % self.email