Skip to content

Commit

Permalink
Merge pull request #265 from fga-gpp-mds/devel
Browse files Browse the repository at this point in the history
Bug-Security
  • Loading branch information
GuiMarques98 authored Dec 6, 2017
2 parents 549abc4 + c993473 commit 7fcf4dc
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 2 deletions.
3 changes: 3 additions & 0 deletions medical_prescription/landing/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@

from django.shortcuts import render

from user.decorators import user_is_logged


@user_is_logged
def home(request):
return render(request, 'landing.html')
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
<tr class='clickable-row'>

<td>
<button class="likes post-likes" url-prescription="{% url 'favorite_prescription' pk=prescription.pk %}">
<button class="likes post-likes favorite" url-prescription="{% url 'favorite_prescription' pk=prescription.pk %}">
{% if prescription.is_favorite %}
<span class="fa fa-star" style="color:orange"></span>
{% else %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
<tr class='clickable-row'>

<td>
<button class="likes post-likes" url-prescription="{% url 'favorite_prescription' pk=prescription.pk %}">
<button class="likes post-likes favorite" url-prescription="{% url 'favorite_prescription' pk=prescription.pk %}">
{% if prescription.is_favorite %}
<span class="fa fa-star" style="color:orange"></span>
{% else %}
Expand Down
4 changes: 4 additions & 0 deletions medical_prescription/static/prescription/css/favorite.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.favorite {
background-color: transparent;
border: 0px;
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
<script src="{% static "general/js/jquery-ui.js" %}"></script>

<!--========== END JAVASCRIPTS ==========-->
<link rel="stylesheet" href="{% static "prescription/css/favorite.css" %}">

</body>

Expand Down
23 changes: 23 additions & 0 deletions medical_prescription/user/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,26 @@ def wrap(request, email, *args, **kwargs):
raise PermissionDenied

return wrap


def user_is_logged(method):
"""
Make sure the user is logged in and redirects it to the dashboard
"""
def wrap(request, *args, **kwargs):
if 'user' in request.__dict__:
if request.user.is_authenticated():
is_health_professional = hasattr(request.user, 'healthprofessional')
is_patient = hasattr(request.user, 'patient')
if is_health_professional:
return redirect('/dashboard_health_professional/health_professional/')
elif is_patient:
return redirect('/dashboard_patient/patient/')
else:
return method(request, *args, **kwargs)
else:
return method(request, *args, **kwargs)
else:
return method(request, *args, **kwargs)

return wrap
3 changes: 3 additions & 0 deletions medical_prescription/user/views/loginview.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@
from django.shortcuts import render, redirect
from django.contrib import auth
from django.views.generic import FormView
from django.utils.decorators import method_decorator

# Local Django
from user.models import HealthProfessional
from user.forms import UserLoginForm
from user import constants
from user.decorators import user_is_logged

# Set level logger.
logging.basicConfig(level=logging.DEBUG)
Expand All @@ -26,6 +28,7 @@ class LoginView(FormView):
dashboard_name = ''

# Render the login page.
@method_decorator(user_is_logged)
def get(self, request, *args, **kwargs):
logger.debug("Start get method.")
form = self.form_class(initial=self.initial)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
from django.shortcuts import render, redirect
from django.views.generic import FormView
from django.contrib import messages
from django.utils.decorators import method_decorator

# Local Django
from user.models import HealthProfessional
from user.forms import HealthProfessionalForm
from user import constants
from user.views import ConfirmAccountView
from user.decorators import user_is_logged

# Set level logger.
logging.basicConfig(level=logging.DEBUG)
Expand All @@ -21,6 +23,7 @@ class RegisterHealthProfessionalView(FormView):
form_class = HealthProfessionalForm
template_name = 'register_health_professional.html'

@method_decorator(user_is_logged)
def get(self, request, *args, **kwargs):
logger.debug("Start get method.")
form = self.form_class(initial=self.initial)
Expand Down

0 comments on commit 7fcf4dc

Please sign in to comment.