Skip to content

Commit

Permalink
added password and username instruction, added error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
rashiranjan22 committed May 19, 2024
1 parent 8a0a80c commit bca295f
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 6 deletions.
39 changes: 39 additions & 0 deletions newsaggregator/static/assets/css/userauth.css
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ body {
flex-direction: column;
}


.main-container {
display: flex;
flex-grow: 1;
Expand Down Expand Up @@ -169,6 +170,7 @@ body {

.form-group {
margin: 0 40px 6px;

}

.animate-input {
Expand Down Expand Up @@ -376,6 +378,43 @@ button:disabled {
text-align: center;
}

.footer {
background: #f1f1f1;
padding: 20px;
text-align: center;
margin-top: auto;
}

.password-requirements {
list-style-type: disc;
margin-left: 20px;
margin-top: 10px;
margin-bottom: 20px;
font-size: 12px;
color: var(--txt-second-color);
padding-left: 20px;
}

.errors {
background-color: #f8d7da;
color: #721c24;
border: 1px solid #f5c6cb;
border-radius: 5px;
padding: 10px;
margin-bottom: auto;
margin-top: 20px;
}

.errors ul {
list-style-type: none;
padding: 0;
margin: 0;
}

.errors li {
margin-bottom: 5px;
}

/* responsive */

@media only screen and (max-width: 800px) {
Expand Down
28 changes: 22 additions & 6 deletions newsaggregator/templates/userauths/sign-up.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,19 @@
<img src="../../static/assets/images/news.png" width="80px" alt="News logo" class="logo-light">
<img src="../../static/assets/images/news.png" width="80px" alt="News logo" class="logo-dark">
</div>

{% if form.errors %}
<div class="errors">
<ul>
{% for field, error_list in form.errors.items %}
{% for error in error_list %}
<li>{{ error }}</li>
{% endfor %}
{% endfor %}
</ul>
<p>Please try again</p>
</div>
{% endif %}


<form method="POST">
Expand Down Expand Up @@ -43,7 +56,7 @@
Enter Password
</span>
<input class="login-signup-input" type="password" name="password1" autocomplete="new-password" required aria-describedby="id_password1_helptext" id="id_password1">
<button>Show</button>
<button type="button">Show</button>
</div>
</div>
<div class="form-group">
Expand All @@ -52,13 +65,16 @@
Enter confirm Password
</span>
<input class="login-signup-input" type="password" name="password2" autocomplete="new-password" required aria-describedby="id_password2_helptext" id="id_password2">
<button>Show</button>
<button type="button">Show</button>
</div>
</div>
<div class="form-group">
<div class="animate-input" style="border: none;">
<span>Enter password without special characters</span>
</div>
<div class="password-requirements">
<ul>
<li>Username must be atleast 6 characters long</li>
<li>Password must be at least 8 characters long</li>
<li>Password shouldn't be very similar to the username</li>
<li>Password shouldn't be entirely numeric</li>
</ul>
</div>
<div class="btn-groupss">
<button class="btn-login" id="signin-btn" type="submit">
Expand Down
8 changes: 8 additions & 0 deletions newsaggregator/userauths/forms.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
from django import forms
from django.contrib.auth.forms import UserCreationForm
from userauths.models import User
from django.core.exceptions import ValidationError


class UserRegisterForm(UserCreationForm):
email = forms.EmailField()

class Meta:
model = User
fields = ['username', 'email', 'password1', 'password2']

def clean_username(self):
username = self.cleaned_data.get('username')
if len(username) < 6:
raise ValidationError("Username must be at least 6 characters long.")
return username

0 comments on commit bca295f

Please sign in to comment.