English 中文(简体)
如何在Django/Pinax中设置电子邮件验证/确认?
原标题:How to setup email verification/confirmation in Django/Pinax?

如何在Pinax中设置电子邮件确认?,我需要设置SMTP服务器或类似的东西吗?,我试图找到有关这方面的文件,但失败了。有人能把我重定向到文档或任何相关文章来解释这一点吗?,Pinax使用电子邮件确认应用程序。我浏览了电子邮件确认的代码,但它不包括任何关于主机或服务器的设置。

最佳回答

电子邮件确认的集成非常简单。如果你有一个可以用来发送邮件的现有邮件服务器,你不必设置任何邮件服务器。您只需在标准Django设置中填写用于发送邮件的数据,电子邮件确认将使用该数据:

# e-mail settings
# XXXXXXXXXXXXXXXXXXXXXXX     THESE ARE NOT YET PRODUCTIONREADY!
EMAIL_HOST= mail.your_mailserver.com 
EMAIL_PORT=1025
EMAIL_HOST_USER= your_username 
EMAIL_HOST_PASSWORD= your_password 

总结下一步要做的事情:你必须创建一个表单来输入电子邮件地址(为什么这样的表单没有附带电子邮件配置的原因有点模糊)。这看起来像这样:

# email form using emailconfirmation
class AddEmailForm(forms.Form):

    def __init__(self, *args, **kwargs):
        try:
            self.user = kwargs.pop( user )
        except KeyError:
            pass
        super(AddEmailForm, self).__init__(*args, **kwargs)

    email = forms.EmailField(label="Email",required=True, widget=forms.TextInput())

    def clean_email(self):
        try:
            EmailAddress.objects.get(user=self.user, email=self.cleaned_data["email"])
        except EmailAddress.DoesNotExist:
            try:
                User.objects.get(email = self.cleaned_data[ email ])
            except User.DoesNotExist:
                return self.cleaned_data["email"]
        raise forms.ValidationError(u"email address associated with another account.")

    def save(self):
        try:
            self.user.message_set.create(message="Confirmation email sent to %s" % self.cleaned_data["email"])
        except AttributeError:
            pass
        return EmailAddress.objects.add_email(self.user, self.cleaned_data["email"])

这将允许用户输入电子邮件地址,检查电子邮件地址是否存在并且是否被其他帐户使用。之后,它会将电子邮件添加到未确认的电子邮件中,并向用户发送一封带有链接的电子邮件。然后,用户可以通过单击链接确认电子邮件。

这就是全部。让我们希望Pinax的球员很快就能对他们的球队进行高质量的进攻;)

问题回答

暂无回答




相关问题
How to get two random records with Django

How do I get two distinct random records using Django? I ve seen questions about how to get one but I need to get two random records and they must differ.

Moving (very old) Zope/Plone Site to Django

I am ask to move data from a (now offline) site driven by Plone to a new Django site. These are the version informations I have: Zope Version (unreleased version, python 2.1.3 ) Python Version 2.1....

Can Django models use MySQL functions?

Is there a way to force Django models to pass a field to a MySQL function every time the model data is read or loaded? To clarify what I mean in SQL, I want the Django model to produce something like ...

Flexible pagination in Django

I d like to implement pagination such that I can allow the user to choose the number of records per page such as 10, 25, 50 etc. How should I go about this? Is there an app I can add onto my project ...

is it convenient to urlencode all next parameters? - django

While writing code, it is pretty common to request a page with an appended "next" query string argument. For instance, in the following template code next points back to the page the user is on: &...

Pragmatically adding give-aways/freebies to an online store

Our business currently has an online store and recently we ve been offering free specials to our customers. Right now, we simply display the special and give the buyer a notice stating we will add the ...

热门标签