Beispiel #1
0
def index(request):
    context = {'boards': Board.objects.all()[:6]}
    if request.method == 'POST':
        context['result'] = '0'
        if request.POST.get('email'):
            email = request.POST.get('email').lower()
            try:
                validate_email_address(email)
            except:
                context['result'] = '7'
            else:
                subscriber, created = Subscriber.objects.get_or_create(
                    email=email)
                if not subscriber.email_validated:
                    validation, created = SubscriberValidation.objects.get_or_create(
                        subscriber=subscriber)
                    ctx = {
                        'url':
                        'https://kids.cbsoft.ro/validate/{}'.format(
                            validation.code)
                    }
                    send_email('frontend/validate_email.html',
                               'Confirma adresa ta de email', ctx,
                               validation.subscriber.email)
    context['abonati'] = Subscriber.objects.count()
    return render(request, 'frontend/index.html', context)
Beispiel #2
0
    def validate_password(self, value):
        email = self.initial_data.get('email')
        user = ""
        try:
            validate_email_address(email)
            user = get_user_model().objects.get(email=email)
        except:
            pass

        if user and not user.check_password(value):
            raise serializers.ValidationError("Incorrect password entered.")
        return value
Beispiel #3
0
 def validate_email(email):
     validate_email_address(email)
     if email:
         try:
             user = get_user_model().objects.get(email=email.lower())
             if user.is_active and user.username:
                 return user
             raise
         except get_user_model().DoesNotExist:
             pass
         except:
             raise serializers.ValidationError("This user has not been activated")
     raise serializers.ValidationError("Invalid credentials provided")
Beispiel #4
0
 def validate(self, attrs):
     try:
         validate_email_address(attrs.get('username'))
         temp_user = get_user_model().objects.get(
             email=attrs.get('username').lower())
         if temp_user.check_password(attrs.get('password')):
             if temp_user.username:
                 attrs['username'] = temp_user.username
             elif temp_user.user_type == "FACULTY":
                 return temp_user
     except:
         attrs['username'] = attrs.get('username').lower()
         pass
     user = authenticate(**attrs)
     if user and user.is_active:
         return user
     raise serializers.ValidationError(
         {
             'error': "Incorrect credentials",
             'username': "******"
         }, 422)
Beispiel #5
0
    def validate_email(value):

        try:
            validate_email_address(value)
        except:
            raise serializers.ValidationError("Invalid email entered.")

        try:
            user = get_user_model().objects.get(email=value)
        except:
            raise serializers.ValidationError("This email is not registered.")

        try:
            user = get_user_model().objects.get(email=value)
            if user.username:
                raise
        except:
            raise serializers.ValidationError(
                "This email is already registered.")

        return value