Commit f17954bd authored by Antoine Millet's avatar Antoine Millet
Browse files

Updated authentify handler method to raises better exceptions.

parent 3de8193d
Loading
Loading
Loading
Loading
+5 −8
Original line number Diff line number Diff line
@@ -234,19 +234,16 @@ class WelcomeHandler(CCHandler):
        try:
            role = self._server.conf.authentify(login, password)
        except CCConf.UnknownAccount:
            raise AuthenticationError('Authentication failure (Unknown login)')
            raise AuthenticationError('Unknown login')

        if role is None:
            logging.info('New authentication from %s: failure' % login)
            raise AuthenticationError('Authentication failure')
            raise AuthenticationError('Bad login/password')
        else:
            # If authentication is a success, try to register the client:
            try:
                self._server.register(login, role, connection)
                self._server.register(login, role, conn)
            except AlreadyRegistered:
                raise AuthenticationError('Authentication failure '
                                          '(already connected)')
            connection.set_handler(WelcomeHandler.ROLES.get(role)(self._server))
            logging.info('New authentication from %s: success' % login)
                raise AuthenticationError('Already connected')
            conn.set_handler(WelcomeHandler.ROLES.get(role)(self._server))
            
            return role