Skip to content

Commit

Permalink
Merge bfc04da into b16d9dc
Browse files Browse the repository at this point in the history
  • Loading branch information
josephmancuso committed May 29, 2019
2 parents b16d9dc + bfc04da commit d59cdfe
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ def up(self):
table.string('name')
table.string('email').unique()
table.string('password')
table.string('second_password').nullable()
table.string('remember_token').nullable()
table.timestamp('verified_at').nullable()
table.timestamps()
Expand Down
11 changes: 6 additions & 5 deletions masonite/auth/Auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ 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(model.password, 'utf-8')):
if model and bcrypt.checkpw(bytes(password, 'utf-8'), bytes(self._get_password_column(model), 'utf-8')):
if not self._once:
remember_token = str(uuid.uuid4())
model.remember_token = remember_token
Expand Down Expand Up @@ -130,11 +130,12 @@ def once(self):
self._once = True
return self

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__
if hasattr(model, '__password__'):
return getattr(model, model.__password__)

if hasattr(model, 'password'):
return getattr(model, 'password')

def register(self, user):
user['password'] = bcrypt_password(user['password'])
Expand Down
1 change: 1 addition & 0 deletions masonite/testing/DatabaseTestCase.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ def registerFactory(self, model, callable_factory):
self.factory.register(model, callable_factory)

def setUpDatabase(self):
self.tearDownDatabase()
subprocess.call(['craft', 'migrate'])

def tearDownDatabase(self):
Expand Down
14 changes: 11 additions & 3 deletions tests/core/test_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ def setUp(self):
User.create({
'name': 'testuser123',
'email': 'user@email.com',
'password': bcrypt_password('secret')
'password': bcrypt_password('secret'),
'second_password': bcrypt_password('pass123'),
})
self.app.bind('Container', self.app)
view = View(self.container)
Expand All @@ -47,10 +48,16 @@ def test_login_user(self):
self.assertTrue(self.auth.login('user@email.com', 'secret'))
self.assertTrue(self.request.get_cookie('token'))

# def test_login_user_with_list_auth_column(self):
# self.assertTrue(self.auth.login('testuser123', 'secret'))
# def test_can_login_with_second_password(self):
# self.auth.auth_model.__password__ = 'second_password'
# self.assertTrue(self.auth.login('user@email.com', 'pass123'))
# self.assertTrue(self.request.get_cookie('token'))

def test_login_user_with_list_auth_column(self):
self.auth.auth_model.__auth__ = ['name', 'email']
self.assertTrue(self.auth.login('testuser123', 'secret'))
self.assertTrue(self.request.get_cookie('token'))

def test_can_register(self):
self.auth.register({
'name': 'Joe',
Expand All @@ -71,6 +78,7 @@ def test_get_user_returns_false_if_not_loggedin(self):
def test_logout_user(self):
self.auth.login('user@email.com', 'secret')
self.assertTrue(self.request.get_cookie('token'))
self.assertTrue(self.auth.user())

self.auth.logout()
self.assertFalse(self.request.get_cookie('token'))
Expand Down

0 comments on commit d59cdfe

Please sign in to comment.