Commit 49ce1962 authored by MariaV's avatar MariaV
Browse files

Merge branch 'remove_old_login_form_logic' into 'master'

Remove References to old login method (words over string)

See merge request !84
parents 17e4f8aa eadb1fd6
......@@ -13,33 +13,8 @@ gl = gitlab.Gitlab(settings.GITLAB_URL, private_token=settings.GITLAB_SECRET_TOK
class LoginForm(forms.Form):
"""A form that allows users to enter in their keycodes to login."""
word_1 = forms.CharField(max_length=9, required=False)
word_2 = forms.CharField(max_length=9, required=False)
word_3 = forms.CharField(max_length=9, required=False)
word_4 = forms.CharField(max_length=9, required=False)
word_5 = forms.CharField(max_length=9, required=False)
word_6 = forms.CharField(max_length=9, required=False)
login_string = forms.CharField(max_length=255, required=False)
# def join_words(self):
# """Pull cleaned data from form and join into code_phrase"""
# word_list = []
# word_list.append(self.cleaned_data['word_1'])
# word_list.append(self.cleaned_data['word_2'])
# word_list.append(self.cleaned_data['word_3'])
# word_list.append(self.cleaned_data['word_4'])
# word_list.append(self.cleaned_data['word_5'])
# word_list.append(self.cleaned_data['word_6'])
# join_key = '-'
# code_phrase = join_key.join(word_list)
# return code_phrase
def build_code_phrase(self, cleaned_word_data=[]):
"""Join form cleaned data into code_phrase"""
join_key = '-'
code_phrase = join_key.join(cleaned_word_data)
return code_phrase
def sanitize_login_string(self, login_string):
"""Santizes the login string"""
#convert to lowercase and strip whitespace
......@@ -54,50 +29,11 @@ class LoginForm(forms.Form):
"""Custom clean method for form"""
# Call the parent method
cleaned_data = super().clean()
# Set two flags for strings and all words filled.
string_filled = False
all_words_filled = True
any_words = False
# Grab the login string field
if cleaned_data.get('login_string') != '':
login_string = cleaned_data.get('login_string')
string_filled = True
# Now get the individual word login fields - first set up a list called word_counter
word_counter = ['word_1', 'word_2', 'word_3', 'word_4', 'word_5', 'word_6']
# iterate through the wordlist, matching to cleaned_data and further santizing the input by
# calling .lower() on each word before passing it to a cleaned_word_data dictionary to be joined.
cleaned_word_data = []
for word in word_counter:
value = cleaned_data.get(word)
cleaned_word_data.append(value.lower())
# if any of the words are left blank, flip the flag for all_words_filled.
if value == '':
all_words_filled = False
# if any word is filled in, flip the flap for any_words.
if value != '':
any_words = True
if string_filled == True:
if any_words == True:
raise ValidationError(
"""ERROR: It looks like you've filled out both the login words and the login string/phrase fields.
Please choose one or the other.""")
else:
user_identifier = self.sanitize_login_string(login_string)
self.cleaned_data['user_identifier'] = user_identifier
if string_filled == False:
if all_words_filled == False:
if any_words == True:
raise ValidationError(
"""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:
user_identifier = self.build_code_phrase(cleaned_word_data=cleaned_word_data)
self.cleaned_data['user_identifier'] = user_identifier
user_identifier = self.sanitize_login_string(login_string)
self.cleaned_data['user_identifier'] = user_identifier
# Forms relating to User Objects:
......
......@@ -13,16 +13,18 @@
{% endblock %}
<!-- Subheader block sets the subheader -->
{% block subheader %}
Enter in a User Identifier Code-Phrase
Login with Existing User Identifier
{% endblock %}
<!-- block content block is where page contents go -->
{% block content %}
<!-- Explanation block -->
<div class="row mb-4">
<div class="row mb-1">
<div class="col-12">
<p class="pr-5">
If you've already created a user identifier, you can
enter it below to login, or you can <a href="{% url 'create-identifier' %}">create one now.</a>
If you've already created a user identifier, enter it and click the button below.
You can separate words with commas, spaces, dashes, or underscores.</p>
<p class="pr-5">If you don't have a user identifier,
(or want a different one), you can <a href="{% url 'create-identifier' %}">create one now.</a>
</p>
</div>
</div>
......@@ -42,65 +44,17 @@
</div>
{% endif %}
<!-- Render login string block -->
<div class="row">
<div class="row mb-3">
<div class="col-12">
<div class="">
<p>
Enter your user identifier and click the button below.
You can separate the words with commas, spaces, dashes, or underscores.
</p>
</div>
<div class="bg-light p-4 flex-form">
<div class="bg-light px-4 pt-4 pb-1 flex-form fieldWrapper mb-0">
{{ form.login_string.errors}}
{{ form.login_string}}
<label for="{{form.login_string.id_for_label }}" class="text-muted ml-2 small">
Enter your user identifier above.</label>
</div>
</div>
</div>
<!-- Render words fields
<div class="row mt-2">
<div class="col-12">
<div class="mt-4">
<p class="">
Option 2: Enter the words of your user identifier below
to login. Put one word in each box. You can use tab to navigate from one box to the next.
</p>
</div>
<ul class="bg-light p-4 flex-form">
<li>
{{ form.word_1.errors}}
{{ form.word_1 }}
{{ form.word_1.label_tag}}
</li>
<li>
{{ form.word_2.errors}}
{{ form.word_2 }}
{{ form.word_2.label_tag}}
</li>
<li>
{{ form.word_3.errors}}
{{ form.word_3 }}
{{ form.word_3.label_tag}}
</li>
<li>
{{ form.word_4.errors}}
{{ form.word_4 }}
{{ form.word_4.label_tag}}
</li>
<li>
{{ form.word_5.errors}}
{{ form.word_5 }}
{{ form.word_5.label_tag}}
</li>
<li>
{{ form.word_6.errors}}
{{ form.word_6 }}
{{ form.word_6.label_tag}}
</li>
</ul>
</div> -->
<!-- </div> -->
<!-- Render login button block -->
<div>
<button type="submit" class="btn btn-lg btn-primary mr-2 mt-3 new-line">Login With This Identifier</button>
</div>
<div>
<button type="submit" class="btn btn-lg btn-primary mr-2 mt-3 new-line">Login With This Identifier</button>
</div>
{% endblock %}
\ No newline at end of file
......@@ -278,12 +278,7 @@ class TestIdentifierAndLoginViewsWithoutDatabase(SimpleTestCase):
def test_login_view_GET_with_data(self):
"""Test the response for the login_view with data."""
response = self.client.get(self.login_url, data={
'word_1': 'duo',
'word_2': 'atlas',
'word_3': 'hypnotism',
'word_4': 'curry',
'word_5': 'creatable',
'word_6': 'rubble',
'login_string': self.new_user,
})
self.assertEqual(response.status_code, 302)
......@@ -1344,32 +1339,6 @@ class TestLoginFormIsValid(SimpleTestCase):
})
self.assertTrue(form.is_valid())
def test_login_valid_data_six_words(self):
"""Test login form with six words."""
# duo-atlas-hypnotism-curry-creatable-rubble
form = LoginForm(data = {
'word_1': 'duo',
'word_2': 'atlas',
'word_3': 'hypnotism',
'word_4': 'curry',
'word_5': 'creatable',
'word_6': 'rubble',
})
self.assertTrue(form.is_valid())
def test_login_valid_data_six_words_random_case(self):
"""Test login form with six words regardless of case."""
# duo-atlas-hypnotism-curry-creatable-rubble
form = LoginForm(data = {
'word_1': 'DUO',
'word_2': 'atlas',
'word_3': 'Hypnotism',
'word_4': 'curry',
'word_5': 'creatable',
'word_6': 'rubble',
})
self.assertTrue(form.is_valid())
def test_login_valid_data_login_string(self):
"""Test login form with a valid string."""
# duo-atlas-hypnotism-curry-creatable-rubble
......@@ -1377,56 +1346,11 @@ class TestLoginFormIsValid(SimpleTestCase):
'login_string': 'duo-atlas-hypnotism-curry-creatable-rubble' ,
})
self.assertTrue(form.is_valid())
def test_login_invalid_data_five_words(self):
"""Test login form with only five valid words."""
# duo-atlas-hypnotism-curry-creatable-rubble
form = LoginForm(data = {
'word_1': 'duo',
'word_2': 'atlas',
'word_3': 'hypnotism',
'word_4': 'curry',
'word_5': 'creatable',
})
self.assertFalse(form.is_valid())
self.assertEquals(len(form.errors), 1)
def test_login_invalid_data_any_words_AND_string(self):
"""Test login form with a word and a login string filled out."""
# duo-atlas-hypnotism-curry-creatable-rubble
form = LoginForm(data = {
'word_1': 'duo',
'login_string': 'duo-atlas-hypnotism-curry-creatable-rubble'
})
self.assertFalse(form.is_valid())
self.assertEquals(len(form.errors), 1)
def test_login_invalid_data_six_words_AND_string(self):
"""Test login form with six valid words AND login string filled out."""
# duo-atlas-hypnotism-curry-creatable-rubble
form = LoginForm(data = {
'word_1': 'duo',
'word_2': 'atlas',
'word_3': 'hypnotism',
'word_4': 'curry',
'word_5': 'creatable',
'word_6': 'rubble',
'login_string': 'duo-atlas-hypnotism-curry-creatable-rubble'
})
self.assertFalse(form.is_valid())
self.assertEquals(len(form.errors), 1)
@tag('login-form')
class TestLoginFormAttributes(SimpleTestCase):
"""Test functions of the LoginForm (besides is_valid)"""
def test_build_code_phrase(self):
"""Test login form build_code_phrase method."""
form = LoginForm()
cleaned_word_data = ['word_1', 'word_2', 'word_3']
result = form.build_code_phrase(cleaned_word_data)
self.assertEqual(result, 'word_1-word_2-word_3')
def test_sanitize_login_string_all_dash_no_strip(self):
"""Test sanitize_login_string method with dash
separators and no whitespace to strip."""
......
......@@ -296,22 +296,20 @@ class CreateIdentifierView(TemplateView):
def login_view(request):
"""Generate a login form. Note that most processing for this view is in forms.py"""
results = {}
form = LoginForm(request.GET)
# if the LoginForm is filled out, clean data and join the words together
# using the forms join_words function (defined in the form.)
if form.is_valid():
# if there is a user_identifier in the form keys (sanitized login_string field):
if 'user_identifier' in form.cleaned_data.keys():
user_identifier = form.cleaned_data['user_identifier']
# redirect to user-landing view, passing results dictionary as kwarg
# redirect to user-landing view, passing user_identifier to url
return redirect('user-landing', user_identifier = user_identifier)
else:
return render (request, 'anonticket/user_login.html', {'form':form, 'results': results})
# if no valid post request, display the form
return render (request, 'anonticket/user_login.html', {'form':form})
# if no valid user_identifier in GET, just display the form
else:
# form = LoginForm
return render (request, 'anonticket/user_login.html', {'form': form})
return render (request, 'anonticket/user_login.html', {'form':form, 'results': results})
# If everything else fails, just render the form.
return render (request, 'anonticket/user_login.html', {'form':form})
@validate_user
def user_landing_view(request, user_identifier):
......
......@@ -76,9 +76,9 @@ ul.flex-form {
.flex-form li {
flex-basis: 16%;
}
.flex-form label {
/* .flex-form label {
display: none;
}
} */
button.new-line{
flex-basis: 1;
}
......
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