mirror of
https://github.com/DarkflameUniverse/NexusDashboard.git
synced 2024-11-21 21:17:23 +00:00
it works
This commit is contained in:
parent
e6c452d000
commit
7633053490
@ -328,20 +328,21 @@ def register_settings(app):
|
||||
app.config['RECAPTCHA_PRIVATE_KEY']
|
||||
)
|
||||
# Optional
|
||||
app.config['RECAPTCHA_API_SERVER'] = os.getenv(
|
||||
'RECAPTCHA_API_SERVER',
|
||||
app.config['RECAPTCHA_API_SERVER']
|
||||
)
|
||||
app.config['RECAPTCHA_PARAMETERS'] = os.getenv(
|
||||
'RECAPTCHA_PARAMETERS',
|
||||
app.config['RECAPTCHA_PARAMETERS']
|
||||
)
|
||||
if "RECAPTCHA_DATA_ATTRS" not in app.config:
|
||||
app.config['RECAPTCHA_DATA_ATTRS'] = {'theme': 'white', 'size': 'invisible'}
|
||||
app.config['RECAPTCHA_DATA_ATTRS'] = os.getenv(
|
||||
'RECAPTCHA_DATA_ATTRS',
|
||||
app.config['RECAPTCHA_DATA_ATTRS']
|
||||
)
|
||||
if "RECAPTCHA_API_SERVER" in app.config:
|
||||
app.config['RECAPTCHA_API_SERVER'] = os.getenv(
|
||||
'RECAPTCHA_API_SERVER',
|
||||
app.config['RECAPTCHA_API_SERVER']
|
||||
)
|
||||
if "RECAPTCHA_PARAMETERS" in app.config:
|
||||
app.config['RECAPTCHA_PARAMETERS'] = os.getenv(
|
||||
'RECAPTCHA_PARAMETERS',
|
||||
app.config['RECAPTCHA_PARAMETERS']
|
||||
)
|
||||
if "RECAPTCHA_DATA_ATTRS" in app.config:
|
||||
app.config['RECAPTCHA_DATA_ATTRS'] = os.getenv(
|
||||
'RECAPTCHA_DATA_ATTRS',
|
||||
app.config['RECAPTCHA_DATA_ATTRS']
|
||||
)
|
||||
|
||||
|
||||
|
||||
|
68
app/forms.py
68
app/forms.py
@ -1,18 +1,15 @@
|
||||
from flask_wtf import FlaskForm
|
||||
from flask_wtf.recaptcha import RecaptchaField
|
||||
from flask_wtf import FlaskForm, Recaptcha, RecaptchaField
|
||||
from flask import current_app
|
||||
|
||||
from flask_user.forms import (
|
||||
unique_email_validator,
|
||||
password_validator,
|
||||
unique_username_validator
|
||||
LoginForm,
|
||||
RegisterForm
|
||||
)
|
||||
from flask_user import UserManager
|
||||
from wtforms.widgets import TextArea, NumberInput
|
||||
from wtforms import (
|
||||
StringField,
|
||||
HiddenField,
|
||||
PasswordField,
|
||||
BooleanField,
|
||||
SubmitField,
|
||||
validators,
|
||||
@ -37,35 +34,21 @@ def validate_play_key(form, field):
|
||||
field.data = PlayKey.key_is_valid(key_string=field.data)
|
||||
return
|
||||
|
||||
def validate_recaptcha(form, field):
|
||||
current_app.logger.info("start validating with recaptcha")
|
||||
if current_app.config["RECAPTCHA_ENABLE"]:
|
||||
current_app.logger.info("validating with recaptcha")
|
||||
return Recaptcha()
|
||||
current_app.logger.info("skipping validating with recaptcha")
|
||||
return True
|
||||
|
||||
|
||||
class CustomUserManager(UserManager):
|
||||
def customize(self, app):
|
||||
self.RegisterFormClass = CustomRegisterForm
|
||||
self.LoginFormClass = CustomLoginForm
|
||||
|
||||
|
||||
class CustomRegisterForm(FlaskForm):
|
||||
"""Registration form"""
|
||||
next = HiddenField()
|
||||
reg_next = HiddenField()
|
||||
|
||||
# Login Info
|
||||
email = StringField(
|
||||
'E-Mail',
|
||||
validators=[
|
||||
Optional(),
|
||||
validators.Email('Invalid email address'),
|
||||
unique_email_validator,
|
||||
]
|
||||
)
|
||||
|
||||
username = StringField(
|
||||
'Username',
|
||||
validators=[
|
||||
DataRequired(),
|
||||
unique_username_validator,
|
||||
]
|
||||
)
|
||||
|
||||
class CustomRegisterForm(RegisterForm):
|
||||
play_key_id = StringField(
|
||||
'Play Key',
|
||||
validators=[
|
||||
@ -73,25 +56,14 @@ class CustomRegisterForm(FlaskForm):
|
||||
validate_play_key,
|
||||
]
|
||||
)
|
||||
recaptcha = RecaptchaField(
|
||||
validators=[validate_recaptcha]
|
||||
)
|
||||
|
||||
password = PasswordField('Password', validators=[
|
||||
DataRequired(),
|
||||
password_validator,
|
||||
validators.length(max=40, message="The maximum length of the password is 40 characters due to game client limitations")
|
||||
])
|
||||
retype_password = PasswordField('Retype Password', validators=[
|
||||
validators.EqualTo('password', message='Passwords did not match'),
|
||||
validators.length(max=40, message="The maximum length of the password is 40 characters due to game client limitations")
|
||||
])
|
||||
|
||||
invite_token = HiddenField('Token')
|
||||
|
||||
# Use recaptcha if config enables recaptcha
|
||||
if current_app.config["ENABLE_RECAPTCHA"]:
|
||||
recaptcha = RecaptchaField()
|
||||
|
||||
submit = SubmitField('Register')
|
||||
|
||||
class CustomLoginForm(LoginForm):
|
||||
recaptcha = RecaptchaField(
|
||||
validators=[validate_recaptcha]
|
||||
)
|
||||
|
||||
class CreatePlayKeyForm(FlaskForm):
|
||||
|
||||
|
@ -60,7 +60,12 @@
|
||||
|
||||
{# Remember me #}
|
||||
{% if user_manager.USER_ENABLE_REMEMBER_ME %}
|
||||
{{ render_checkbox_field(login_form.remember_me, tabindex=130) }}
|
||||
{{ render_checkbox_field(login_form.remember_me, tabindex=130) }}
|
||||
{% endif %}
|
||||
|
||||
{# recaptcha #}
|
||||
{% if config.RECAPTCHA_ENABLE %}
|
||||
{{ render_field(form.recaptcha, tabindex=250) }}
|
||||
{% endif %}
|
||||
|
||||
{# Submit button #}
|
||||
|
@ -29,6 +29,11 @@
|
||||
{{ render_checkbox_field(login_form.remember_me, tabindex=130) }}
|
||||
{% endif %}
|
||||
|
||||
{# recaptcha #}
|
||||
{% if config.RECAPTCHA_ENABLE %}
|
||||
{{ form.recaptcha }}
|
||||
{% endif %}
|
||||
|
||||
{# Submit button #}
|
||||
{{ render_submit_field(login_form.submit, tabindex=180) }}
|
||||
</form>
|
||||
@ -63,6 +68,11 @@
|
||||
{{ render_field(register_form.retype_password, tabindex=240) }}
|
||||
{% endif %}
|
||||
|
||||
{# recaptcha #}
|
||||
{% if config.RECAPTCHA_ENABLE %}
|
||||
{{ register_form.recaptcha }}
|
||||
{% endif %}
|
||||
|
||||
{{ render_submit_field(register_form.submit, tabindex=280) }}
|
||||
</form>
|
||||
|
||||
|
@ -47,6 +47,11 @@
|
||||
{{ render_field(form.retype_password, tabindex=240) }}
|
||||
{% endif %}
|
||||
|
||||
{# recaptcha #}
|
||||
{% if config.RECAPTCHA_ENABLE %}
|
||||
{{ render_field(form.recaptcha, tabindex=250) }}
|
||||
{% endif %}
|
||||
|
||||
{{ render_submit_field(form.submit, tabindex=280) }}
|
||||
</form>
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user