コード例 #1
0
ファイル: forms.py プロジェクト: jrpotter/mingle
    def clean(self):
        cleaned_data = super().clean()
        validator.strip_values(["name", "email", "password"], cleaned_data)
        try:
            alias = Alias.objects.get(email=cleaned_data["email"])
            msg = "An account has been made with this email"
            self._errors["email"] = self.error_class([msg])
            raise forms.ValidationError(msg)
        except Alias.DoesNotExist:
            pass

        return cleaned_data
コード例 #2
0
ファイル: forms.py プロジェクト: jrpotter/mingle
    def clean(self):
        """
        Check the user's (if he exists) provided password matches salted password.
        """
        cleaned_data = super().clean()
        validator.strip_values(["email", "password"], cleaned_data)

        try:
            # Check the user's password matches
            alias = Alias.objects.get(email=cleaned_data["email"])
            sha = hashlib.sha256((alias.salt + cleaned_data["password"]).encode("UTF-8"))
            digest = base64.b64encode(sha.digest()).decode()
            if digest != alias.password:
                raise forms.ValidationError("User's password does not match expected value")

        except Alias.DoesNotExist:
            raise forms.ValidationError("User does not have a mingle account")

        return cleaned_data