Skip to content

Commit

Permalink
Fixed bugs with authentication.
Browse files Browse the repository at this point in the history
  • Loading branch information
Rob Vaterlaus committed Dec 21, 2010
1 parent 027c946 commit d35c95f
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions django_cassandra/db/base.py
Expand Up @@ -69,7 +69,7 @@ def login(self):
# TODO: This user/password auth code hasn't been tested
if not self.logged_in:
if self.user:
credentials = {'username': user, 'password': password}
credentials = {'username': self.user, 'password': self.password}
self.client.login(AuthenticationRequest(credentials))
self.logged_in = True

Expand All @@ -82,12 +82,12 @@ def open(self, set_keyspace=False, login=False):
transport.open()
self.transport = transport
self.client = Cassandra.Client(protocol)

if set_keyspace:
self.set_keyspace()

if login:
self.login()

if set_keyspace:
self.set_keyspace()

def close(self):
if self.transport != None:
Expand Down Expand Up @@ -151,7 +151,6 @@ def get_db_connection(self, set_keyspace=False, login=False):
password = self.settings_dict.get('PASSWORD')

# Create our connection wrapper
print "Creating Cassandra connection"
self._db_connection = CassandraConnection(host, port, keyspace, user, password)

if not self._db_connection.is_connected():
Expand All @@ -161,6 +160,13 @@ def get_db_connection(self, set_keyspace=False, login=False):
# FIXME: Should do some version check here to make sure that we're
# talking to a cassandra daemon that supports the operations we require

if login:
try:
self._db_connection.login()
except Exception, e:
# FIXME: Better handling of auth error
raise e

if set_keyspace:
try:
self._db_connection.set_keyspace()
Expand All @@ -178,13 +184,6 @@ def get_db_connection(self, set_keyspace=False, login=False):
self._db_connection.client.system_add_keyspace(keyspace_def)
self._db_connection.set_keyspace()

if login:
try:
self._db_connection.login()
except Exception, e:
# FIXME: Better handling of auth error
raise e

return self._db_connection

@property
Expand Down

0 comments on commit d35c95f

Please sign in to comment.