Refactor to leverage all existing methods of auth handler
instead of importing and calling functions from core rattail
This commit is contained in:
parent
53fc1508f3
commit
232a02b944
7 changed files with 64 additions and 33 deletions
|
@ -2,7 +2,7 @@
|
|||
################################################################################
|
||||
#
|
||||
# Rattail -- Retail Software Framework
|
||||
# Copyright © 2010-2020 Lance Edgar
|
||||
# Copyright © 2010-2021 Lance Edgar
|
||||
#
|
||||
# This file is part of Rattail.
|
||||
#
|
||||
|
@ -26,7 +26,7 @@ Tailbone Web API - Auth Views
|
|||
|
||||
from __future__ import unicode_literals, absolute_import
|
||||
|
||||
from rattail.db.auth import authenticate_user, set_user_password, cache_permissions
|
||||
from rattail.db.auth import set_user_password
|
||||
|
||||
from cornice import Service
|
||||
|
||||
|
@ -82,15 +82,20 @@ class AuthenticationView(APIView):
|
|||
if error:
|
||||
return {'error': error}
|
||||
|
||||
app = self.get_rattail_app()
|
||||
auth = app.get_auth_handler()
|
||||
|
||||
login_user(self.request, user)
|
||||
return {
|
||||
'ok': True,
|
||||
'user': self.get_user_info(user),
|
||||
'permissions': list(cache_permissions(Session(), user)),
|
||||
'permissions': list(auth.cache_permissions(Session(), user)),
|
||||
}
|
||||
|
||||
def authenticate_user(self, username, password):
|
||||
return authenticate_user(Session(), username, password)
|
||||
app = self.get_rattail_app()
|
||||
auth = app.get_auth_handler()
|
||||
return auth.authenticate_user(Session(), username, password)
|
||||
|
||||
def why_cant_user_login(self, user):
|
||||
"""
|
||||
|
@ -156,7 +161,7 @@ class AuthenticationView(APIView):
|
|||
data = self.request.json_body
|
||||
|
||||
# first make sure "current" password is accurate
|
||||
if not authenticate_user(Session(), self.request.user, data['current_password']):
|
||||
if not self.authenticate_user(self.request.user, data['current_password']):
|
||||
return {'error': "The current/old password you provided is incorrect"}
|
||||
|
||||
# okay then, set new password
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue