server/users: track login time
This commit is contained in:
parent
d44bcdf3da
commit
baf9b1d31a
3 changed files with 10 additions and 3 deletions
|
@ -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();
|
||||
|
|
|
@ -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}'
|
||||
|
|
|
@ -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()
|
||||
|
|
Loading…
Reference in a new issue