Skip to content

Commit

Permalink
refactor: Add TODOs for mobile login view to avoid sonar code duplica…
Browse files Browse the repository at this point in the history
…tation error

This mobile specific login endpoint will be implemented later (when different options to password authentication are determined)
  • Loading branch information
makchamp committed Nov 29, 2020
1 parent c51dae6 commit f6d3a40
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 43 deletions.
2 changes: 1 addition & 1 deletion server/user_account/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@
urlpatterns = [
path('', include(router.urls)),
path('login/', views.LoginView.as_view()),
path('login-mobile/', views.LoginMobileView.as_view()),
path('logout/', views.LogoutView.as_view())
path('login-mobile/', views.LoginView.as_view()), # TODO: Call mobile specific view
]
45 changes: 3 additions & 42 deletions server/user_account/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,48 +170,9 @@ class LoginMobileView(generics.GenericAPIView):
serializer_class = LoginMobileSerializer

def post(self, request):
"""
Verify that a Stock Keeper or Inventory Manager has valid credentials and is active.
:param request: request.data: email, password
:return: user_name, token
"""
data = request.data
email = data.get('email', '')
password = data.get('password', '')

try:
user = CustomUser.objects.get(email=email)

if user.is_active:
encrypted_password = user.password
is_verified = check_password(password, encrypted_password)
if is_verified:
has_token = Token.objects.filter(user=user).count()
if has_token:
token = Token.objects.get(user=user)
else:
token = Token.objects.create(user=user)

if user.organization is None:
data = {'user': user.user_name, 'user_id': user.id, 'role': user.role,
'organization': '', 'token': token.key}
else:
data = {'user': user.user_name, 'user_id': user.id, 'role': user.role,
'organization_id': user.organization.org_id,
'organization_name': user.organization.org_name,
'token': token.key}

return Response(data, status=status.HTTP_200_OK)

return Response({'detail': 'Invalid credentials'},
status=status.HTTP_401_UNAUTHORIZED)

return Response({'detail': 'Please contact admin to activate your account'},
status=status.HTTP_401_UNAUTHORIZED)

except CustomUser.DoesNotExist:
return Response({'detail': 'Invalid user'},
status=status.HTTP_500_INTERNAL_SERVER_ERROR)
pass # TODO: Implement mobile specific endpoint
# Should be implemented when different options to password authentication are determined


class LogoutView(generics.GenericAPIView):
"""
Expand Down

0 comments on commit f6d3a40

Please sign in to comment.