Corriger erreur d'enregistrement
This commit is contained in:
+20
-7
@@ -187,9 +187,6 @@ def register():
|
||||
if current_user.is_authenticated:
|
||||
return redirect(url_for('main.dashboard'))
|
||||
|
||||
# Generate CAPTCHA for GET requests
|
||||
captcha = generate_captcha()
|
||||
|
||||
if request.method == 'POST':
|
||||
# Validate CAPTCHA first
|
||||
captcha_answer = request.form.get('captcha_answer', '')
|
||||
@@ -203,9 +200,12 @@ def register():
|
||||
)
|
||||
|
||||
# Validate input with marshmallow schema
|
||||
# Convert MultiDict to dict with proper lists for checkbox fields
|
||||
form_data = dict(request.form)
|
||||
form_data['games'] = request.form.getlist('games')
|
||||
register_schema = RegisterSchema()
|
||||
try:
|
||||
validated = register_schema.load(request.form)
|
||||
validated = register_schema.load(form_data)
|
||||
except ValidationError as err:
|
||||
for field, messages in err.messages.items():
|
||||
for msg in messages:
|
||||
@@ -223,9 +223,7 @@ def register():
|
||||
full_name = validated['full_name']
|
||||
phone = validated.get('phone')
|
||||
selected_games = validated.get('games', [])
|
||||
trn_username = request.form.get('trn_username', '').strip() or None
|
||||
discord_username = validated.get('discord_username')
|
||||
league_os_profile = validated.get('league_os_profile')
|
||||
|
||||
if User.query.filter_by(username=username).first():
|
||||
flash('Username already exists.', 'danger')
|
||||
@@ -255,14 +253,29 @@ def register():
|
||||
phone=phone,
|
||||
games=','.join(selected_games) if selected_games else None,
|
||||
discord_username=discord_username,
|
||||
league_os_profile=league_os_profile,
|
||||
)
|
||||
db.session.add(user)
|
||||
db.session.commit()
|
||||
|
||||
# Create UserGamertag records for each selected game
|
||||
from app.models import UserGamertag
|
||||
for game in selected_games:
|
||||
field_name = f'gamertag_{game}'
|
||||
gamertag_value = request.form.get(field_name, '').strip()
|
||||
if gamertag_value:
|
||||
gamertag = UserGamertag(
|
||||
user_id=user.id,
|
||||
game=game,
|
||||
gamertag=gamertag_value,
|
||||
)
|
||||
db.session.add(gamertag)
|
||||
db.session.commit()
|
||||
|
||||
flash('Your account has been created! You can now log in.', 'success')
|
||||
return redirect(url_for('auth.login'))
|
||||
|
||||
# Generate CAPTCHA only for GET requests
|
||||
captcha = generate_captcha()
|
||||
return render_template('pages/register.html', esport_games=ESPORT_GAMES, captcha=captcha)
|
||||
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{% extends "layouts/base.html" %}
|
||||
{% block title %}Register - TryoutPro{% endblock %}
|
||||
{% block auth_content %}
|
||||
<form method="POST" action="{{ url_for('auth.register') }}" class="auth-form">
|
||||
<form method="POST" action="{{ url_for('auth.register') }}" class="auth-form" id="register-form">
|
||||
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}"/>
|
||||
<div class="form-group">
|
||||
<label for="full_name"><i class="fas fa-id-card"></i> Full Name</label>
|
||||
@@ -22,34 +22,30 @@
|
||||
|
||||
<hr class="section-divider">
|
||||
<h4 class="section-title"><i class="fas fa-gamepad"></i> E-Sports Profile</h4>
|
||||
<p class="text-muted small">Set up your competitive gaming profile for tryouts.</p>
|
||||
<p class="text-muted small">Select the games you play and provide your gamertag for each.</p>
|
||||
|
||||
<div class="form-group">
|
||||
<div class="form-group" id="games-container">
|
||||
<label><i class="fas fa-headset"></i> Games You Play</label>
|
||||
<div class="checkbox-grid">
|
||||
{% for game in esport_games %}
|
||||
{% for game in esport_games %}
|
||||
<div class="game-entry">
|
||||
<label class="checkbox-label">
|
||||
<input type="checkbox" name="games" value="{{ game }}">
|
||||
<input type="checkbox" name="games" value="{{ game }}" class="game-checkbox" data-game="{{ game }}">
|
||||
<span>{{ game }}</span>
|
||||
</label>
|
||||
{% endfor %}
|
||||
<div class="gamertag-input" id="gamertag-group-{{ game | replace(' ', '_') }}" style="display:none; margin-top: 4px; margin-left: 20px;">
|
||||
<input type="text" name="gamertag_{{ game }}" id="gamertag_{{ game | replace(' ', '_') }}"
|
||||
placeholder="Enter your {{ game }} gamertag" class="gamertag-field"
|
||||
data-game="{{ game }}">
|
||||
</div>
|
||||
</div>
|
||||
<small class="form-text text-muted">Select all games you're signing in for.</small>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="trn_username"><i class="fas fa-chart-line"></i> TRN (Tracker Network) Username</label>
|
||||
<input type="text" id="trn_username" name="trn_username" placeholder="e.g. YourTrackerGGUsername">
|
||||
<small class="form-text text-muted">Your public Tracker Network profile name. Others can click it to view your stats.</small>
|
||||
{% endfor %}
|
||||
<small class="form-text text-muted">Check each game you play, then enter your gamertag for that game.</small>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="discord_username"><i class="fab fa-discord"></i> Discord Username</label>
|
||||
<input type="text" id="discord_username" name="discord_username" placeholder="e.g. YourName#1234">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="league_os_profile"><i class="fas fa-link"></i> League OS Connection</label>
|
||||
<input type="text" id="league_os_profile" name="league_os_profile" placeholder="League OS profile link or ID">
|
||||
<small class="form-text text-muted">Connect your League OS profile for organized play.</small>
|
||||
</div>
|
||||
|
||||
<hr class="section-divider">
|
||||
<div class="form-group">
|
||||
@@ -60,7 +56,69 @@
|
||||
<label for="confirm_password"><i class="fas fa-check-circle"></i> Confirm Password</label>
|
||||
<input type="password" id="confirm_password" name="confirm_password" placeholder="Confirm your password" required>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="captcha_answer">
|
||||
<i class="fas fa-shield-alt"></i> Security Check: {{ captcha.question }}
|
||||
</label>
|
||||
<input type="text" id="captcha_answer" name="captcha_answer" placeholder="Enter the answer" required>
|
||||
</div>
|
||||
|
||||
<button type="submit" class="btn btn-primary btn-block">Create Account</button>
|
||||
<p class="auth-link">Already have an account? <a href="{{ url_for('auth.login') }}">Sign in</a></p>
|
||||
</form>
|
||||
{% endblock %}
|
||||
|
||||
{% block scripts %}
|
||||
<script>
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
const checkboxes = document.querySelectorAll('.game-checkbox');
|
||||
const form = document.getElementById('register-form');
|
||||
|
||||
checkboxes.forEach(function(checkbox) {
|
||||
checkbox.addEventListener('change', function() {
|
||||
const game = this.dataset.game.replace(/ /g, '_');
|
||||
const gamertagGroup = document.getElementById('gamertag-group-' + game);
|
||||
const gamertagField = document.getElementById('gamertag_' + game);
|
||||
|
||||
if (this.checked) {
|
||||
gamertagGroup.style.display = 'block';
|
||||
gamertagField.setAttribute('required', 'required');
|
||||
} else {
|
||||
gamertagGroup.style.display = 'none';
|
||||
gamertagField.removeAttribute('required');
|
||||
gamertagField.value = '';
|
||||
}
|
||||
});
|
||||
|
||||
// Initialize on page load (in case of form re-render after validation error)
|
||||
const game = checkbox.dataset.game.replace(/ /g, '_');
|
||||
const gamertagGroup = document.getElementById('gamertag-group-' + game);
|
||||
if (checkbox.checked) {
|
||||
gamertagGroup.style.display = 'block';
|
||||
}
|
||||
});
|
||||
|
||||
form.addEventListener('submit', function(e) {
|
||||
const checkedGames = document.querySelectorAll('.game-checkbox:checked');
|
||||
let allFilled = true;
|
||||
|
||||
checkedGames.forEach(function(checkbox) {
|
||||
const game = checkbox.dataset.game.replace(/ /g, '_');
|
||||
const gamertagField = document.getElementById('gamertag_' + game);
|
||||
if (!gamertagField || !gamertagField.value.trim()) {
|
||||
allFilled = false;
|
||||
gamertagField.style.borderColor = '#dc3545';
|
||||
} else {
|
||||
gamertagField.style.borderColor = '';
|
||||
}
|
||||
});
|
||||
|
||||
if (!allFilled) {
|
||||
e.preventDefault();
|
||||
alert('Please enter a gamertag for each game you selected.');
|
||||
}
|
||||
});
|
||||
});
|
||||
</script>
|
||||
{% endblock %}
|
||||
@@ -208,15 +208,6 @@ class RegisterSchema(StripMixin):
|
||||
allow_none=True,
|
||||
load_default=None,
|
||||
)
|
||||
trn_username = fields.String(
|
||||
allow_none=True,
|
||||
load_default=None,
|
||||
)
|
||||
league_os_profile = fields.String(
|
||||
validate=validate.Length(max=256),
|
||||
allow_none=True,
|
||||
load_default=None,
|
||||
)
|
||||
|
||||
@validates_schema
|
||||
def validate_password_match(self, data, **kwargs):
|
||||
|
||||
Reference in New Issue
Block a user