diff --git a/crispy_ai/settings.py b/crispy_ai/settings.py index f0e7af3..e46ffef 100644 --- a/crispy_ai/settings.py +++ b/crispy_ai/settings.py @@ -126,8 +126,12 @@ LOGIN_REDIRECT_URL = '/users/' # LOGOUT_REDIRECT_URL = '/' -EMAIL_HOST = 'localhost' +EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend' +EMAIL_HOST = 'smtp.gmail.com' EMAIL_PORT = 587 +EMAIL_HOST_USER = os.environ.get('HOST_EMAIL') +EMAIL_HOST_PASSWORD = os.environ.get('HOST_EMAIL_PASSWORD') +EMAIL_USE_TLS = True # crispy_forms CRISPY_TEMPLATE_PACK = 'bootstrap4' diff --git a/users/forms.py b/users/forms.py index 2b9c135..3391dc6 100644 --- a/users/forms.py +++ b/users/forms.py @@ -2,6 +2,7 @@ from django import forms from django.contrib.auth.models import User from .models import ProfileModel +from django.forms import ValidationError class UserRegisterForm(UserCreationForm): @@ -11,6 +12,19 @@ class Meta: model = User fields = ['username', 'email', 'password1', 'password2'] + def clean(self): + cleaned_data = super(UserRegisterForm, self).clean() + + try: + email = cleaned_data['email'] + except KeyError: + raise ValidationError("") + + if email and User.objects.filter(email=email).count() > 0: + raise ValidationError(u"Email already exists.") + + return cleaned_data + class UserUpdateForm(forms.ModelForm): email = forms.EmailField(max_length=254, help_text='Please provide a valid email address.') diff --git a/users/templates/registration/account_activated.html b/users/templates/registration/account_activated.html new file mode 100644 index 0000000..24ea887 --- /dev/null +++ b/users/templates/registration/account_activated.html @@ -0,0 +1,13 @@ +{% extends 'baseApp/base.html' %} + +{% block title %} +
Please use this link to Login to Crispy AI
+