ajout Dernières connexions pt
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
pyramid
|
||||
pyramid_chameleon
|
||||
pyramid_mako==0.3.1
|
||||
pyramid_debugtoolbar
|
||||
pyramid_layout
|
||||
pyramid_mailer
|
||||
@@ -11,6 +12,7 @@ waitress
|
||||
mysqlclient
|
||||
python-dateutil
|
||||
docutils
|
||||
user-agents
|
||||
|
||||
[testing]
|
||||
WebTest>=1.3.1
|
||||
|
||||
@@ -50,10 +50,10 @@ def update_membre_mdp(request, login, password):
|
||||
query = "UPDATE p_users SET mdp = SHA1(:password), mdp_oublie=NULL, mdp_oublie_date=NULL WHERE cd_uti=:login;"
|
||||
execute_query(request, query, {'login': login, 'password': password})
|
||||
|
||||
def update_last_connection(request, login):
|
||||
def update_last_connection(request, login, ua_string):
|
||||
"""Update last connection for login """
|
||||
query = "UPDATE p_users SET dern_cnx_le=NOW() WHERE cd_uti=:login;"
|
||||
execute_query(request, query, {'login': login})
|
||||
query = "UPDATE p_users SET dern_cnx_le=NOW(), ua_string=:ua_string WHERE cd_uti=:login;"
|
||||
execute_query(request, query, {'login': login, 'ua_string': ua_string})
|
||||
|
||||
def update_membre(request, cd_uti, new_values):
|
||||
# formater les champs
|
||||
|
||||
@@ -26,3 +26,4 @@ def includeme(config):
|
||||
config.add_route('orphans_de', '/orphans_de/{societe}')
|
||||
config.add_route('user_edit', '/user_edit/{cd_uti}')
|
||||
config.add_route('users_list', '/users_list')
|
||||
config.add_route('users_ua', '/users_ua')
|
||||
|
||||
@@ -7,6 +7,10 @@
|
||||
<a href="${request.application_url}/users_list"><span class="glyphicon glyphicon-user logo-primary"></span></a>
|
||||
<h4>UTILISATEURS</h4>
|
||||
</div>
|
||||
<div class="col-sm-3">
|
||||
<a href="${request.application_url}/users_ua"><span class="glyphicon glyphicon-log-in logo-primary"></span></a>
|
||||
<h4>CONNEXIONS</h4>
|
||||
</div>
|
||||
<div class="col-sm-3">
|
||||
<a href="${request.application_url}/dashboard"><span class="glyphicon glyphicon-dashboard logo-primary"></span></a>
|
||||
<h4>TABLEAU de BORD</h4>
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
<th>Email</th>
|
||||
<th>Agenda</th>
|
||||
<th>Rôle</th>
|
||||
<th>Dern cnx</th>
|
||||
<th>Etat</th>
|
||||
</tr>
|
||||
</thead>
|
||||
|
||||
46
mondumas/templates/parametres/users_ua.pt
Normal file
46
mondumas/templates/parametres/users_ua.pt
Normal file
@@ -0,0 +1,46 @@
|
||||
<metal:block use-macro="main_template">
|
||||
<div metal:fill-slot="content">
|
||||
|
||||
<p>
|
||||
<a href="${request.application_url}/" class="btn btn-default" role="button">
|
||||
<span class="glyphicon glyphicon-chevron-left"></span> Retour</a>
|
||||
<a href="${request.application_url}/user_edit/0" class="btn btn-success" role="button">
|
||||
<span class="glyphicon glyphicon-plus"></span> Nouveau utilisateur</a>
|
||||
</p>
|
||||
|
||||
<table id="users_list_ua" class="table table-striped table-bordered">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Dern cnx</th>
|
||||
<th>Login</th>
|
||||
<th>Nom, Prénom</th>
|
||||
<th>Appareil utilisé</th>
|
||||
</tr>
|
||||
</thead>
|
||||
</table>
|
||||
|
||||
<br />
|
||||
<br />
|
||||
|
||||
<script type="text/javascript">
|
||||
var dataSet = ${dt_data};
|
||||
|
||||
$(document).ready(function() {
|
||||
$.fn.dataTable.moment('DD/MM/YYYY - HH:mm');
|
||||
$('#users_list_ua').DataTable({
|
||||
data: dataSet,
|
||||
pageLength: 50,
|
||||
bLengthChange: false,
|
||||
language: {
|
||||
url: 'https://cdn.datatables.net/plug-ins/1.10.16/i18n/French.json'
|
||||
},
|
||||
"order": [[ 0, "desc" ]]
|
||||
});
|
||||
|
||||
});
|
||||
</script>
|
||||
|
||||
</div><!-- content -->
|
||||
</metal:block>
|
||||
|
||||
|
||||
@@ -20,6 +20,7 @@ from datetime import *
|
||||
import hashlib
|
||||
from sqlalchemy.exc import DBAPIError
|
||||
from ..security import groupfinder
|
||||
from user_agents import parse
|
||||
|
||||
import json
|
||||
|
||||
@@ -181,7 +182,11 @@ def login(request):
|
||||
if record :
|
||||
# mot de passe hash valide ?
|
||||
if record.mdp == to_sha1(password):
|
||||
update_last_connection(request, login)
|
||||
# get user agent string from request
|
||||
ua_string = request.user_agent
|
||||
user_agent = parse(ua_string)
|
||||
update_last_connection(request, login, str(user_agent))
|
||||
|
||||
# force le commit car il ne se fait pas automatiquement après l'update
|
||||
transaction.commit()
|
||||
|
||||
|
||||
@@ -41,11 +41,6 @@ def users_list(request):
|
||||
# construire la liste
|
||||
liste=[]
|
||||
for item in items:
|
||||
if item.dern_cnx_le:
|
||||
der_cnx_le = item.dern_cnx_le.strftime('%d/%m/%Y - %H:%M')
|
||||
else:
|
||||
der_cnx_le = ""
|
||||
|
||||
if item.actif == 0:
|
||||
etat = 'Inactif'
|
||||
else:
|
||||
@@ -60,7 +55,7 @@ def users_list(request):
|
||||
else:
|
||||
role = 'Gestion'
|
||||
|
||||
d = (item.CD_UTI, item.NOM, item.email, item.agenda, role, der_cnx_le, etat)
|
||||
d = (item.CD_UTI, item.NOM, item.email, item.agenda, role, etat)
|
||||
liste.append(d)
|
||||
|
||||
return {
|
||||
@@ -68,6 +63,28 @@ def users_list(request):
|
||||
'dt_data': json.dumps(liste),
|
||||
}
|
||||
|
||||
@view_config(route_name='users_ua', renderer='../templates/parametres/users_ua.pt', permission='manage')
|
||||
def users_ua(request):
|
||||
# lire les utilisateurs
|
||||
items = get_member_by_id(request, '0')
|
||||
|
||||
# construire la liste
|
||||
liste=[]
|
||||
for item in items:
|
||||
# utilisateur a au moins une connexion ?
|
||||
if item.dern_cnx_le:
|
||||
der_cnx_le = item.dern_cnx_le.strftime('%d/%m/%Y - %H:%M')
|
||||
|
||||
d = (der_cnx_le, item.CD_UTI, item.NOM, item.ua_string)
|
||||
liste.append(d)
|
||||
|
||||
return {
|
||||
'page_title': u'Liste des connexions',
|
||||
'dt_data': json.dumps(liste),
|
||||
}
|
||||
|
||||
|
||||
|
||||
@view_config(route_name='user_edit', renderer='../templates/parametres/user_edit.pt', permission='manage')
|
||||
def user_edit(request):
|
||||
cd_uti = request.matchdict['cd_uti']
|
||||
|
||||
@@ -1,51 +0,0 @@
|
||||
# uncomment the next import line to get print to show up or see early
|
||||
# exceptions if there are errors then run
|
||||
# python -m win32traceutil
|
||||
# to see the output
|
||||
#import win32traceutil
|
||||
import win32serviceutil
|
||||
|
||||
PORT_TO_BIND = 9180
|
||||
CONFIG_FILE = 'production.ini'
|
||||
SERVER_NAME = 'gestion.entreprise-dumas.com'
|
||||
|
||||
SERVICE_NAME = "Pyramid_Service"
|
||||
SERVICE_DISPLAY_NAME = "Pyramid Web Service"
|
||||
SERVICE_DESCRIPTION = """Permet de laner l'application Pyramid comme un servcie."""
|
||||
|
||||
class PyWebService(win32serviceutil.ServiceFramework):
|
||||
"""Python Web Service."""
|
||||
|
||||
_svc_name_ = SERVICE_NAME
|
||||
_svc_display_name_ = SERVICE_DISPLAY_NAME
|
||||
_svc_deps_ = None # sequence of service names on which this depends
|
||||
# Only exists on Windows 2000 or later, ignored on Windows NT
|
||||
_svc_description_ = SERVICE_DESCRIPTION
|
||||
|
||||
def SvcDoRun(self):
|
||||
from cheroot import wsgi
|
||||
from pyramid.paster import get_app
|
||||
from pyramid.paster import setup_logging
|
||||
import os, sys
|
||||
|
||||
path = os.path.dirname(os.path.abspath(__file__))
|
||||
print(path)
|
||||
os.chdir(path)
|
||||
|
||||
app = get_app(CONFIG_FILE)
|
||||
setup_logging(CONFIG_FILE)
|
||||
|
||||
|
||||
self.server = wsgi.Server(
|
||||
('0.0.0.0', PORT_TO_BIND), app,
|
||||
server_name=SERVER_NAME)
|
||||
|
||||
self.server.start()
|
||||
|
||||
|
||||
def SvcStop(self):
|
||||
self.server.stop()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
win32serviceutil.HandleCommandLine(PyWebService)
|
||||
3
setup.py
3
setup.py
@@ -10,8 +10,8 @@ with open(os.path.join(here, 'CHANGES.txt')) as f:
|
||||
|
||||
requires = [
|
||||
'pyramid',
|
||||
# 'pyramid_jinja2',
|
||||
'pyramid_chameleon',
|
||||
'pyramid_mako==0.3.1', # bug dans pserve --reload
|
||||
'pyramid_debugtoolbar',
|
||||
'pyramid_layout',
|
||||
'pyramid_mailer',
|
||||
@@ -23,6 +23,7 @@ requires = [
|
||||
'mysqlclient',
|
||||
'python-dateutil',
|
||||
'docutils',
|
||||
'user-agents',
|
||||
]
|
||||
|
||||
tests_require = [
|
||||
|
||||
Reference in New Issue
Block a user