diff --git a/mysite/settings.py b/mysite/settings.py index 572a80b..f5523db 100644 --- a/mysite/settings.py +++ b/mysite/settings.py @@ -126,3 +126,9 @@ STATICFILES_DIRS = [BASE_DIR] # https://docs.djangoproject.com/en/4.2/ref/settings/#default-auto-field DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' + +LOGIN_REDIRECT_URL = "home_redirect" +LOGOUT_REDIRECT_URL = "home_redirect" + +EMAIL_BACKEND = "django.core.mail.backends.filebased.EmailBackend" +EMAIL_FILE_PATH = BASE_DIR / "sent_emails" \ No newline at end of file diff --git a/mysite/urls.py b/mysite/urls.py index 1b67d3f..5e952b1 100644 --- a/mysite/urls.py +++ b/mysite/urls.py @@ -7,4 +7,5 @@ urlpatterns = [ path('', RedirectView.as_view(pattern_name='polls:index'), name='home_redirect'), path("polls/", include("polls.urls")), path('admin/', admin.site.urls), + path("accounts/", include("django.contrib.auth.urls")), ] diff --git a/polls/forms.py b/polls/forms.py new file mode 100644 index 0000000..1e738ea --- /dev/null +++ b/polls/forms.py @@ -0,0 +1,27 @@ +from django import forms +from django.contrib.auth.forms import UserCreationForm +from django.contrib.auth.models import User + + +class SignUpForm(UserCreationForm): + tailwind_class = "w-full border-2 border-gray-300 bg-gray-100 rounded-lg focus:ring focus:border-blue-300 focus:shadow-none" + + username = forms.CharField(widget=forms.TextInput(attrs={'class': tailwind_class}), + error_messages={ + 'unique': 'This username is already in use.', + 'invalid': 'Invalid username format.', + 'max_length': 'Username should not exceed 150 characters.', + } + ) + password1 = forms.CharField(widget=forms.PasswordInput(attrs={'class': tailwind_class}), + error_messages={'min_length': 'Password must contain at least 8 characters.',} + ) + password2 = forms.CharField(widget=forms.PasswordInput(attrs={'class': tailwind_class}),) + + class Meta: + model = User + fields = ('username', 'password1', 'password2') + + error_messages = { + 'password_mismatch': "The two password fields didn't match.", + } \ No newline at end of file diff --git a/polls/models.py b/polls/models.py index 1e06a4e..24d3eb2 100644 --- a/polls/models.py +++ b/polls/models.py @@ -14,6 +14,7 @@ from django.utils import timezone from django.contrib import admin from django.core.validators import MaxValueValidator, MinValueValidator from django.db.models import Sum +from django.contrib.auth.models import User class Question(models.Model): diff --git a/polls/templates/polls/index.html b/polls/templates/polls/index.html index ff23cdc..3451240 100644 --- a/polls/templates/polls/index.html +++ b/polls/templates/polls/index.html @@ -26,15 +26,22 @@ - - + {% if user.is_authenticated %} + + + Sign out 😠+ + {% else %} + Sign in 😎 + {% endif %} diff --git a/polls/templates/registration/login.html b/polls/templates/registration/login.html new file mode 100644 index 0000000..99361b9 --- /dev/null +++ b/polls/templates/registration/login.html @@ -0,0 +1,37 @@ + + +
+ + ++ Don't have an account? Sign up here +
++ Forget the Password? Reset here +
+ Back to Poll +Your new password has been set. You can log in now on the log in page.
\ No newline at end of file diff --git a/polls/templates/registration/password_reset_confirm.html b/polls/templates/registration/password_reset_confirm.html new file mode 100644 index 0000000..13db400 --- /dev/null +++ b/polls/templates/registration/password_reset_confirm.html @@ -0,0 +1,12 @@ +{% if validlink %} + +The password reset link was invalid, possibly because it has already been used. Please request a new password reset.
\ No newline at end of file diff --git a/polls/templates/registration/password_reset_done.html b/polls/templates/registration/password_reset_done.html new file mode 100644 index 0000000..fa1ed5a --- /dev/null +++ b/polls/templates/registration/password_reset_done.html @@ -0,0 +1,2 @@ +We've emailed you instructions for setting your password. You should receive the email shortly!
\ No newline at end of file diff --git a/polls/templates/registration/password_reset_form.html b/polls/templates/registration/password_reset_form.html new file mode 100644 index 0000000..98b091c --- /dev/null +++ b/polls/templates/registration/password_reset_form.html @@ -0,0 +1,8 @@ +Enter your email address below, and we'll email instructions for setting a new one.
+ + \ No newline at end of file diff --git a/polls/templates/registration/signup.html b/polls/templates/registration/signup.html new file mode 100644 index 0000000..0bac13d --- /dev/null +++ b/polls/templates/registration/signup.html @@ -0,0 +1,46 @@ + + + + +