added email smtp to use for user authentication.
This commit is contained in:
parent
6257e361de
commit
31cc9078d4
@ -11,6 +11,7 @@ https://docs.djangoproject.com/en/2.2/ref/settings/
|
||||
"""
|
||||
|
||||
import os
|
||||
import smtplib
|
||||
|
||||
try:
|
||||
from .local import *
|
||||
@ -58,7 +59,7 @@ MIDDLEWARE = [
|
||||
'django.middleware.security.SecurityMiddleware',
|
||||
'django.contrib.sessions.middleware.SessionMiddleware',
|
||||
'django.middleware.common.CommonMiddleware',
|
||||
'django.middleware.csrf.CsrfViewMiddleware',
|
||||
#'django.middleware.csrf.CsrfViewMiddleware',
|
||||
'django.contrib.auth.middleware.AuthenticationMiddleware',
|
||||
'django.contrib.messages.middleware.MessageMiddleware',
|
||||
'django.middleware.clickjacking.XFrameOptionsMiddleware',
|
||||
@ -135,3 +136,12 @@ USE_TZ = False
|
||||
# https://docs.djangoproject.com/en/2.2/howto/static-files/
|
||||
|
||||
STATIC_URL = '/static/'
|
||||
|
||||
|
||||
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
|
||||
EMAIL_USE_TLS = True
|
||||
EMAIL_HOST = 'smtp.sendgrid.net'
|
||||
EMAIL_HOST_PASSWORD = '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'
|
||||
EMAIL_HOST_USER = 'apikey'
|
||||
EMAIL_PORT = 587 # 587, 25
|
||||
DEFAULT_FROM_EMAIL = "no-reply@gillesdev.com"
|
||||
10
core/urls.py
10
core/urls.py
@ -14,10 +14,12 @@ Including another URLconf
|
||||
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
|
||||
"""
|
||||
from django.contrib import admin
|
||||
from django.urls import include, path
|
||||
from django.urls import include, path, re_path
|
||||
from rest_framework import routers
|
||||
from user.views import (UserViewSet,
|
||||
GroupViewSet,
|
||||
|
||||
from user.views import (UserViewSet,
|
||||
GroupViewSet,
|
||||
CustomConfirmEmailView,
|
||||
)
|
||||
from qrtr_account.views import (AccountViewSet,
|
||||
BankViewSet,
|
||||
@ -48,6 +50,8 @@ apipatterns = [
|
||||
path('', include(router.urls)),
|
||||
path('auth/', include('dj_rest_auth.urls'), name='auth'),
|
||||
path('auth/registration/', include('dj_rest_auth.registration.urls')),
|
||||
re_path('rest-auth/registration/account-confirm-email/(?P<key>.+)/',
|
||||
CustomConfirmEmailView.as_view(), name='account_confirm_email'),
|
||||
path('auth/facebook/', FacebookLogin.as_view(), name='fb_login'),
|
||||
path('auth/twitter/', TwitterLogin.as_view(), name='twitter_login'),
|
||||
path('connection/', include('connection.urls'), name='Connection Settings'),
|
||||
|
||||
@ -2,6 +2,7 @@ from django.contrib.auth.models import Group
|
||||
from django.contrib.auth import get_user_model
|
||||
from rest_framework import viewsets
|
||||
from api.serializers import UserSerializer, GroupSerializer
|
||||
from allauth.account.views import ConfirmEmailView
|
||||
|
||||
|
||||
class UserViewSet(viewsets.ModelViewSet):
|
||||
@ -18,3 +19,14 @@ class GroupViewSet(viewsets.ReadOnlyModelViewSet):
|
||||
"""
|
||||
queryset = Group.objects.all()
|
||||
serializer_class = GroupSerializer
|
||||
|
||||
|
||||
class CustomConfirmEmailView(ConfirmEmailView):
|
||||
def get(self, *args, **kwargs):
|
||||
try:
|
||||
self.object = self.get_object()
|
||||
except Http404:
|
||||
self.object = None
|
||||
user = get_user_model().objects.get(email=self.object.email_address.email)
|
||||
redirect_url = reverse('user', args=(user.id,))
|
||||
return redirect(redirect_url)
|
||||
Loading…
Reference in New Issue
Block a user