server/users: track login time

This commit is contained in:
rr- 2016-04-03 15:12:15 +02:00
parent d44bcdf3da
commit baf9b1d31a
3 changed files with 10 additions and 3 deletions

View file

@ -66,7 +66,7 @@ class Api {
return new Promise((resolve, reject) => {
this.userName = userName;
this.userPassword = userPassword;
this.get('/user/' + userName)
this.get('/user/' + userName + '?bump-login=true')
.then(response => {
this.user = response.user;
resolve();

View file

@ -18,6 +18,10 @@ class Authenticator(object):
def process_request(self, request, response):
''' Executed before passing the request to the API. '''
request.context.user = self._get_user(request)
if request.get_param_as_bool('bump-login') \
and request.context.user.user_id:
self._user_service.bump_login_time(request.context.user)
request.context.session.commit()
def _get_user(self, request):
if not request.auth:
@ -34,8 +38,8 @@ class Authenticator(object):
username, password = base64.decodebytes(
user_and_password.encode('ascii')).decode('utf8').split(':')
session = request.context.session
return self._authenticate(session, username, password)
return self._authenticate(
request.context.session, username, password)
except ValueError as err:
msg = 'Basic authentication header value not properly formed. ' \
+ 'Supplied header {0}. Got error: {1}'

View file

@ -43,6 +43,9 @@ class UserService(object):
session.add(user)
return user
def bump_login_time(self, user):
user.last_login_time = datetime.now()
def get_by_name(self, session, name):
''' Retrieves an user by its name. '''
return session.query(User).filter_by(name=name).first()