示例#1
0
    def is_valid(self, request, save_password=True):
        if not super(AuthorizeForm, self).is_valid():
            return False
        
        username = self.cleaned_data['username']
        password = self.cleaned_data['password']
        zipcode = self.cleaned_data['zipcode'].strip()
        
        invalid_zipcode = True
        if not zipcode:
            self.errors['zipcode'] = ('Please enter a zipcode',)
        #elif not zipcode_re.match(zipcode):
        #    self.errors['zipcode'] = ('Please enter a valid 5-digit zipcode',)
        else:
            invalid_zipcode = False

        invalid_user = True
        if not view_utils.verify_password(username, password):
            self.errors['password'] = ("Password does not match username",)
        else:
            invalid_user = False
            
        if not invalid_zipcode and not invalid_user:
            # user is authorized and we have zipcode so proceed
            twitter_user = TwitterUser.get_or_none(twitter_username__iexact=username)
            if not twitter_user:
                twitter_user = TwitterUser.add(twitter_username=username)
            # save data
            if save_password:
                twitter_user.password = password
            twitter_user.zipcode = zipcode
            twitter_user.get_user_data()
            twitter_user.save()
            view_utils.log_in(request, twitter_user)
            return True
        return False
示例#2
0
 def is_valid(self):
     if not forms.Form.is_valid(self):
         return False
     
     username = self.cleaned_data['username']
     password = self.cleaned_data['password']
     
     if not view_utils.verify_password(username, password):
         self.errors['password'] = ("Password does not match username",)
         return False
     
     else:
         # user is authorized and we have zipcode so proceed
         twitter_user = TwitterUser.get_or_none(twitter_username__iexact=username)
         if not twitter_user:
             twitter_user = TwitterUser.add(twitter_username=username)
         # save data
         if self.save_password:
             twitter_user.password = password
         twitter_user.zipcode = zipcode
         twitter_user.get_user_data()
         twitter_user.save()
         view_utils.log_in(request, twitter_user)
         return True