mirror of
https://github.com/aljazceru/CTFd.git
synced 2025-12-18 14:34:21 +01:00
Add some more progress
This commit is contained in:
19
CTFd/auth.py
19
CTFd/auth.py
@@ -252,6 +252,19 @@ def register():
|
|||||||
if valid_affiliation is False:
|
if valid_affiliation is False:
|
||||||
errors.append("Please provide a shorter affiliation")
|
errors.append("Please provide a shorter affiliation")
|
||||||
|
|
||||||
|
from CTFd.models import Fields
|
||||||
|
|
||||||
|
fields = {}
|
||||||
|
for field in Fields.query.all():
|
||||||
|
fields[field.id] = field
|
||||||
|
|
||||||
|
entries = {}
|
||||||
|
for field_id, field in fields.items():
|
||||||
|
value = request.form.get(f"field-{field_id}", "").strip()
|
||||||
|
if field.required is True and (value is None or value == ""):
|
||||||
|
errors.append("Please enter in all required fields")
|
||||||
|
entries[field_id] = value
|
||||||
|
|
||||||
if len(errors) > 0:
|
if len(errors) > 0:
|
||||||
return render_template(
|
return render_template(
|
||||||
"register.html",
|
"register.html",
|
||||||
@@ -275,6 +288,12 @@ def register():
|
|||||||
db.session.commit()
|
db.session.commit()
|
||||||
db.session.flush()
|
db.session.flush()
|
||||||
|
|
||||||
|
from CTFd.models import FieldEntries
|
||||||
|
for field_id, value in entries.items():
|
||||||
|
entry = FieldEntries(field_id=field_id, value=value, user_id=user.id)
|
||||||
|
db.session.add(entry)
|
||||||
|
db.session.commit()
|
||||||
|
|
||||||
login_user(user)
|
login_user(user)
|
||||||
|
|
||||||
if config.can_send_mail() and get_config(
|
if config.can_send_mail() and get_config(
|
||||||
|
|||||||
@@ -19,13 +19,13 @@ def RegistrationForm(*args, **kwargs):
|
|||||||
fields = []
|
fields = []
|
||||||
new_fields = Fields.query.all()
|
new_fields = Fields.query.all()
|
||||||
for field in new_fields:
|
for field in new_fields:
|
||||||
entry = (field.name, getattr(self, field.name))
|
entry = (field.name, getattr(self, f"field-{field.id}"))
|
||||||
fields.append(entry)
|
fields.append(entry)
|
||||||
return fields
|
return fields
|
||||||
|
|
||||||
new_fields = Fields.query.all()
|
new_fields = Fields.query.all()
|
||||||
for field in new_fields:
|
for field in new_fields:
|
||||||
setattr(_RegistrationForm, field.name, StringField(field.name))
|
setattr(_RegistrationForm, f"field-{field.id}", StringField(field.name))
|
||||||
|
|
||||||
return _RegistrationForm(*args, **kwargs)
|
return _RegistrationForm(*args, **kwargs)
|
||||||
|
|
||||||
|
|||||||
@@ -4,17 +4,34 @@ from wtforms.fields.html5 import DateField, URLField
|
|||||||
from CTFd.forms import BaseForm
|
from CTFd.forms import BaseForm
|
||||||
from CTFd.forms.fields import SubmitField
|
from CTFd.forms.fields import SubmitField
|
||||||
from CTFd.utils.countries import SELECT_COUNTRIES_LIST
|
from CTFd.utils.countries import SELECT_COUNTRIES_LIST
|
||||||
|
from CTFd.models import Fields
|
||||||
|
|
||||||
|
|
||||||
class SettingsForm(BaseForm):
|
def SettingsForm(*args, **kwargs):
|
||||||
name = StringField("User Name")
|
class _SettingsForm(BaseForm):
|
||||||
email = StringField("Email")
|
name = StringField("User Name")
|
||||||
password = PasswordField("Password")
|
email = StringField("Email")
|
||||||
confirm = PasswordField("Current Password")
|
password = PasswordField("Password")
|
||||||
affiliation = StringField("Affiliation")
|
confirm = PasswordField("Current Password")
|
||||||
website = URLField("Website")
|
affiliation = StringField("Affiliation")
|
||||||
country = SelectField("Country", choices=SELECT_COUNTRIES_LIST)
|
website = URLField("Website")
|
||||||
submit = SubmitField("Submit")
|
country = SelectField("Country", choices=SELECT_COUNTRIES_LIST)
|
||||||
|
submit = SubmitField("Submit")
|
||||||
|
|
||||||
|
@property
|
||||||
|
def extra(self):
|
||||||
|
fields = []
|
||||||
|
new_fields = Fields.query.all()
|
||||||
|
for field in new_fields:
|
||||||
|
entry = (field.name, getattr(self, f"field-{field.id}"))
|
||||||
|
fields.append(entry)
|
||||||
|
return fields
|
||||||
|
|
||||||
|
new_fields = Fields.query.all()
|
||||||
|
for field in new_fields:
|
||||||
|
setattr(_SettingsForm, f"field-{field.id}", StringField(field.name))
|
||||||
|
|
||||||
|
return _SettingsForm(*args, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
class TokensForm(BaseForm):
|
class TokensForm(BaseForm):
|
||||||
|
|||||||
@@ -812,4 +812,15 @@ class Fields(db.Model):
|
|||||||
|
|
||||||
|
|
||||||
class UserFields(Comments):
|
class UserFields(Comments):
|
||||||
__mapper_args__ = {"polymorphic_identity": "user"}
|
__mapper_args__ = {"polymorphic_identity": "user"}
|
||||||
|
|
||||||
|
|
||||||
|
class FieldEntries(db.Model):
|
||||||
|
__tablename__ = "field_entries"
|
||||||
|
id = db.Column(db.Integer, primary_key=True)
|
||||||
|
value = db.Column(db.Text)
|
||||||
|
field_id = db.Column(db.Integer, db.ForeignKey("fields.id", ondelete="CASCADE"))
|
||||||
|
user_id = db.Column(db.Integer, db.ForeignKey("users.id", ondelete="CASCADE"))
|
||||||
|
|
||||||
|
user = db.relationship("Users", foreign_keys="FieldEntries.user_id")
|
||||||
|
field = db.relationship("Fields", foreign_keys="FieldEntries.field_id")
|
||||||
|
|||||||
@@ -60,6 +60,16 @@
|
|||||||
{{ form.country(class="form-control custom-select", value=country) }}
|
{{ form.country(class="form-control custom-select", value=country) }}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<hr>
|
||||||
|
|
||||||
|
{% for k, v in form.extra %}
|
||||||
|
<div class="form-group">
|
||||||
|
<b>{{ v.label }}</b>
|
||||||
|
{{ v(class="form-control") }}
|
||||||
|
</div>
|
||||||
|
{% endfor %}
|
||||||
|
|
||||||
|
|
||||||
<div id="results" class="form-group">
|
<div id="results" class="form-group">
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user