Skip to content

Commit

Permalink
Merge 90764a9 into 4e8e143
Browse files Browse the repository at this point in the history
  • Loading branch information
josephmancuso committed Jan 11, 2019
2 parents 4e8e143 + 90764a9 commit 28cafb8
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 9 deletions.
18 changes: 11 additions & 7 deletions masonite/auth/Auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,6 @@ def login(self, name, password):
object|bool -- Returns the current authenticated user object or False or None if there is none.
"""
auth_column = self.auth_model.__auth__
try:
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

try:
# Try to login multiple or statements if given an auth list
Expand All @@ -79,7 +75,12 @@ def login(self, name, password):
else:
model = self.auth_model.where(auth_column, name).first()

if model and bcrypt.checkpw(bytes(password, 'utf-8'), bytes(password_column, 'utf-8')):
# try:
# password_column = self._get_password_value(model)
# 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

if model and bcrypt.checkpw(bytes(password, 'utf-8'), bytes(model.password, 'utf-8')):
if not self._once:
remember_token = str(uuid.uuid4())
model.remember_token = remember_token
Expand Down Expand Up @@ -131,5 +132,8 @@ 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
def _get_password_value(self, model):
return getattr(model, model.__password__) if hasattr(model, '__password__') else model.password

def _get_password_column(self, model):
return 'password' if not hasattr(model, '__password__') else model.__password__
2 changes: 1 addition & 1 deletion masonite/info.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
"""Module for specifying the Masonite version in a central location."""

VERSION = '2.1.9'
VERSION = '2.1.10'
12 changes: 11 additions & 1 deletion tests/test_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,17 @@ def test_login_user_with_list_auth_column(self):

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

auth = Auth(self.request, MockUser())
assert auth._get_password_value(MockUser()) == '$2a$04$SXAMKoNuuiv7iO4g4U3ZOemyJJiKAHomUIFfGyH4hyo4LrLjcMqvS'

def test_auth_gets_user_login_attribute_column(self):
auth = Auth(self.request, ListUser())
assert auth._get_password_column(ListUser()) == 'users_password'

auth = Auth(self.request, MockUser())
assert auth._get_password_column(MockUser()) == 'password'

def test_get_user(self):
assert self.auth.login_by_id(1)
Expand Down

0 comments on commit 28cafb8

Please sign in to comment.