(self)
Validate a password request.
Validate a password request.
Validate a password request .
def _validate_password(self):
        """Validate a password request."""
        if self.username is None and self.email is None:
            raise InvalidRequest('No username')
        if self.password is None:
            raise InvalidRequest('No password')
        if self.scope is not None:
            access_ranges = AccessRange.objects.filter(key__in=self.scope)
            access_ranges = set(access_ranges.values_list('key', flat=True))
            difference = access_ranges.symmetric_difference(self.scope)
            if len(difference) != 0:
                raise InvalidScope("""Following access ranges do not
                    exist: %s""" % ', '.join(difference))
            if self.authorized_scope is not None:
                new_scope = self.scope - self.authorized_scope
                if len(new_scope) > 0:
                    raise InvalidScope(
                        "Invalid scope request: %s" % ', '.join(new_scope))
        if "HTTP_AUTHORIZATION" in self.request.META:
            authorization = self.request.META["HTTP_AUTHORIZATION"]
            auth_type, auth_value = authorization.split()[0:2]
            if auth_type.lower() == "basic":
                credentials = "%s:%s" % (self.client.key, self.client.secret)
                if auth_value != b64encode(credentials):
                    raise InvalidClient('Client authentication failed.')
            else:
                raise InvalidClient('Client authentication failed.')
        else:
            raise InvalidClient('Client authentication failed.')
        if self.username is not None:
            user = authenticate(username=self.username, password=self.password)
        else:
            user = authenticate(email=self.email, password=self.password)
        if user is not None:
            if not user.is_active:
                raise InvalidRequest('Inactive user.')
        else:
            raise InvalidRequest('User authentication failed.')
        self.user = user
def _validate_password ( self ) : if self . username is None and self . email is None : raise InvalidRequest ( 'No username' ) if self . password is None : raise InvalidRequest ( 'No password' ) if self . scope is not None : access_ranges = AccessRange . objects . filter ( key__in = self . scope ) access_ranges = set ( access_ranges . values_list ( 'key' , flat = True ) ) difference = access_ranges . symmetric_difference ( self . scope ) if len ( difference ) != 0 : raise InvalidScope ( """Following access ranges do not
                    exist: %s""" % ', ' . join ( difference ) ) if self . authorized_scope is not None : new_scope = self . scope - self . authorized_scope if len ( new_scope ) > 0 : raise InvalidScope ( "Invalid scope request: %s" % ', ' . join ( new_scope ) ) if "HTTP_AUTHORIZATION" in self . request . META : authorization = self . request . META [ "HTTP_AUTHORIZATION" ] auth_type , auth_value = authorization . split ( ) [ 0 : 2 ] if auth_type . lower ( ) == "basic" : credentials = "%s:%s" % ( self . client . key , self . client . secret ) if auth_value != b64encode ( credentials ) : raise InvalidClient ( 'Client authentication failed.' ) else : raise InvalidClient ( 'Client authentication failed.' ) else : raise InvalidClient ( 'Client authentication failed.' ) if self . username is not None : user = authenticate ( username = self . username , password = self . password ) else : user = authenticate ( email = self . email , password = self . password ) if user is not None : if not user . is_active : raise InvalidRequest ( 'Inactive user.' ) else : raise InvalidRequest ( 'User authentication failed.' ) self . user = user