Skip to content

Commit

Permalink
fixed issue with auth password column
Browse files Browse the repository at this point in the history
  • Loading branch information
josephmancuso committed Jan 11, 2019
1 parent e14d18e commit 4e8e143
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
5 changes: 4 additions & 1 deletion masonite/auth/Auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def login(self, name, password):
"""
auth_column = self.auth_model.__auth__
try:
password_column = self.auth_model.password if not hasattr(self.auth_model, '__password__') else self.auth_model.__password__
password_column = self._get_password_column()
except AttributeError as e:
raise AttributeError('Your model does not have a password column or a designated __password__ attribute. Set the __password__ attribute to the name of your password column.') from e

Expand Down Expand Up @@ -130,3 +130,6 @@ def once(self):
"""
self._once = True
return self

def _get_password_column(self):
return getattr(self.auth_model, self.auth_model.__password__) if hasattr(self.auth_model, '__password__') else self.auth_model.password
10 changes: 9 additions & 1 deletion tests/test_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class MockUser():

__auth__ = 'email'
password = '$2a$04$SXAMKoNuuiv7iO4g4U3ZOemyJJiKAHomUIFfGyH4hyo4LrLjcMqvS'
users_password = 'pass123'
email = 'user@email.com'
name = 'testuser123'
id = 1
Expand Down Expand Up @@ -44,6 +45,10 @@ class MockVerifyUser(MockUser, MustVerifyEmail):
pass


class ListUser(MockUser):
__password__ = 'users_password'


class TestAuth:

def setup_method(self):
Expand Down Expand Up @@ -72,6 +77,10 @@ def test_login_user_with_list_auth_column(self):
assert isinstance(self.auth.login('testuser123', 'secret'), user)
assert self.request.get_cookie('token')

def test_auth_gets_user_login_attribute(self):
auth = Auth(self.request, ListUser())
assert auth._get_password_column() == 'pass123'

def test_get_user(self):
assert self.auth.login_by_id(1)
assert isinstance(self.auth.user(), MockUser)
Expand Down Expand Up @@ -138,7 +147,6 @@ def test_confirm_controller_failure(self):
self.auth = Auth(self.request, MockVerifyUser())

timestamp_plus_11 = datetime.datetime.now() - datetime.timedelta(minutes=11)
print(timestamp_plus_11.timestamp())

params = {'id': Sign().sign('{0}::{1}'.format(1, timestamp_plus_11.timestamp()))}
self.request.set_params(params)
Expand Down

0 comments on commit 4e8e143

Please sign in to comment.