def form_valid(self, form): """ Validated email fields and send email. """ # Send email to admin send_email_template( subject=_("PGTBL - message from {0}" .format(form.cleaned_data['name']) ), template='core/email.html', from_email=form.cleaned_data['email'], context={ 'name': form.cleaned_data['name'], 'email': form.cleaned_data['email'], 'message': form.cleaned_data['message'] }, recipient_list=[settings.DEFAULT_FROM_EMAIL], ) messages.success( self.request, _("Message sent successfully.") ) # Redirect to success_url return super(HomePageView, self).form_valid(form)
def form_valid(self, form): """ Validated form and send email. """ user = User.objects.get(email=form.cleaned_data['email']) # Generate unique key to reset password key = generate_hash_key(user.username) reset_password = PasswordReset(user=user, key=key) reset_password.save() # Send email send_email_template( subject=_('Requesting new password'), template='accounts/reset_password_email.html', context={'reset_password': reset_password}, recipient_list=[user.email], ) messages.success( self.request, _("An email was sent with more details on how to create a new password" )) # Redirect to success_url return super(ResetPasswordView, self).form_valid(form)