-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added account, feedback form, edit profile
- Loading branch information
Showing
56 changed files
with
848 additions
and
302 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
[MASTER] | ||
ignore=migrations | ||
ignore=migrations | ||
disable=C0114, # missing-module-docstring |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
from django import forms | ||
from django.contrib.auth.forms import PasswordChangeForm | ||
|
||
|
||
class ChangePasswordForm(PasswordChangeForm): | ||
old_password = forms.CharField( | ||
label="Old password", | ||
strip=False, | ||
widget=forms.PasswordInput( | ||
attrs={"autocomplete": "current-password", "autofocus": True, 'class': 'form-control'} | ||
), | ||
) | ||
|
||
new_password1 = forms.CharField( | ||
label="New Password", | ||
help_text='Please use 8 or more characters with a mix of letters, numbers & symbols', | ||
widget=forms.PasswordInput(attrs={'class': 'form-control'}, ) | ||
) | ||
new_password2 = forms.CharField( | ||
label="Confirm New Password", | ||
widget=forms.PasswordInput(attrs={'class': 'form-control'}), | ||
) | ||
|
||
def clean_new_password2(self): | ||
new_password1 = self.cleaned_data.get('new_password1') | ||
new_password2 = self.cleaned_data.get('new_password2') | ||
|
||
if new_password1 and new_password2 and new_password1 != new_password2: | ||
raise forms.ValidationError("Passwords do not match.") | ||
return new_password2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
from django import forms | ||
from django.contrib.auth import get_user_model | ||
|
||
|
||
class UpdateUsernameForm(forms.ModelForm): | ||
class Meta: | ||
model = get_user_model() | ||
fields = ['username'] | ||
help_texts={ | ||
'username': 'Letters, digits and "_" only allowed.' | ||
} | ||
labels = { | ||
"username": "New username", | ||
} | ||
|
||
widgets = { | ||
'username': forms.TextInput(attrs={ | ||
'class': 'form-control', | ||
'placeholder': 'Username', | ||
}), | ||
} | ||
|
||
def clean_username(self): | ||
new_username = self.cleaned_data['username'] | ||
user_model = get_user_model() | ||
|
||
# Check if the new username is available | ||
if user_model.objects.filter(username=new_username).exclude(pk=self.instance.pk).exists(): | ||
raise forms.ValidationError('This username is already in use. Please choose a different one.') | ||
|
||
return new_username |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,55 +1,36 @@ | ||
from django.core.mail import send_mail | ||
from django.template.loader import render_to_string | ||
from django.urls import reverse | ||
|
||
from bloggy import settings | ||
|
||
|
||
def send_custom_email(subject, recipients, template, args, from_email=settings.DEFAULT_FROM_EMAIL): | ||
def send_html_email(subject, to_email, template, args, from_email=settings.DEFAULT_FROM_EMAIL): | ||
email_body = render_to_string(template, args) | ||
send_mail( | ||
subject, | ||
email_body, | ||
from_email, | ||
recipients, | ||
to_email, | ||
fail_silently=False, | ||
html_message=email_body | ||
) | ||
|
||
|
||
def send_newsletter_verification_token(request, email, uuid, token): | ||
subject = f'Confirm to {settings.SITE_TITLE} newsletter' | ||
|
||
args = { | ||
"email_subject": subject, | ||
"app_name": settings.SITE_TITLE, | ||
"verification_link": request.build_absolute_uri(reverse("newsletter_verification", args=[uuid, token])) | ||
} | ||
|
||
send_custom_email(subject, [email], "email/newsletter_verification_token.html", args) | ||
|
||
|
||
def email_verification_token(request, new_user, token): | ||
subject = f"{settings.SITE_TITLE} confirmation code: {token.code}" | ||
args = { | ||
"email_subject": subject, | ||
"verification_code": token.code, | ||
"app_name": settings.SITE_TITLE, | ||
"verification_link": request.build_absolute_uri(reverse("otp_verification", args=[token.uuid])) | ||
} | ||
send_custom_email(subject, [new_user.email], "email/login_code_email.html", args) | ||
|
||
|
||
def send_account_activation_email(request, new_user, verification_token): | ||
subject = f'Welcome to {settings.SITE_TITLE}!' | ||
args = { | ||
"email_subject": subject, | ||
"user_name": new_user.name, | ||
"app_name": settings.SITE_TITLE, | ||
"verification_link": request.build_absolute_uri(reverse("activate_account", args=[ | ||
verification_token.uuid, | ||
verification_token.token | ||
])) | ||
} | ||
def send_plain_email(subject, to_email, message_content, from_email=settings.DEFAULT_FROM_EMAIL): | ||
send_mail( | ||
subject, | ||
message_content, | ||
from_email, | ||
to_email, | ||
fail_silently=False, | ||
) | ||
|
||
send_custom_email(subject, [new_user.email], "email/account_activation_email.html", args) | ||
# def email_verification_token(request, new_user, token): | ||
# subject = f"{settings.SITE_TITLE} confirmation code: {token.code}" | ||
# args = { | ||
# "email_subject": subject, | ||
# "verification_code": token.code, | ||
# "app_name": settings.SITE_TITLE, | ||
# "verification_link": request.build_absolute_uri(reverse("otp_verification", args=[token.uuid])) | ||
# } | ||
# send_html_email(subject, [new_user.email], "email/login_code_email.html", args) |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.