Skip to content

Commit

Permalink
Merge pull request #7 from kkkkkkkkatya/manage
Browse files Browse the repository at this point in the history
add send emails feature
  • Loading branch information
kkkkkkkkatya authored Mar 18, 2024
2 parents 501bd96 + 693ce3c commit 52be00d
Show file tree
Hide file tree
Showing 10 changed files with 65 additions and 3 deletions.
Binary file modified OnlineBookClub/__pycache__/settings.cpython-311.pyc
Binary file not shown.
12 changes: 10 additions & 2 deletions OnlineBookClub/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,10 @@

AUTHENTICATION_BACKENDS = [
# Needed to login by username in Django admin, regardless of `allauth`
'django.contrib.auth.backends.ModelBackend',
#'django.contrib.auth.backends.ModelBackend',

# `allauth` specific authentication methods, such as login by email
#'allauth.account.auth_backends.AuthenticationBackend',
'allauth.account.auth_backends.AuthenticationBackend',

]

Expand Down Expand Up @@ -169,3 +169,11 @@
# https://docs.djangoproject.com/en/5.0/ref/settings/#default-auto-field

DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'


EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_PORT = 587
EMAIL_USE_TLS = True
EMAIL_HOST_USER = '[email protected]'
EMAIL_HOST_PASSWORD = 'bjtsvjnnmjypxmrb'
Binary file modified db.sqlite3
Binary file not shown.
10 changes: 10 additions & 0 deletions main/templates/main/layout.html
Original file line number Diff line number Diff line change
Expand Up @@ -82,5 +82,15 @@
<main class="container">
{% block content %}{% endblock %}
</main>

{% if messages %}
<ul class="messages">
{% for message in messages %}
<li{% if message.tags %} class="{{ message.tags }}"{% endif %}>{{ message }}
</li>
{% endfor %}
</ul>
{% endif %}

</body>
</html>
Binary file modified registry/__pycache__/apps.cpython-311.pyc
Binary file not shown.
Binary file added registry/__pycache__/signals.cpython-311.pyc
Binary file not shown.
Binary file modified registry/__pycache__/views.cpython-311.pyc
Binary file not shown.
3 changes: 3 additions & 0 deletions registry/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@
class RegistryConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'registry'

def ready(self):
import registry.signals
22 changes: 22 additions & 0 deletions registry/signals.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from django.db.models.signals import post_save
from django.dispatch import receiver
from django.contrib.auth.models import User
from django.contrib.auth.signals import user_logged_in
from .views import welcome_email


# Signal receiver for post_save
@receiver(post_save, sender=User)
def check_new_user(sender, instance, created, **kwargs):
if created:
instance._newly_created = True
print(f"_newly_created attribute for user {instance.username}: {instance._newly_created}")
elif not hasattr(instance, '_newly_created'):
instance._newly_created = False


@receiver(user_logged_in)
def send_welcome_email_if_new(sender, request, user, **kwargs):
if (getattr(user, '_newly_created')):
#and request.user.backend == 'allauth.account.auth_backends.AuthenticationBackend'):
welcome_email(request)
21 changes: 20 additions & 1 deletion registry/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,23 @@
from django.contrib.auth import login, authenticate, logout
from django.contrib import messages
from django.contrib.auth.forms import AuthenticationForm
from django.core.mail import send_mail
from django.conf import settings
from django.contrib.auth.decorators import login_required


@login_required
def welcome_email(request):
username = request.user
print("username = ", username)
email = request.user.email
print("email = ", email)
subject = 'Welcome to our Book Club!'
message = f'Hi {username}, thank you for choosing our book club. Now you can be the part of a reading family! '
from_email = settings.EMAIL_HOST_USER
recipient_list = [email]
send_mail(subject, message, from_email, recipient_list, fail_silently=False)
return redirect("main:home")


def register_request(request):
Expand Down Expand Up @@ -48,4 +65,6 @@ def login_request(request):
def logout_request(request):
logout(request)
messages.info(request, "You have successfully logged out.")
return redirect("main:home")
return redirect("main:home")


0 comments on commit 52be00d

Please sign in to comment.