B
B
blackbb2017-06-01 14:33:30
Django
blackbb, 2017-06-01 14:33:30

How to make reviews with verification by email?

Added reviews to the site on the site:

class Review(models.Model):
    name = models.CharField(max_length=300, verbose_name='Имя')
    school = models.ForeignKey(School, verbose_name='Школа')
    email =models.EmailField(verbose_name='Почта')
    body = models.TextField(verbose_name='Описание')

Views.py:
class ReviewAdd(CreateView):
    model = Review
    form_class = ReviewAddForm
    template_name = 'school/review_add.html'
    def form_valid(self,form):
        self.object = form.save(commit=False)
        school = get_object_or_404(School, slug=self.kwargs['slug'])
        self.object.school = school
        self.object.save()
        return super(ReviewAdd, self).form_valid(form)

forms.py:
class ReviewAddForm(forms.ModelForm):
    class Meta:
        model = Review
        fields = '__all__'
        exclude = ['school']

I want to add verification by email when adding a review. Those. a person writes a review, clicks send and it is redirected to a page where it says "Thank you blah blah blah, a confirmation link has been sent to your mail, follow it to complete." A message comes to the mail, we follow the link and the review is published.
How to correctly implement such verification?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
Peter, 2017-06-01
@petermzg

1. Add a Verificated field to the Review model, which will initially be set to False.
2. Send an email with the ID of the created record, and in order not to be faked, for example, add md5 from the Review fields
3. When the user clicked on the link, check the ID and MD5 for him.
4. If everything is fine, then change the value of the Verificated field to True
5. Show the "Review published" page

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question