Commit 23893139 authored by ViolanteCodes's avatar ViolanteCodes
Browse files

added any_words to determine if ANY words are fille din on form

parent a396c404
from django import forms from django import forms
from django.forms import ModelForm, modelformset_factory, BaseModelFormSet from django.forms import ModelForm, modelformset_factory, BaseModelFormSet
from django.conf import settings from django.conf import settings
from django.shortcuts import get_object_or_404 from django.shortcuts import get_object_or_404, render
from django.urls import reverse from django.urls import reverse
import gitlab import gitlab
import random import random
from django.core.exceptions import ValidationError from django.core.exceptions import ValidationError
...@@ -47,6 +47,7 @@ class LoginForm(forms.Form): ...@@ -47,6 +47,7 @@ class LoginForm(forms.Form):
# Set two flags for strings and all words filled. # Set two flags for strings and all words filled.
string_filled = False string_filled = False
all_words_filled = True all_words_filled = True
any_words = False
# Grab the login string field # Grab the login string field
if cleaned_data.get('login_string') != '': if cleaned_data.get('login_string') != '':
login_string = cleaned_data.get('login_string') login_string = cleaned_data.get('login_string')
...@@ -61,21 +62,26 @@ class LoginForm(forms.Form): ...@@ -61,21 +62,26 @@ class LoginForm(forms.Form):
# if any of the words are left blank, flip the flag for all_words_filled. # if any of the words are left blank, flip the flag for all_words_filled.
if value == '': if value == '':
all_words_filled = False all_words_filled = False
if value != '':
any_words = True
if string_filled == True: if string_filled == True:
if all_words_filled == True: if any_words == True:
raise ValidationError( raise ValidationError(
"""ERROR: It looks like you've filled out both the login words and the login string/phrase fields. """ERROR: It looks like you've filled out both the login words and the login string/phrase fields.
Please choose one or the other.""") Please choose one or the other.""")
if all_words_filled == False: else:
user_identifier = login_string user_identifier = login_string
self.cleaned_data['user_identifier'] = user_identifier self.cleaned_data['user_identifier'] = user_identifier
if string_filled == False: if string_filled == False:
if all_words_filled == False: if all_words_filled == False:
raise ValidationError( if any_words == True:
"""Make sure to fill out either all words of your user identifier above, or paste the string raise ValidationError(
version of your user identifier below.""") """Make sure to fill out either all words of your user identifier above, or paste the string
version of your user identifier below.""")
else:
self.cleaned_data['blank'] = True
else: else:
user_identifier = self.build_code_phrase(cleaned_word_data=cleaned_word_data) user_identifier = self.build_code_phrase(cleaned_word_data=cleaned_word_data)
self.cleaned_data['user_identifier'] = user_identifier self.cleaned_data['user_identifier'] = user_identifier
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment