Browse Source

deleted files

main
crunk 6 months ago
parent
commit
4425888116
  1. 105
      verse/adminpage.py
  2. 23
      verse/forms/admindistribusiform.py
  3. 23
      verse/forms/adminuserform.py
  4. 15
      verse/forms/forgotpasswordform.py
  5. 18
      verse/forms/loginform.py
  6. 38
      verse/forms/registerform.py
  7. 23
      verse/forms/resetpasswordform.py

105
verse/adminpage.py

@ -1,105 +0,0 @@
import os
import shutil
from flask import render_template
from sqlalchemy.exc import (
DatabaseError,
DataError,
InterfaceError,
InvalidRequestError,
)
from app import db
from distribusikan.distribusisinfo import DistribusisInfo
from forms.admindistribusiform import AdminDistribusiForm
from forms.adminuserform import AdminUserForm
from models.distribusi_model import Distribusis
from models.user_model import User
def AdminPage():
adminuserform = AddUsersToForm(AdminUserForm())
admindistribusiform = AddDistribusisToForm(AdminDistribusiForm())
if admindistribusiform.validate_on_submit():
DeleteDistribusis(admindistribusiform)
if adminuserform.validate_on_submit():
if adminuserform.delete.data:
DeleteUsers(adminuserform)
template = render_template(
"admin.html",
adminuserform=adminuserform,
admindistribusiform=admindistribusiform,
)
return template
def DeleteUsers(adminuserform):
for userform in adminuserform:
if "user" in userform.id:
if userform.data:
useremail = userform.label.text
user = User.query.filter_by(email=useremail).first()
DeleteUserDistribusis(user)
DeleteUserFromDb(user)
userform.errors.append(f"User {useremail} deleted!")
def DeleteUserFromDb(user):
try:
db.session.delete(user)
db.session.commit()
except (InvalidRequestError, DataError, InterfaceError, DatabaseError):
db.session.rollback()
def DeleteUserDistribusis(user):
distribusis = DistribusisInfo.getuserdistribusis(user.email)
for distribusi in distribusis:
DeleteDistribusiFiles(distribusi.distribusiname)
DeleteDistribusiFromDb(distribusi)
def DeleteDistribusis(admindistribusiform):
for distribusiform in admindistribusiform:
if "distribusi" in distribusiform.id:
if distribusiform.data:
distribusiname = distribusiform.label.text
distribusi = Distribusis.query.filter_by(
distribusiname=distribusiname
).first()
DeleteDistribusiFromDb(distribusi)
DeleteDistribusiFiles(distribusiname)
distribusiform.errors.append("Deleted distribusi")
def DeleteDistribusiFromDb(distribusi):
try:
db.session.delete(distribusi)
db.session.commit()
except (InvalidRequestError, DataError, InterfaceError, DatabaseError):
db.session.rollback()
def DeleteDistribusiFiles(distribusiname):
userfolder = os.path.join("stash", distribusiname)
if os.path.exists(userfolder):
shutil.rmtree(userfolder)
cssfolder = os.path.join("themes/userthemes", distribusiname)
if os.path.exists(cssfolder):
shutil.rmtree(cssfolder)
def AddDistribusisToForm(admindistribusiform):
distribusis = DistribusisInfo.visibledistribusis()
admindistribusiform = AdminDistribusiForm.distribusi_list_form_builder(
distribusis
)
return admindistribusiform
def AddUsersToForm(adminuserform):
users = User.query.all()
adminuserform = AdminUserForm.user_list_form_builder(users)
return adminuserform

23
verse/forms/admindistribusiform.py

@ -1,23 +0,0 @@
"""Form object declaration."""
from flask_wtf import FlaskForm
from wtforms import BooleanField, SubmitField
class AdminDistribusiForm(FlaskForm):
"""Admin Distribusi form."""
delete = SubmitField("Delete")
def distribusi_list_form_builder(distribusis):
class DistribusiListForm(AdminDistribusiForm):
pass
for i, distribusi in enumerate(distribusis):
setattr(
DistribusiListForm,
f"distribusi_{i}",
BooleanField(label=distribusi.distribusiname),
)
return DistribusiListForm()

23
verse/forms/adminuserform.py

@ -1,23 +0,0 @@
"""Form object declaration."""
from flask_wtf import FlaskForm
from wtforms import BooleanField, SubmitField
class AdminUserForm(FlaskForm):
"""Admin Userform form."""
def user_list_form_builder(users):
class UserListForm(AdminUserForm):
pass
for i, user in enumerate(users):
setattr(
UserListForm,
f"user_{i}",
BooleanField(label=user.email),
)
return UserListForm()
delete = SubmitField("Delete")

15
verse/forms/forgotpasswordform.py

@ -1,15 +0,0 @@
"""Forgotten password form to help user."""
from flask_wtf import FlaskForm
from wtforms import StringField, SubmitField, validators
from wtforms.validators import Email, Length
class ForgotPasswordForm(FlaskForm):
"""Forgotten password distribusiverse form class."""
email = StringField(
"Email address:",
validators=[validators.InputRequired(), Email(), Length(6, 64)],
)
submit = SubmitField("Send email")

18
verse/forms/loginform.py

@ -1,18 +0,0 @@
"""Login form to validate user."""
from flask_wtf import FlaskForm
from wtforms import PasswordField, StringField, SubmitField, validators
from wtforms.validators import Email, Length
class LoginForm(FlaskForm):
"""Login distribusiverse form class."""
email = StringField(
"Email address:",
validators=[validators.InputRequired(), Email(), Length(6, 64)],
)
password = PasswordField(
"Password:", validators=[validators.InputRequired()]
)
submit = SubmitField("Sign In")

38
verse/forms/registerform.py

@ -1,38 +0,0 @@
"""Register form to make a new user."""
from flask_wtf import FlaskForm
from wtforms import PasswordField, StringField, SubmitField, validators
from wtforms.validators import Email, EqualTo, Length
class RegisterForm(FlaskForm):
"""Register for distribusi-verse form class"""
username = StringField(
"Username:",
validators=[validators.InputRequired(), Length(3, 150)],
)
email = StringField(
"Email address:",
validators=[
validators.InputRequired(),
Email(),
Length(6, 128),
],
)
password = PasswordField(
"New password:",
validators=[validators.InputRequired(), Length(12, 72)],
)
confirmpassword = PasswordField(
"Confirm your password:",
validators=[
validators.InputRequired(),
Length(12, 72),
EqualTo("password", message="Passwords must match !"),
],
)
submit = SubmitField("Register to Distribusi-verse")

23
verse/forms/resetpasswordform.py

@ -1,23 +0,0 @@
"""Reset Password Form form to reset a users PasswordField."""
from flask_wtf import FlaskForm
from wtforms import PasswordField, SubmitField, validators
from wtforms.validators import EqualTo, Length
class ResetPasswordForm(FlaskForm):
"""ResetPassword for distribusi-verse form class"""
password = PasswordField(
"New password:",
validators=[validators.InputRequired(), Length(12, 72)],
)
confirmpassword = PasswordField(
"Confirm your password:",
validators=[
validators.InputRequired(),
Length(12, 72),
EqualTo("password", message="Passwords must match !"),
],
)
submit = SubmitField("Reset your password")
Loading…
Cancel
Save