diff --git a/amadeus/settings.py b/amadeus/settings.py index 53fe606..4bd85ba 100644 --- a/amadeus/settings.py +++ b/amadeus/settings.py @@ -149,5 +149,5 @@ AUTHENTICATION_BACKENDS = [ ] ROLEPERMISSIONS_MODULE = 'amadeus.roles' - +LOGS_URL = 'logs/' #https://github.com/squ1b3r/Djaneiro diff --git a/app/templates/home_app.html b/app/templates/home_app.html deleted file mode 100644 index 951e0c1..0000000 --- a/app/templates/home_app.html +++ /dev/null @@ -1,74 +0,0 @@ -{% extends 'base.html' %} - -{% load i18n %} - -{% block breadcrumbs %} -
-
-

{{ user }}

-
-
-
-
- -
-
-{% endblock %} - -{% block sidebar %} -
- {% trans 'Pending tasks' %} - {% trans 'Users Online (1)' %} - - -
-{% endblock %} - -{% block content %} -

- -
{% trans 'Courses' %}
-
-

- - {% if courses|length > 0 %} - {% for course in courses %} - - - {% endfor %} - {% else %} -

{% trans "You didn't create any course yet." %}

- {% endif %} -{% endblock %} - -{% block rightbar %} -
-

- -
{% trans 'Goals' %}
-
-

- - - - - - - - - -
70% de Presenca nas aulas
30/11 - Entrega das notas finais
-
-{% endblock rightbar %} diff --git a/app/templates/home_student.html b/app/templates/home_student.html index d568f89..4750757 100644 --- a/app/templates/home_student.html +++ b/app/templates/home_student.html @@ -6,7 +6,7 @@
diff --git a/app/views.py b/app/views.py index e21f29e..53840e2 100644 --- a/app/views.py +++ b/app/views.py @@ -1,10 +1,15 @@ from django.shortcuts import render from django.views.generic import TemplateView from django.contrib.auth.mixins import LoginRequiredMixin +from django.utils.decorators import decorator_from_middleware_with_args +from django.utils.decorators import decorator_from_middleware +from django.utils.decorators import method_decorator +from core.mixins import LogMixin from courses.models import Course -class AppIndex(LoginRequiredMixin, TemplateView): +class AppIndex(LoginRequiredMixin, LogMixin, TemplateView): + log_action = "Acessou home" template_name = "home_professor.html" def render_to_response(self, context, **response_kwargs): diff --git a/core/decorators.py b/core/decorators.py new file mode 100644 index 0000000..45b4eff --- /dev/null +++ b/core/decorators.py @@ -0,0 +1,31 @@ +import os +import datetime +from django.conf import settings +from functools import wraps + +def log_decorator(log_action = ''): + + def _log_decorator(view_function): + + def _decorator(request, *args, **kwargs): + + response = view_function(request, *args, **kwargs) + + if request.user.is_authenticated and request.POST: + date = datetime.datetime.now() + + message = date.strftime("%d/%m/%Y %H:%M:%S") + ' - ' + request.user.username + ' - ' + log_action + '\n' + + file_name = 'log_file_' + date.strftime("%d-%m-%Y") + '.txt' + + log_path = os.path.join(settings.LOGS_URL, file_name) + + log_file = open(log_path,'a+') + log_file.write(message) + log_file.close() + + return response + + return wraps(view_function)(_decorator) + + return _log_decorator \ No newline at end of file diff --git a/core/mixins.py b/core/mixins.py new file mode 100644 index 0000000..d5301bd --- /dev/null +++ b/core/mixins.py @@ -0,0 +1,21 @@ +import os +import datetime +from django.conf import settings + +class LogMixin(object): + log_action = "" + + def dispatch(self, request, *args, **kwargs): + date = datetime.datetime.now() + + message = date.strftime("%d/%m/%Y %H:%M:%S") + ' - ' + request.user.username + ' - ' + self.log_action + '\n' + + file_name = 'log_file_' + date.strftime("%d-%m-%Y") + '.txt' + + log_path = os.path.join(settings.LOGS_URL, file_name) + + log_file = open(log_path,'a+') + log_file.write(message) + log_file.close() + + return super(LogMixin, self).dispatch(request, *args, **kwargs) \ No newline at end of file diff --git a/core/views.py b/core/views.py index 97a518b..fb6e071 100644 --- a/core/views.py +++ b/core/views.py @@ -1,6 +1,11 @@ - from django.shortcuts import render from django.http import HttpResponse + +from django.contrib.auth import authenticate, login as login_user +from django.shortcuts import redirect +from django.core.urlresolvers import reverse + +from .decorators import log_decorator # from django.contrib.auth.views import LoginView def index(request): @@ -15,12 +20,7 @@ def create_account(request): def remember_password(request): return render(request, "remember_password.html") - - -from django.contrib.auth import authenticate, login as login_user -from django.shortcuts import redirect -from django.urls import reverse - +@log_decorator('Entrou no sistema') def login(request): if request.POST: username = request.POST['username'] diff --git a/db.sqlite3 b/db.sqlite3 deleted file mode 100644 index fb67489..0000000 Binary files a/db.sqlite3 and /dev/null differ diff --git a/logs/log_file_02-09-2016.txt b/logs/log_file_02-09-2016.txt new file mode 100644 index 0000000..c23df31 --- /dev/null +++ b/logs/log_file_02-09-2016.txt @@ -0,0 +1,2 @@ +02/09/2016 23:34:45 - zambom - Entrou no sistema +02/09/2016 23:34:45 - zambom - Acessou home -- libgit2 0.21.2